seagrid.grids.factories#
Functions that build Grid objects.
Data sources never build grids by hand. They use one of these factories, or
describe their grid in the settings and call from_settings().
- ivar NASA_L3_COLUMNS:
Number of columns of the NASA OBPG Level-3 mapped (equal-angle) grids for each nominal resolution.
- vartype NASA_L3_COLUMNS:
Module Attributes
Grids that can be referred to by name in the settings ( |
Functions
|
Return obj as a |
Build the CBIOMES global 0.5° climatology grid (360 × 720 cells). |
|
|
Build a grid from a pyresample area definition. |
|
Build the grid of an xarray Dataset or DataArray from its coordinates. |
|
Build a grid from a settings entry. |
|
Build a NASA OBPG Level-3 mapped (equal-angle, global) grid. |
|
Build a regular latitude/longitude grid from its cell size and extent. |
- seagrid.grids.factories.NAMED_GRIDS: dict[str, Callable[[], Grid]] = {'cbiomes_halfdeg': <function cbiomes_halfdeg>, 'nasa_l3_18km': functools.partial(<function nasa_l3>, '18km'), 'nasa_l3_1deg': functools.partial(<function nasa_l3>, '1deg'), 'nasa_l3_1km': functools.partial(<function nasa_l3>, '1km'), 'nasa_l3_2km': functools.partial(<function nasa_l3>, '2km'), 'nasa_l3_4km': functools.partial(<function nasa_l3>, '4km'), 'nasa_l3_9km': functools.partial(<function nasa_l3>, '9km')}#
Grids that can be referred to by name in the settings (
grid = "<name>").
- seagrid.grids.factories.as_grid(obj, *, lat=None, lon=None)[source]#
Return obj as a
Grid, whatever kind of grid description it is.- Parameters:
obj (
Grid,pyresample geometry,xarray.Dataset,xarray.DataArrayorsource) – AGrid(returned as is); apyresample.geometry.AreaDefinition; apyresample.geometry.GridDefinitionor anything else with 2-Dlats/lons(rectilinear ones become 1-D grids); an xarray object (seefrom_dataset()); a grid name fromNAMED_GRIDS; or a data source (itsgrid()).lat (
str, optional) – Coordinate names, for xarray objects.lon (
str, optional) – Coordinate names, for xarray objects.
- Returns:
Grid- Raises:
TypeError – If obj describes no grid.
- Return type:
Examples
>>> import numpy as np, pyresample as pr >>> lons, lats = np.meshgrid(np.arange(-179.5, 180), np.arange(-89.5, 90)) >>> as_grid(pr.geometry.GridDefinition(lons=lons, lats=lats)).is_regular True
- seagrid.grids.factories.cbiomes_halfdeg()[source]#
Build the CBIOMES global 0.5° climatology grid (360 × 720 cells).
- Returns:
Grid– Centres at -89.75 … 89.75 and -179.75 … 179.75.- Return type:
- seagrid.grids.factories.from_area_def(area_def, *, lat_ascending=True, name=None)[source]#
Build a grid from a pyresample area definition.
- Parameters:
area_def (
pyresample.geometry.AreaDefinition) – The area. A plain latitude/longitude projection gives a rectilinear grid; any other projection gives a curvilinear grid that keeps area_def (rows north to south, as in pyresample).lat_ascending (
bool, optional) – For a latitude/longitude area: order rows south to north (default) or keep pyresample’s north-to-south order.name (
str, optional) – Grid name. Default:area_def.area_id.
- Returns:
Grid- Return type:
- seagrid.grids.factories.from_dataset(ds, lat=None, lon=None, *, name=None)[source]#
Build the grid of an xarray Dataset or DataArray from its coordinates.
- Parameters:
ds (
xarray.Datasetorxarray.DataArray) – Object with latitude and longitude coordinates (or variables), either 1-D or 2-D.lat (
str, optional) – Names of the latitude and longitude variables. Default: the first oflat,latitude,nav_lat,lats(and thelonequivalents) that exists.lon (
str, optional) – Names of the latitude and longitude variables. Default: the first oflat,latitude,nav_lat,lats(and thelonequivalents) that exists.name (
str, optional) – Grid name.
- Returns:
Grid– In the dataset’s own row and column order.- Raises:
KeyError – If no latitude or longitude variable is found.
- Return type:
- seagrid.grids.factories.from_settings(spec)[source]#
Build a grid from a settings entry.
A source’s settings section describes its grid with a
gridkey in one of three forms:a name from
NAMED_GRIDS:grid = "nasa_l3_4km"
a regular latitude/longitude grid:
grid = { dlat = 0.05, lat_range = [-90, 90], lon_range = [-180, 180] }
a pyresample area definition, with the arguments of
pyresample.create_area_def():grid = { projection = "EPSG:3413", shape = [448, 304], area_extent = [-3850000, -5350000, 3750000, 5850000] }
- Parameters:
spec (
strormapping) – Thegridentry.- Returns:
Grid- Raises:
ValueError – If spec is not one of the forms above.
- Return type:
Examples
>>> from_settings("nasa_l3_9km").shape (2160, 4320) >>> from_settings({"dlat": 1.0}).shape (180, 360)
- seagrid.grids.factories.nasa_l3(resolution='4km')[source]#
Build a NASA OBPG Level-3 mapped (equal-angle, global) grid.
Used by MODIS, VIIRS, SeaWiFS, OLCI and OC-CCI mapped products.
- Parameters:
resolution (
{"1deg", "18km", "9km", "4km", "2km", "1km"}, optional) – Nominal resolution. Default"4km"(8640 × 4320 cells).- Returns:
Grid– Latitude ascending, longitude -180 … 180.- Raises:
ValueError – If resolution is not one of
NASA_L3_COLUMNS.- Return type:
Notes
The files themselves store latitude descending; the sources flip it on open so that data and grid agree.
Examples
>>> nasa_l3("9km").shape (2160, 4320)
- seagrid.grids.factories.regular_latlon(dlat, dlon=None, *, lat_range=(-90.0, 90.0), lon_range=(-180.0, 180.0), lat_ascending=True, name=None)[source]#
Build a regular latitude/longitude grid from its cell size and extent.
Cell centres are half a cell inside the edges of the ranges, so a global 1° grid has centres at -89.5 … 89.5 and -179.5 … 179.5.
- Parameters:
dlat (
float) – Cell height in degrees of latitude.dlon (
float, optional) – Cell width in degrees of longitude. Default: dlat.lat_range (
(float,float), optional) – Southern and northern edge of the grid. Default(-90, 90).lon_range (
(float,float), optional) – Western and eastern edge of the grid. Default(-180, 180).lat_ascending (
bool, optional) – Order rows south to north (seagrid’s convention, the default) or north to south.name (
str, optional) – Grid name. Default"regular_<dlat>x<dlon>".
- Returns:
Grid- Raises:
ValueError – If a range is not a whole number of cells.
- Return type:
Examples
>>> grid = regular_latlon(0.25, lat_range=(-80, 90)) >>> grid.shape, float(grid.lat[0]), float(grid.lat[-1]) ((680, 1440), -79.875, 89.875)