seagrid.sources.module#

Module-level access to a data source: from seagrid import ostia.

Each built-in source has a module (seagrid.ostia, seagrid.modis, …) whose attributes are those of the source object, so

>>> from seagrid import ostia
>>> ostia.filename("2010-06-01")
'20100601120000-UKMO-L4_GHRSST-SSTfnd-OSTIA-GLOB_REP-v02.0-fv02.0.nc'

is the same as seagrid.get_source("ostia").filename("2010-06-01"). The module attributes always reflect the current settings, so a changed configuration environment (seagrid.config.change_env()) takes effect at the next call. ostia.source(variant="nrt", datadir=...) returns a separate source object for a variant or with overridden settings.

A source module is two lines:

from seagrid.sources.module import bind

__getattr__, __dir__, source = bind("ostia")

Functions

bind(name[, extra])

Return __getattr__, __dir__ and source for a source module.

seagrid.sources.module.bind(name, extra=())[source]#

Return __getattr__, __dir__ and source for a source module.

Parameters:
  • name (str) – The registry name of the source, e.g. "ostia".

  • extra (tuple of str, optional) – Names the module defines itself, listed by dir().

Returns:

  • getattr (callable) – Module __getattr__ delegating to the default source object.

  • dir (callable) – Module __dir__ listing the source’s public members.

  • source (callable) – source(variant=None, **overrides), returning a new source object.

Return type:

tuple[Callable[[str], Any], Callable[[], list[str]], Callable[…, DataSource]]

Notes

The default object is created on first use and kept while the source’s settings stay the same, so its cached grids are reused between calls.