osmose.forcing.grid¶
Grid geometry helpers for CMEMS->OSMOSE forcing conversion.
Pure: numpy/xarray + osmose.maps.builder.GridSpec only. No CMEMS/MCP deps, so this module (and its tests) run in the clean CI venv.
regrid/resample use O(nlat*nlon) Python loops (verbatim from the MCP source), intended for OSMOSE-scale config grids (~1e3-1e4 cells, coarse by construction). A much finer grid would want a vectorized scipy.spatial.cKDTree / np.searchsorted.
Functions
|
Set land cells to NaN in every (time, lat, lon) array, in place. |
|
Approximate cell volume (m^3) using the grid's mid-latitude cos factor. |
|
Extract lat/lon arrays, tolerating 'latitude'/'lat' and 'longitude'/'lon'. |
|
Variable as 3D (time, lat, lon), NaN->0; None if absent. |
|
Load a bool (nlat, nlon) ocean mask (True=ocean) from a grid NetCDF, or None. |
|
Nearest-neighbor regrid (time, src_lat, src_lon) -> (time, nlat, nlon). |
|
Linear-interpolate (time, lat, lon) to 24 biweekly steps; identity if already 24. |
|
Cell-center (lat[nlat], lon[nlon]); latitude descending (north->south). |