seagrid.utils#
Helpers from seagrid 2.x: date ranges, directories, netCDF checks, subsetting.
New code uses the DataSource members instead
(dtm_vec, datadir, downloaded, open_dataset(bbox=...)).
Functions
|
Create and return the data directory path from a settings dictionary. |
|
Generate a pandas date range from a settings dictionary. |
|
Check if a netCDF file contains a specific data variable. |
|
Check if a file exists and is a valid netCDF file. |
|
Subset an xarray Dataset to a lat/lon bounding box from settings. |
|
Log text at INFO level, or WARNING level if verbose. |
- seagrid.utils.datadir(settings)[source]#
Create and return the data directory path from a settings dictionary.
The directory (and any missing parents) is created if it does not already exist.
- seagrid.utils.dtm_vec(settings)[source]#
Generate a pandas date range from a settings dictionary.
- Parameters:
settings (
dict) – Dictionary containing the keysdtm_min,dtm_max, anddtm_freqwhich are forwarded topandas.date_range.- Returns:
pandas.DatetimeIndex– Date range spanning fromdtm_mintodtm_maxat the frequency given bydtm_freq.- Return type:
DatetimeIndex
- seagrid.utils.has_nc_data_var(full_filename, data_var)[source]#
Check if a netCDF file contains a specific data variable.
The file is opened with
xarray.open_datasetand the presence of data_var is verified.
- seagrid.utils.is_nc_file(full_filename)[source]#
Check if a file exists and is a valid netCDF file.
Attempts to open the file with
xarray.open_dataset. If the file does not exist or cannot be opened,Falseis returned.
- seagrid.utils.ll2dist2vec(lonvec1, latvec1, lonvec2, latvec2)[source]#
Return the distance between corresponding points of two sets.
- seagrid.utils.slice_dataframe(ds, settings, latname='lat', lonname='lon')[source]#
Subset an xarray Dataset to a lat/lon bounding box from settings.
- Parameters:
ds (
xarray.Dataset) – The dataset to subset.settings (
dict) – Dictionary with keyslatmin,latmax,lonmin, andlonmaxdefining the bounding box in degrees.latname (
str, optional) – Name of the latitude coordinate in ds. Default is"lat".lonname (
str, optional) – Name of the longitude coordinate in ds. Default is"lon".
- Returns:
xarray.Dataset– The subset of ds whose coordinates fall within the bounding box defined by settings.- Return type:
- seagrid.utils.vprint(text, verbose=False)[source]#
Log text at INFO level, or WARNING level if verbose.
In 2.x this printed when the
verbosesetting was on. Configure theseagridlogger instead.
Modules
Legacy grid helpers, kept for the 2.x series. |
|
Grid-spacing helpers (2.x interface), computed by |
|
Great-circle distances (2.x interface). |