Working with data sources#
A data source is one product, such as OSTIA SST or MODIS-Aqua chlorophyll.
Every source is a seagrid.sources.DataSource with the same
methods, whatever the provider, so code written for one source works for all
of them.
The simplest way to use a source is its module:
from seagrid import modis
modis.describe()
ds = modis.open_dataset("2023-06-01", "par", timetype="monthly")
Each module (seagrid.ostia, seagrid.modis, seagrid.oc_cci,
seagrid.acspo, …) has every method below as a function and is also
reachable as seagrid.ostia after import seagrid. The same object is
available from the registry, which is handy when the source name is a
variable:
import seagrid
seagrid.list_sources()
for name in ("ostia", "acspo"):
print(seagrid.get_source(name).time_range())
Choosing what to open#
Each method takes the same arguments:
Argument |
Meaning |
Default |
|---|---|---|
|
any time inside the time step |
the first available date |
|
variable (for NASA L3 products it chooses the file) |
the source’s default |
|
|
the source’s default |
|
|
the source’s default |
Variants of a product, such as near-real-time data, are selected when the
source is created: ostia.source(variant="nrt") or
seagrid.get_source("ostia", variant="nrt"). Keyword
arguments override settings for that object only:
seagrid.get_source("ostia", datadir="/scratch/ostia").
Methods#
Method |
Does |
|---|---|
|
download if needed, open, apply seagrid conventions |
|
one variable |
|
a time series along |
|
fetch into the cache |
|
is the time step on the server? (no download) |
|
which time steps are cached |
|
naming |
|
available time steps |
|
the |
|
summary for listings |
|
2-D coordinates (°) and cell metrics (m, m²) of the grid |
|
True on land; great-circle distance to land in km |
|
Longhurst province, biome and basin of every cell ( |
|
forget the fields above (and with |
Geographic fields#
Every source gives the coordinates, cell sizes and land of its grid, as methods that keep their result:
from seagrid import ostia, modis
lats, lons = ostia.lats(), ostia.lons() # numpy, (3600, 7200)
area = modis.area(resolution="9km") # m²
land = ostia.landmask() # DataArray, True on land
dist = ostia.distance_from_land() # DataArray, km (float32)
The first call computes the field and keeps it on the source object, so
later calls return the same array at once (read-only; use .copy() to
change it). cache=False computes it again and keeps nothing.
landmask and distance_from_land take seconds to minutes on a global
grid, so they are also stored as Zarr in <datadir>/geo/ (the geodir
setting changes this) and read from there by later sessions. A stored
field is used only if it was built on the same grid.
Land comes from the source wherever it has its own:
Sources |
Land is |
|---|---|
|
the land bit of the GHRSST L4 |
|
the cells where the model’s surface field is missing (a model has no clouds) |
|
|
every other source |
GEBCO: a cell is land if more than half of it is above sea level |
The first two kinds open the first available time step, so they may download one file; GEBCO is about 7.5 GB, downloaded on first use.
Longhurst provinces#
Longhurst’s biogeographical provinces come in two versions:
Version |
Provinces |
Data |
|---|---|---|
|
57, numbered as in Longhurst (2007) |
a 1/6° grid, |
|
54 “initial static boundaries” (Longhurst 1995; 1998), other numbers |
polygons, downloaded once from Marine Regions (or the SAERI copy). Using it warns. |
Every source puts them on its own grid, with the same caching as
landmask:
prov = ostia.longhurst_provinces() # 1-57 (0 on land), int16
biome = ostia.longhurst_biomes() # 1 Coastal, 2 Polar, 3 Trades, 4 Westerlies
basin = ostia.longhurst_basins() # 1 Arctic, 2 Atlantic, 3 Indian, 4 Pacific, 5 Southern
old = ostia.longhurst_provinces(version="1995") # warns
seagrid.longhurst.province_table() # ID, Code, Province, Biome, Basin
Each cell takes the province at its centre. The provinces’ coastline is
coarse, so some ocean cells near the coast are in none; they take the
nearest province, using the source’s landmask(). fill=False leaves
them 0 (and needs no land mask). seagrid.longhurst.open_dataset() gives
regions, biomes and basins on the 1/6° grid, unfilled
(seagrid.longhurst.source(variant="1995") for the polygons), and
seagrid.longhurst.resample(grid, version=...) puts them on any grid.
Conventions of the returned data#
lat/loncoordinates with latitude ascending (south to north);SST in °C, with
unitsattributes set;a
timecoordinate: the start of the time step;attrs["seagrid_history"]lists every change seagrid made (renames, unit conversions, flips), andattrs["seagrid_source"]names the source.
Means over longer periods#
Coarser time types than a source’s native ones are computed: a source with
daily files also offers "8day" and "monthly". The mean skips missing
values cell by cell, is computed one file at a time (so memory use is one
time step), and is cached in <datadir>/derived/.
Files that are missing on the server (or fail to open) are skipped with a
warning, and the mean is built from the rest. The number of files used and
the dates skipped are in ds.attrs["seagrid_n_files"],
ds.attrs["seagrid_missing"] and the history. Because the mean is cached,
rebuild it with force=True if the missing files appear later. A period
with no files raises FileNotFoundError, and so does a period that reaches
past the end of the source’s time range (it is not complete yet).
sst = seagrid.get_source("ostia").open_dataset("2010-06-01", timetype="monthly")
Time ranges of rolling archives#
Settings can describe archives that move: dtm_max = "today", relative
dates such as dtm_min = "-720D", and latency = "70D" for products that are
published with a delay. seagrid check SOURCE and the full test level check
the configured range against the server.