dataset
xarray extensions for tidal model data
General Attributes and Methods
- class pyTMD.io.dataset.DataTree(dtree)[source]
Accessor for extending an
xarray.DataTreefor tidal model data- assign_coords(x: ndarray, y: ndarray, crs: str | int | dict = 4326, **kwargs)[source]
Assign new coordinates to the
DataTree- 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:
- dtree: xarray.DataTree
DataTreewith updated coordinates
- coords_as(x: ndarray, y: ndarray, crs: str | int | dict = 4326, **kwargs)[source]
Transform coordinates into
DataArraysin theDataTreecoordinate 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
- interp(x: ndarray, y: ndarray, **kwargs)[source]
Interpolate
DataTreeto new coordinates- Parameters:
- x: np.ndarray
Interpolation x-coordinates
- y: np.ndarray
Interpolation y-coordinates
- subset(c: str | list)[source]
Reduce to a subset of constituents
- Parameters:
- c: str or list
List of constituents names
- transform_as(x: ndarray, y: ndarray, crs: str | int | dict = 4326, **kwargs)[source]
Transform coordinates to/from the
DataTreecoordinate 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_ellipse(**kwargs)[source]
Expresses tidal currents in terms of four ellipse parameters
- Returns:
- dtree: xr.DataTree
DataTreecontaining:major: amplitude of the semi-major axisminor: amplitude of the semi-minor axisincl: angle of inclination of the northern semi-major axisphase: phase lag of the current behind the tidal potential
- from_ellipse(**kwargs)[source]
Calculates tidal currents from the four ellipse parameters
major: amplitude of the semi-major axisminor: amplitude of the semi-minor axisincl: angle of inclination of the northern semi-major axisphase: phase lag of the current behind the tidal potential
- Returns:
- dtree: xr.DataTree
DataTreecontaining transports or currents
- property crs
Coordinate reference system of the
DataTree
- atlas
alias of
ATLASDataTree
- otis
alias of
OTISDataTree
- class pyTMD.io.dataset.Dataset(ds)[source]
Accessor for extending an
xarray.Datasetfor tidal model 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
- extrap_like(other: Dataset, **kwargs)[source]
Extrapolate missing values in
Datasetusing nearest-neighbors or inverse distance weighting- Parameters:
- other: xarray.Dataset
Datasetwith missing values to be extrapolated- kwargs: dict
Keyword arguments for
pyTMD.interpolate._query_tree()
- Returns:
- other: xarray.Dataset
Datasetwith extrapolated values
- 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
- infer(t: float | ndarray, **kwargs)[source]
Infer minor tides from
Datasetat times- Parameters:
- t: float or np.ndarray
Days relative to 1992-01-01T00:00:00 UTC
- kwargs: dict
Keyword arguments for
pyTMD.predict.infer_minor()
- Returns:
- darr: xarray.DataArray
Predicted tides
- inpaint(**kwargs)[source]
Inpaint over missing data in
Dataset- Parameters:
- kwargs: dict
Keyword arguments for
pyTMD.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
- extrapolate: bool, default False
Spatially extrapolate values beyond model domain
- cutoff: int or float, default np.inf
Maximum distance for extrapolation
- k: int, default 1
Number of nearest neighbors to use for extrapolation
1: nearest neighbor (NN)>1: inverse distance weighting (IDW)
- power: int or float, default 2
Power parameter for inverse distance weighting extrapolation
- workers: int, default 1
Number of workers to use for parallel extrapolation
- kwargs: dict
Keyword arguments for interpolation functions
- Returns:
- other: xarray.Dataset
Interpolated
Dataset
- node_equilibrium()[source]
Compute the equilibrium amplitude and phase of the 18.6 year node tide [11, 12]
- pad(n: int = 1, chunks=None)[source]
Pad
Datasetby repeating edge values in the x-direction- Parameters:
- n: int, default 1
Number of padding values to add on each side
- Returns:
- ds: xarray.Dataset
Padded
Dataset
- predict(t: float | ndarray, **kwargs)[source]
Predict tides from
Datasetat times- Parameters:
- t: float or np.ndarray
Days relative to 1992-01-01T00:00:00 UTC
- kwargs: dict
Keyword arguments for
pyTMD.predict.time_series()
- Returns:
- darr: xarray.DataArray
Predicted tides
- subset(c: str | list)[source]
Reduce to a subset of constituents
- Parameters:
- c: str or list
List of constituents names
- 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 tide units- Parameters:
- units: str
Output units
- value: float, default 1.0
Scaling factor to apply
- property constituents
List of tidal constituent names in the
Dataset
- property crs
Coordinate reference system of the
Dataset
- property is_global: bool
Determine if
Datasetcovers a global domain
- 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 grid_type: str
Spatial structure of the
Dataset
- atlas
alias of
ATLASDataset
- compact
alias of
CompactDataset
- fes
alias of
FESDataset
- got
alias of
GOTDataset
- otis
alias of
OTISDataset
- class pyTMD.io.dataset.DataArray(da)[source]
Accessor for extending an
xarray.DataArrayfor tidal model data- property amplitude
Calculate the amplitude of a tide model constituent
- Returns:
- amp: xarray.DataArray
Tide model constituent amplitude
- property phase
Calculate the phase of a tide model constituent
- Returns:
- ph: xarray.DataArray
Tide model constituent phase (degrees)
- find_peaks(**kwargs)[source]
Find peaks in the
DataArray- Parameters:
- kwargs: dict
Keyword arguments for
xarray.DataArray.differentiate
- Returns:
- high_peaks: xarray.DataArray
Boolean array indicating locations of high tide peaks
- low_peaks: xarray.DataArray
Boolean array indicating locations of low tide peaks
- to_units(units: str, value: float = 1.0)[source]
Convert
DataArrayto specified tide 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
- to_default_units(value=1.0)[source]
Convert
DataArrayto default tide units- Parameters:
- value: float, default 1.0
Scaling factor to apply
- property units
Units of the
DataArray
- property quantity
PintQuantity of theDataArray
- property group
Variable group of the
DataArray
- pyTMD.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
- pyTMD.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
- pyTMD.io.dataset.register_datatree_subaccessor(name)[source]
Register a custom subaccessor on
DataTreeobjects- Parameters:
- name: str
Name of the subaccessor
- pyTMD.io.dataset.register_dataset_subaccessor(name)[source]
Register a custom subaccessor on
Datasetobjects- Parameters:
- name: str
Name of the subaccessor
- pyTMD.io.dataset.register_dataarray_subaccessor(name)[source]
Register a custom subaccessor on
DataArrayobjects- Parameters:
- name: str
Name of the subaccessor
- pyTMD.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
- pyTMD.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