I'm looking to select all data from an xarray
dataset that is between one point and another. This is of course easy with sel
for example with a dataset based on a lat/lon grid to subset from a global dataset to the Atlantic coastline I can do ds_geo_subset = ds.sel( lat=slice(42, 20), lon=slice(-85,-65))
but I want to select all data along the Gulf Stream front, basically from to point (-78 lon, 32 lat) to (-72 lon, 36 lat) but I'm not sure how to do this. Would this be best done by giving a full point dataset and getting data from each point or can these two end points be given to xarray and interpolated data returned?
Asked
Active
Viewed 792 times
3

DopplerShift
- 5,472
- 1
- 21
- 20

clifgray
- 4,313
- 11
- 67
- 116
-
You can find a solution for a similar problem here: https://stackoverflow.com/questions/58326202/how-to-plot-a-vertical-section-of-the-atmosphere-along-with-the-topography-using/58343518#58343518 – dl.meteo Oct 16 '20 at 07:50
1 Answers
4
As the comment above suggested, Metpy
has a specific function which can be handy for this task.
from metpy.interpolate import cross_section
data = xr.open_dataset('my_data')
# Define start and end points:
start = (-78, 32)
end = (-72, 36)
cross = cross_section(data, start, end).set_coords(('lat', 'lon'))
Here is a nice example to plot a cross-section.

Light_B
- 1,660
- 1
- 14
- 28