Helpers to get embedded data#

resourcecode.data.get_closest_point(latitude: float, longitude: float) Tuple[int, float]#

Get the closest point in the mesh, from the given position

Parameters:
  • latitude – the latitude in decimal degrees

  • longitude – the latitude in decimal degrees

Returns:

the corresponding point id, and its distance in meters, to the requested coordinates

Return type:

(pointId, distance)

resourcecode.data.get_closest_station(latitude: float, longitude: float) Tuple[str, float]#

Get the closest station name from the given position

Parameters:
  • latitude – the latitude in decimal degrees

  • longitude – the latitude in decimal degrees

Returns:

the corresponding station name, and its distance in meters, to the requested coordinates

Return type:

(station name, distance)

resourcecode.data.get_coastline(columns: Sequence[Hashable] | None = None, use_threads: bool = True, storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = _NoDefault.no_default) DataFrame#

Return a pandas dataframe describing the costline nodes.

The default returned columns are: longitude, latitude, depth.

Parameters:
  • columns (sequence, optional) – Only read a specific set of columns. If not provided, all columns are read.

  • use_threads (bool, default True) – Whether to parallelize reading using multiple threads.

  • memory_map (boolean, default True) – Use memory mapping when opening file on disk

Returns:

df

Return type:

pandas.DataFrame

resourcecode.data.get_covered_period() dict#

Get the closest station name from the given position

Returns:

a datetime dict with the starting and ending dates covered by the hindcast

Return type:

(start, end)

resourcecode.data.get_grid_field(columns: Sequence[Hashable] | None = None, use_threads: bool = True, storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = _NoDefault.no_default) DataFrame#

Return a pandas dataframe describing the grid field.

The default returned columns are: node, longitude, latitude, depth, d50

Parameters:
  • columns (sequence, optional) – Only read a specific set of columns. If not provided, all columns are read.

  • use_threads (bool, default True) – Whether to parallelize reading using multiple threads.

  • memory_map (boolean, default True) – Use memory mapping when opening file on disk

Returns:

df

Return type:

pandas.DataFrame

resourcecode.data.get_grid_spec(columns: Sequence[Hashable] | None = None, use_threads: bool = True, storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = _NoDefault.no_default) DataFrame#

Return a pandas dataframe describing the grid specifications.

The default returned columns are: longitude, latitude, name, depth, d50

Parameters:
  • columns (sequence, optional) – Only read a specific set of columns. If not provided, all columns are read.

  • use_threads (bool, default True) – Whether to parallelize reading using multiple threads.

  • memory_map (boolean, default True) – Use memory mapping when opening file on disk

Returns:

df

Return type:

pandas.DataFrame

resourcecode.data.get_islands(columns: Sequence[Hashable] | None = None, use_threads: bool = True, storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = _NoDefault.no_default) DataFrame#

Return a pandas dataframe describing the islands.

The default returned columns are: longitude, latitude, depth, ID

Parameters:
  • columns (sequence, optional) – Only read a specific set of columns. If not provided, all columns are read.

  • use_threads (bool, default True) – Whether to parallelize reading using multiple threads.

  • memory_map (boolean, default True) – Use memory mapping when opening file on disk

Returns:

df

Return type:

pandas.DataFrame

resourcecode.data.get_triangles(columns: Sequence[Hashable] | None = None, use_threads: bool = True, storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = _NoDefault.no_default) DataFrame#

Return a pandas dataframe describing the mesh triangles.

The default returned columns are: Corner 1, Corner 2, Corner 3.

Parameters:
  • columns (sequence, optional) – Only read a specific set of columns. If not provided, all columns are read.

  • use_threads (bool, default True) – Whether to parallelize reading using multiple threads.

  • memory_map (boolean, default True) – Use memory mapping when opening file on disk

Returns:

df

Return type:

pandas.DataFrame

resourcecode.data.get_variables(columns: Sequence[Hashable] | None = None, use_threads: bool = True, storage_options: StorageOptions | None = None, dtype_backend: DtypeBackend | lib.NoDefault = _NoDefault.no_default) DataFrame#

Return a pandas dataframe describing the variables available in the Cassandra database.

The default returned columns are: name, longname, unit

Parameters:
  • columns (sequence, optional) – Only read a specific set of columns. If not provided, all columns are read.

  • use_threads (bool, default True) – Whether to parallelize reading using multiple threads.

  • memory_map (boolean, default True) – Use memory mapping when opening file on disk

Returns:

df

Return type:

pandas.DataFrame

Import/export helpers#

When the resourcecode is loaded, all pandas DataFrame automatically have a to_netcdf() method, and the pandas module has a read_netcdf() function.

For instance:

import pandas as pd

# load the module to provide pandas the `read_netcdf` and `to_netcdf`
# functions
import resourcecode

dataframe = pd.read_netcdf("path/to/my_data.nc")

# to some work on dataframe

dataframe.to_netcdf("path/to/new_data.nc")

If you need custom options to import/export netcdf files, one could use functions from xarray for instance.

resourcecode.io.read_netcdf(filename_or_obj: str | Path) DataFrame#

Open and decode a dataframe from a file or file-like object.

Parameters:

filename_or_obj (str, Path, file-like) – Strings and Path objects are interpreted as a path to a netCDF file or an OpenDAP URL and opened with python-netCDF4, unless the filename ends with .gz, in which case the file is gunzipped and opened with scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF).

Returns:

dataframe – The newly created dataset.

Return type:

pd.DataFrame

Notes

read_netcdf is a simple helper to load netcdf files. Please refer to xarray.open_dataset() for more parameters if needs be.

resourcecode.io.to_mat(dataframe: DataFrame, path: str | Path = 'data.mat', name: str | None = 'rscd') bytes | Delayed | None#

Write dataframe contents to a MATLAB file.

Parameters:
  • path (str, Path or file-like, optional) – Path to which to save this dataset. File-like objects are only supported by the scipy engine.

  • name (str) – The name of the structure containing the data in the MATLAB file.

resourcecode.io.to_netcdf(dataframe: DataFrame, path: str | Path | None = None) bytes | Delayed | None#

Write dataframe contents to a netCFD file.

Parameters:

path (str, Path or file-like, optional) – Path to which to save this dataset. File-like objects are only supported by the scipy engine. If no path is provided, this function returns the resulting netCDF file as bytes; in this case, we need to use scipy, which does not support netCDF version 4 (the default format becomes NETCDF3_64BIT).