Replies: 1 comment 3 replies
-
Given the current way that xarray does coordinate indexing, there are two options to explore for taking a cross section when you just have 2D longitude and latitude and not dimension coordinates from your source data: 1) Add in the dimension coordinates By using # Assign the CRS info
data = data.metpy.assign_crs({
'grid_mapping_name': 'mercator',
'longitude_of_projection_origin': 0,
'standard_parallel': 0
}
# Include dimension coordinates
data = data.metpy.assign_y_x()
# Proceed with cross section
start = (30, -77)
end = (45, -64)
cross = cross_section(data, start, end).set_coords(('nav_lon', 'nav_lat')) 2) Use xoak to directly, but slowly, index with longitude and latitude If you have no ability to get the true CRS information and are therefore stuck with just 2D longitude and latitude, then your next best option is to use from metpy.interpolate import geodesic
import pyproj
import xoak
# Set up search index
data.xoak.set_index(['nav_lat', 'nav_lon'], 'scipy_kdtree')
# Set up path of the cross section
wgs84 = pyproj.CRS(4326)
start = (30, -77)
end = (45, -64)
path = geodesic(wgs84, start, end, steps=100)
# Take the cross section
cross = data.xoak.sel(
nav_lat=xr.DataArray(cross[:, 1], dims='index', attrs=data.nav_lat.attrs),
nav_lon=xr.DataArray(cross[:, 0], dims='index', attrs=data.nav_lon.attrs)
) (note: the default value of |
Beta Was this translation helpful? Give feedback.
-
Dear MetPy team,
I've spent several hours today trying to plot cross section from NEMO ocean model output, but there are still issues.
I would be very grateful if you can advice me how to proceed with it.
My 2D lon and lats are stored in a separate file, like this:
My 3D data is in another file, like this:
The second file also contain nav_lat and nav_lon, but there is an issue with missing values in coors, so I need to use lats
and lons from the separate file.
I've tried to execute https://unidata.github.io/MetPy/latest/examples/cross_section.html#sphx-glr-examples-cross-section-py
example, but obviously got error message.
The thing is that I only have 2D lats and lons and no projection naming is available netcdf desscription.
This is how it looks:
Thank you very much for any advise!!!
Warm regards,
Natalia
Beta Was this translation helpful? Give feedback.
All reactions