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)
Bases:
objectClass to read CMEMS Data files
- close()
Close all datasets to free up resources.
- contains_date(date_time: datetime) bool
Check if the dataset contains the given date_time.
- Parameters:
date_time (datetime) – Date time to check.
- Returns:
True if date_time is within the dataset time range, False otherwise.
- Return type:
bool
- property dates
- property depth_levels
- get_bottom_indices() ndarray
Get indices of the deepest unmasked level for each horizontal point.
- Returns:
2D array of bottom indices (lat, lon)
- Return type:
np.ndarray
- get_closest_date_index(date_time) int
Get the index of the datetime variable closest to the given date_time.
- Parameters:
date_time (datetime) – Date time to find closest index for.
- Returns:
Index of the closest time variable.
- Return type:
int
- get_filled_2D_var(var_name: str, target_datetime: datetime, tolerance=None) ndarray
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.
- Parameters:
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:
Filled variable values on the full (lat, lon) grid.
- Return type:
np.ndarray
- get_filled_3D_var(var_name: str, target_datetime: datetime, tolerance=None) ndarray
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.
- Parameters:
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:
Filled variable values.
- Return type:
np.ndarray
- get_filled_3D_var_by_index(var_name: str, time_index: int = 0) ndarray
Backward compatibility method using time index
- get_mask(var) ndarray
Get the mask for a variable. :param var: Variable to get the mask for. :type var: xarray.DataArray
- Returns:
Boolean mask array, where True indicates a masked value.
- Return type:
np.ndarray
- get_unmasked_var_by_index(var_name: str, time_index: int = 0, depth_index: int = None) ndarray
Backward compatibility method using time index
- get_unmasked_variable(var_name: str, target_datetime: datetime, depth_index: int = None, tolerance=None) ndarray
Get the unmasked values of a variable at a given datetime and depth index.
- Parameters:
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:
Unmasked variable values.
- Return type:
np.ndarray
- get_var(var_name: str, target_datetime: datetime, depth_index: int = None, tolerance=None) ndarray
Get the values of a variable at a given datetime and depth index.
- Parameters:
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:
Variable values.
- Return type:
np.ndarray
- get_var_by_index(var_name: str, time_index: int = 0, depth_index: int = None) ndarray
Backward compatibility method using time index
- get_var_ndims(var_name: str) int
Get the number of dimensions of a variable.
- Parameters:
var_name (str) – Variable name.
- Returns:
Number of dimensions.
- Return type:
int
- 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