def extract_points(
self,
points: List[Point],
new_dimension: str = 'point',
) -> xr.Dataset:
"""
Select data at the given points, discarding all other locations.
Any variables that do not use any of the surface dimensions are dropped.
Any horizontal topology information for this dataset is dropped.
Coordinate variables are kept.
Parameters
----------
points : list of shapely.geometry.Point
The points to extract
new_dimension : str
The name of the new dimension used to index the points.
Returns
-------
xarray.Dataset
A new dataset with data for the given points.
"""
Add a new operation extract_points() that calls the above method
and populates the dataset with extra fields from the CSV:
def extract_points(
dataset: emsarray.format.Format,
points: pandas.DataFrame,
longitude: str = 'lon',
latitude: str = 'lat',
) -> xr.Dataset:
"""
Extract point data from the dataset and combine it with the dataframe
to make a new dataset.
The points from the dataframe will be extracted from the dataset
using `Format.extract_points()`.
The columns from the dataframe will be appended to the dataset.
"""
Add a new command line entry point extract-points which opens the dataset using xarray, opens the csv using pandas, passes these to the operation, and saves the data to the output file.
Use case
Given a dataset covering a wide area with multiple timesteps and depth layers, extract data at a selection of lat/lon points supplied in a CSV.
Example CSV:
Extract the locations from
sites.csv
fromdataset.nc
and save the point data tosites.nc
:Implementation details
Add a new method
Format.extract_points()
:Add a new operation
extract_points()
that calls the above method and populates the dataset with extra fields from the CSV:Add a new command line entry point
extract-points
which opens the dataset using xarray, opens the csv using pandas, passes these to the operation, and saves the data to the output file./cc @frizwi