dataset
xarray extensions for velocity data
General Attributes and Methods
- class IceAdvect.io.dataset.Dataset(ds)[source]
Accessor for extending an
xarray.Datasetfor velocity data- assign_coords(x: ndarray, y: ndarray, crs: str | int | dict = 4326, **kwargs)[source]
Assign new coordinates to the
Dataset- Parameters:
- x: np.ndarray
Updated x-coordinates
- y: np.ndarray
Updated y-coordinates
- crs: str, int, or dict, default 4326 (WGS84 Latitude/Longitude)
Coordinate reference system of coordinates
- kwargs: dict
Keyword arguments for
xarray.Dataset.assign_coords
- Returns:
- ds: xarray.Dataset
Datasetwith updated coordinates
- barycentric_interp(x: ndarray, y: ndarray, **kwargs)[source]
Interpolate unstructured
Datasetsusing a barycentric method with first or second order triangular finite elements- Parameters:
- x: np.ndarray
Interpolation x-coordinates
- y: np.ndarray
Interpolation y-coordinates
- order: int
Polynomial order of the triangular elements
1: linear2: quadratic
- cutoff: int or float, default np.inf
Maximum distance to check for elements
- Returns:
- other: xarray.Dataset
Interpolated
Dataset
- coords_as(x: ndarray, y: ndarray, crs: str | int | dict = 4326, **kwargs)[source]
Transform coordinates into
DataArraysin theDatasetcoordinate reference system- Parameters:
- x: np.ndarray
Input x-coordinates
- y: np.ndarray
Input y-coordinates
- crs: str, int, or dict, default 4326 (WGS84 Latitude/Longitude)
Coordinate reference system of input coordinates
- Returns:
- X: xarray.DataArray
Transformed x-coordinates
- Y: xarray.DataArray
Transformed y-coordinates
- crop(bounds: list | tuple, buffer: int | float = 0)[source]
Crop
Datasetto input bounding box- Parameters:
- bounds: list, tuple
Bounding box [min_x, max_x, min_y, max_y]
- buffer: int or float, default 0
Buffer to add to bounds for cropping
- get(name: str)[source]
Get variable in
Datasetusing a case-insensitive search- Parameters:
- name: str
Name of variable to find in dataset
- Returns:
- var: xarray.DataArray or None
Variable from dataset if found, otherwise None
- grid_interp(x: ndarray, y: ndarray, method='linear', **kwargs)[source]
Interpolate a regular or rectilinear
Datasetto new coordinates- Parameters:
- x: np.ndarray
Interpolation x-coordinates
- y: np.ndarray
Interpolation y-coordinates
- method: str, default ‘linear’
Interpolation method
- Returns:
- other: xarray.Dataset
Interpolated
Dataset
- inpaint(**kwargs)[source]
Inpaint over missing data in
Dataset- Parameters:
- kwargs: dict
Keyword arguments for
IceAdvect.interpolate.inpaint()
- Returns:
- ds: xarray.Dataset
Interpolated
Dataset
- interp(x: ndarray, y: ndarray, **kwargs)[source]
Interpolate
Datasetto new coordinates- Parameters:
- x: np.ndarray
Interpolation x-coordinates
- y: np.ndarray
Interpolation y-coordinates
- kwargs: dict
Additional keyword arguments for interpolation functions
- Returns:
- other: xarray.Dataset
Interpolated
Dataset
- run(**kwargs)[source]
Advect coordinates using the velocity field in the
Dataset- Parameters:
- kwargs: dict
keyword arguments for
IceAdvect.advect.Advect
- Returns:
- x0: np.ndarray
Advected x-coordinates
- y0: np.ndarray
Advected y-coordinates
- transform_as(x: ndarray, y: ndarray, crs: str | int | dict = 4326, **kwargs)[source]
Transform coordinates to/from the
Datasetcoordinate reference system- Parameters:
- x: np.ndarray
Input x-coordinates
- y: np.ndarray
Input y-coordinates
- crs: str, int, or dict, default 4326 (WGS84 Latitude/Longitude)
Coordinate reference system of input coordinates
- direction: str, default ‘FORWARD’
Direction of transformation
'FORWARD': from input crs to model crs'INVERSE': from model crs to input crs
- Returns:
- X: np.ndarray
Transformed x-coordinates
- Y: np.ndarray
Transformed y-coordinates
- to_units(units: str, value: float = 1.0)[source]
Convert
Datasetto specified velocity units- Parameters:
- units: str
Output units
- value: float, default 1.0
Scaling factor to apply
- property area_of_use: str | None
Area of use from the
DatasetCRS
- property axis_units: str
Units of the coordinate axes from the
DatasetCRS
- property crs
Coordinate reference system of the
Dataset
- property divergence
Calculate the divergence of a velocity field
- property grid_type: str
Spatial structure of the
Dataset
- property speed
Calculate the speed from a velocity field
- class IceAdvect.io.dataset.DataArray(da)[source]
Accessor for extending an
xarray.DataArrayfor velocity data- crop(bounds: list | tuple, buffer: int | float = 0)[source]
Crop
DataArrayto input bounding box- Parameters:
- bounds: list, tuple
bounding box [min_x, max_x, min_y, max_y]
- buffer: int or float, default 0
buffer to add to bounds for cropping
- to_units(units: str, value: float = 1.0)[source]
Convert
DataArrayto specified units- Parameters:
- units: str
Output units
- value: float, default 1.0
Scaling factor to apply
- to_base_units(value=1.0)[source]
Convert
DataArrayto base units- Parameters:
- value: float, default 1.0
Scaling factor to apply
- property units
Units of the
DataArray
- property quantity
PintQuantity of theDataArray
- IceAdvect.io.dataset.combine_attrs(attrs_list: list[dict], context: str | None, **kwargs) dict[source]
Combine attributes from multiple datasets into a single dictionary merging conflicting values into a list
- Parameters:
- attrs_list: list of dict
List of attribute dictionaries from multiple datasets
- context: str
Context for the attributes being combined
- skip_keys: list of str, default [“units”]
List of attribute keys to skip from comparison
- Returns:
- result: dict
Combined attributes dictionary
- IceAdvect.io.dataset.equivalent_attrs(a: Any, b: Any) bool[source]
Check if two attribute values are equivalent (ignoring case for strings)
Adapted from
xarray.structure.merge.equivalent_attrs- Parameters:
- a: Any
First attribute value
- b: Any
Second attribute value
- IceAdvect.io.dataset.get_variable(ds: Dataset, name: str) DataArray[source]
Get variable from a
Datasetusing a case-insensitive search- Parameters:
- ds: xarray.Dataset
Dataset to search for variable
- name: str
Name the variable to find
- Returns:
- var: xarray.DataArray
Variable matching the input name
- IceAdvect.io.dataset.register_dataset_subaccessor(name)[source]
Register a custom subaccessor on
Datasetobjects- Parameters:
- name: str
Name of the subaccessor
- IceAdvect.io.dataset.register_dataarray_subaccessor(name)[source]
Register a custom subaccessor on
DataArrayobjects- Parameters:
- name: str
Name of the subaccessor
- IceAdvect.io.dataset._transform(i1: ndarray, i2: ndarray, source_crs: str | int | dict = 4326, target_crs: str | int | dict = None, **kwargs)[source]
Transform coordinates to/from the dataset coordinate reference system
- Parameters:
- i1: np.ndarray
Input x-coordinates
- i2: np.ndarray
Input y-coordinates
- source_crs: str, int, or dict, default 4326 (WGS84 Latitude/Longitude)
Coordinate reference system of input coordinates
- target_crs: str, int, or dict, default None
Coordinate reference system of output coordinates
- direction: str, default ‘FORWARD’
Direction of transformation
'FORWARD': from input crs to model crs'INVERSE': from model crs to input crs
- Returns:
- o1: np.ndarray
Transformed x-coordinates
- o2: np.ndarray
Transformed y-coordinates
- IceAdvect.io.dataset._coords(x: ndarray, y: ndarray, source_crs: str | int | dict = 4326, target_crs: str | int | dict = None, **kwargs)[source]
Transform coordinates into DataArrays in a new coordinate reference system
- Parameters:
- x: np.ndarray
Input x-coordinates
- y: np.ndarray
Input y-coordinates
- source_crs: str, int, or dict, default 4326 (WGS84 Latitude/Longitude)
Coordinate reference system of input coordinates
- target_crs: str, int, or dict, default None
Coordinate reference system of output coordinates
- type: str or None, default None
Coordinate data type
If not provided: must specify
timeparameter to auto-detectNone: determined from input variable dimensions'drift': drift buoys or satellite/airborne altimetry'grid': spatial grids or images'time series': time series at a single point
- time: np.ndarray or None, default None
Time variable for determining coordinate data type
- Returns:
- X: xarray.DataArray
Transformed x-coordinates
- Y: xarray.DataArray
Transformed y-coordinates