deepsensor.data.utils

deepsensor.data.utils#

compute_pandas_data_resolution(df, n_times=1000, percentile=5)[source]#

Approximates the resolution of non-gridded pandas data with indexes time, x1, and x2.

The resolution is approximated as the Nth percentile of the distances between neighbouring observations, possibly using a subset of the dates in the data. The default is to use 1000 dates (or all dates if there are fewer than 1000) and to use the 5th percentile. This means that the resolution is the distance between the closest 5% of neighbouring observations.

Parameters:
  • df (pandas.DataFrame | pandas.Series) – Dataframe or series with indexes time, x1, and x2.

  • n_times (int, optional) – Number of dates to sample. Defaults to 1000. If “all”, all dates are used.

  • percentile (int, optional) – Percentile of pairwise distances for computing the resolution. Defaults to 5.

Returns:

float – Resolution of the data (in spatial units, e.g. 0.1 degrees).

compute_xarray_data_resolution(ds)[source]#

Computes the resolution of an xarray object with coordinates x1 and x2.

The data resolution is the finer of the two coordinate resolutions (x1 and x2). For example, if x1 has a resolution of 0.1 degrees and x2 has a resolution of 0.2 degrees, the data resolution returned will be 0.1 degrees.

Parameters:

ds (xarray.DataArray | xarray.Dataset) – Xarray object with coordinates x1 and x2.

Returns:

float – Resolution of the data (in spatial units, e.g. 0.1 degrees).

construct_circ_time_ds(dates, freq)[source]#

Return an xarray.Dataset containing a circular variable for time. The freq entry dictates the frequency of cycling of the circular variable. E.g.:

  • 'H': cycles once per day at hourly intervals

  • 'D': cycles once per year at daily intervals

  • 'M': cycles once per year at monthly intervals

Parameters:
  • dates

  • freq

Returns:

xarray.Dataset

construct_x1x2_ds(gridded_ds)[source]#

Construct an xarray.Dataset containing two vars, where each var is a 2D gridded channel whose values contain the x_1 and x_2 coordinate values, respectively.

Parameters:

gridded_ds (xarray.Dataset) –

Returns:

xarray.Dataset