pyfvcom2.cmems_reader module

Read CMEMS data

class pyfvcom2.cmems_reader.CMEMSReader(file_path: str | List[str], reference_var_name: str, dimension_var_names: dict | None = None)[source]

Bases: object

Class to read CMEMS Data files

close()[source]

Close all datasets to free up resources.

contains_date(date_time: datetime) bool[source]

Check if the dataset contains the given date_time.

Args:

date_time (datetime): Date time to check.

Returns:

bool: True if date_time is within the dataset time range, False otherwise.

property dates
property depth_levels
get_bottom_indices() ndarray[source]

Get indices of the deepest unmasked level for each horizontal point.

Returns:

np.ndarray: 2D array of bottom indices (lat, lon)

get_closest_date_index(date_time) int[source]

Get the index of the datetime variable closest to the given date_time.

Args:

date_time (datetime): Date time to find closest index for.

Returns:

int: Index of the closest time variable.

get_filled_2D_var(var_name: str, target_datetime: datetime, tolerance=None) ndarray[source]

Fill masked values in a 2D variable by interpolation.

Uses a Delaunay triangulation of unmasked ocean points to linearly interpolate over land-masked cells on the regular CMEMS grid.

Args:

var_name (str): Variable name. target_datetime (datetime): Target datetime to retrieve data for. tolerance (timedelta, optional): Maximum allowed time difference. Defaults to None.

Returns:

np.ndarray: Filled variable values on the full (lat, lon) grid.

get_filled_3D_var(var_name: str, target_datetime: datetime, tolerance=None) ndarray[source]

Fill masked values in a 3D variable by interpolation

First, use griddata to interpolate over all masked surface values. Then, for each horizontal point, fill masked depth levels by downward extrapolation from the nearest unmasked depth level.

Args:

var_name (str): Variable name. target_datetime (datetime): Target datetime to retrieve data for. tolerance (timedelta, optional): Maximum allowed time difference. Defaults to None.

Returns:

np.ndarray: Filled variable values.

get_filled_3D_var_by_index(var_name: str, time_index: int = 0) ndarray[source]

Backward compatibility method using time index

get_mask(var) ndarray[source]

Get the mask for a variable. Args:

var (xarray.DataArray): Variable to get the mask for.

Returns:

np.ndarray: Boolean mask array, where True indicates a masked value.

get_unmasked_var_by_index(var_name: str, time_index: int = 0, depth_index: int = None) ndarray[source]

Backward compatibility method using time index

get_unmasked_variable(var_name: str, target_datetime: datetime, depth_index: int = None, tolerance=None) ndarray[source]

Get the unmasked values of a variable at a given datetime and depth index.

Args:

var_name (str): Variable name. target_datetime (datetime): Target datetime to retrieve data for. depth_index (int, optional): Depth index for 3D variables. Defaults to None. tolerance (timedelta, optional): Maximum allowed time difference. Defaults to None.

Returns:

np.ndarray: Unmasked variable values.

get_var(var_name: str, target_datetime: datetime, depth_index: int = None, tolerance=None) ndarray[source]

Get the values of a variable at a given datetime and depth index.

Args:

var_name (str): Variable name. target_datetime (datetime): Target datetime to retrieve data for. depth_index (int, optional): Depth index for 3D variables. Defaults to None. tolerance (timedelta, optional): Maximum allowed time difference. Defaults to None.

Returns:

np.ndarray: Variable values.

get_var_by_index(var_name: str, time_index: int = 0, depth_index: int = None) ndarray[source]

Backward compatibility method using time index

get_var_ndims(var_name: str) int[source]

Get the number of dimensions of a variable.

Args:

var_name (str): Variable name.

Returns:

int: Number of dimensions.

property lats
property lats_2D
property lons
property lons_2D
property n_depths
property n_files

Get the number of files being used.

property time_span

Get the time span covered by the dataset.

property unmasked_lats
property unmasked_lons