MetPy icon indicating copy to clipboard operation
MetPy copied to clipboard

Add linear path through projection coordinates to `cross_section` as alternative option to geodesic

Open jthielen opened this issue 3 years ago • 0 comments

What should we add?

Currently, metpy.interpolate.cross_section only operates by interpolating to a geodesic between specified start and end points. This becomes problematic when:

  • Data are not georeferenced (e.g., idealized cloud models)
  • User wants a straight path in the projection of their data (e.g., a rhumb line in lat/lon data)
  • User seeks one of the dimensions of target points to be aligned with source points (so as to minimize interpolation artifacts)

I'd like to see something like a new path_type kwarg on cross_section. It would default to "geodesic", which has current behavior, but we would add a new "linear" option, which would construct points something like the following:

x_range_source = data.metpy.x.metpy.sel(x=slice(start[0], end[0])).values
y_range_source = data.metpy.y.metpy.sel(y=slice(start[1], end[1])).values

if steps is None:
    steps = max(len(x_range_source), len(y_range_source))

x_range_target = np.linspace(x_range_source[0], x_range_source[-1], steps)
y_range_target = np.linspace(y_range_source[0], y_range_source[-1], steps)
    
points_cross = np.stack([x_range_target, y_range_target], axis=1)

Note this also makes steps an optional argument rather than defaulting to 100 (which we could probably still implement as default for the "geodesic" option for backwards compatibility). Also, I wrote this sketch assuming start and end are (x, y) pairs...which I like for projection coordinates over (y, x), but really don't like for lon and lat (since that is flipped from (lat, lon) used with geodesic). Not sure the best solution there.

Reference

No response

jthielen avatar Apr 29 '22 04:04 jthielen