TfvTimeseries

class tfv.xarray.TfvTimeseries(xarray_obj)

Xarray accessor object for working with TUFLOW FV timeseries profile netcdf files.

Extends the functionality of native xarray to assist with navigating and extracting data from the grouped netcdf profile timeseries files.

To use, call the .tfv method on an xarray dataset based on a TUFLOW FV timeseries file.

get_location(location: str) xarray.Dataset

Get individual profile dataset

Returns a native Xarray dataset for a single profile location. This can be alternatively accessed via a dictionary .tfv.ds[location]

Parameters:

locations (str) – Location name to extract. (see .locations method for the list of stored locations)

Returns:

Individual profile dataset

Return type:

xr.Dataset

get_timeseries(locations: str | list | None = None, variables: str | list | None = None, time: str | int | Timestamp | slice | None = None, datum: Literal['sigma', 'height', 'depth', 'elevation'] = 'sigma', limits: tuple = (0, 1), agg: Literal['min', 'mean', 'max'] = 'mean')

Extract 1D timeseries at location(s).

Method to extract 1D timeseries at one, or several locations from the dataset. This method will handle dimension reduction, by default using depth-averaging.

Note

This method can be slow for many locations and long-timeseries, as each profile location is effectively a standalone dataset.

Parameters:
  • locations (Union[str, list]) – Location names to extract (see .locations method for the list of stored locations)

  • variables ([str, list]) – variables to extract. Defaults to all. (“V” or “VDir” may be requested if “V_x” and “V_y” are present).

  • time ([str, pd.Timestamp, int, slice], optional) – time indexer for extraction. Defaults to the entire dataset.

  • datum (['sigma', 'height', 'depth', 'elevation'], optional) – depth-averaging datum. Defaults to ‘sigma’. Choose from height, depth, elevation or sigma.

  • limits (tuple, optional) – depth-averaging limits. Defaults to (0,1).

  • agg (['min', 'mean', 'max'], optional) – depth-averaging aggregation function. Defaults to ‘mean’. Choose from min, mean, or max.

Returns:

A timeseries dataset in xarray format

Return type:

xr.Dataset

plot(variable: str | None = None, location: str | None = None, time: str | Timestamp | int = 0, ax=None, **kwargs)

Plots a profile at a single time

Simple method to draw a profile through depth at a single timestep. The profile is shown on the layerfaces of the model (i.e., the vertical cell “edges”) based on linear interpolation from the vertical cell centers.

Parameters:
  • variable (str, optional) – variable to plot. Defaults to the first variable.

  • location (str, optional) – profile location to plot. Defaults to first location.

  • time ([str, pd.Timestamp, int], optional) – Time to plot. Defaults to 0.

  • ax (plt.Axes, optional) – Matplotlib axis to draw profile. Default is to create a new figure unless specified.

  • kwargs (dict, optional) – Keyword arguments passed to matplotlib’s pyplot.plot method.

Returns:

Array containing profile data, interpolated linearly to the layerfaces

Return type:

np.ndarray