emsarray.operations.point_extraction#

exception emsarray.operations.point_extraction.NonIntersectingPoints(indices, points)#

Raised when a point to extract does not intersect the dataset geometry.

emsarray.operations.point_extraction.extract_dataframe(dataset, dataframe, coordinate_columns, *, point_dimension='point')#

Extract the points listed in a pandas DataFrame, and merge the remaining columns in to the Dataset.

Parameters
  • dataset (xarray.Dataset) – The dataset to extract point data from

  • dataframe (pandas.DataFrame) – A dataframe with longitude and latitude columns, and possibly other columns.

  • coordinate_columns (tuple of str, str) – The names of the longitude and latitude columns in the dataframe.

  • point_dimension (Hashable, optional) – The name of the new dimension to create in the dataset. Optional, defaults to “point”.

Returns

xarray.Dataset – A new dataset that only contains data at the given points, plus any new columns present in the dataframe.

Example

import emsarray
import pandas as pd
from emsarray.operations import point_extraction

ds = emsarray.tutorial.open_dataset('gbr4')
df = pd.DataFrame({
    'lon': [152.807, 152.670, 153.543],
    'lat': [-24.9595, -24.589, -25.488],
    'name': ['a', 'b', 'c'],
})
point_data = point_extraction.extract_dataframe(
    ds, df, ['lon', 'lat'])
point_data
<xarray.Dataset>
Dimensions:  (k: 47, point: 3, time: 1)
Coordinates:
    zc       (k) float32 ...
  * time     (time) datetime64[ns] 2022-05-11T14:00:00
    lon      (point) float64 152.8 152.7 153.5
    lat      (point) float64 -24.96 -24.59 -25.49
Dimensions without coordinates: k, point
Data variables:
    botz     (point) float32 ...
    eta      (time, point) float32 ...
    salt     (time, k, point) float32 ...
    temp     (time, k, point) float32 ...
    name     (point) object 'a' 'b' 'c'
Attributes: (12/14)
    ...