tams.data_in_contours

tams.data_in_contours#

tams.data_in_contours(data, contours, *, agg=('mean', 'std', 'count'), method='sjoin', merge=False)#

Compute statistics on data within the shapes of contours.

With the default settings, we calculate, for each shape (row) in the contours dataframe:

  • the mean value of data within the shape

  • the standard deviation of data within the shape

  • the count of non-null values of data within the shape

Parameters:
  • data (xarray.DataArray | xarray.Dataset | pandas.DataFrame | geopandas.GeoDataFrame) – It should have 'lat' and 'lon' coordinates. If you pass a xarray.Dataset, all data_vars will be included. If you pass a dataframe (supported for default method 'sjoin'), all columns except {'time', 'lat', 'lon', 'geometry'} will be included.

  • contours (geopandas.GeoDataFrame) – For example, a dataframe of CE or MCS shapes, e.g. from identify() or track().

  • agg (sequence of str or callable()) – Suitable for passing to pandas.DataFrame.aggregate().

  • method ({'sjoin', 'regionmask'}) – The regionmask method is suited for data on a structured grid, while the GeoPandas sjoin method works for scattered point data as well. The sjoin method is the default since it is more general and currently often faster.

  • merge (bool) – Whether to merge the new data with contours or return a separate frame. If false (default), the index of the returned non-geo frame will be the same as that of contours (e.g. a row corresponding to an individual CE or MCS at a certain time).

Raises:

ValueError – If the input data is all null or the input frame of shapes is empty.

Return type:

pandas.DataFrame | geopandas.GeoDataFrame