Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distance along cross section to interpolate_to_slice #2462

Open
jthielen opened this issue Apr 28, 2022 · 1 comment
Open

Add distance along cross section to interpolate_to_slice #2462

jthielen opened this issue Apr 28, 2022 · 1 comment
Labels
Area: Cross-sections Pertains to making cross-sections through data good first issue Straightforward issues suitable for new and inexperienced contributors to the project Type: Feature New functionality

Comments

@jthielen
Copy link
Collaborator

What should we add?

Currently, MetPy's metpy.interpolate.cross_section and metpy.interpolate.interpolate_to_slice return DataArrays/Datasets with an added "index" dimension coordinate that simply contains the range of the slice's length. For many applications (particularly plotting), the distance along the slice is much more useful, and often something I've seen people need to hack onto the DataArray/Dataset after the fact. I'm thinking we could easily add this by replacing

data_sliced.coords['index'] = range(len(points))

with something like

data_sliced.coords['distance'] = xr.DataArray(
    np.linalg.norm(points - points[0], axis=1),
    dims='index',
    coords={'index': range(len(points))},
    attrs=(
        {'units': x.attrs['units']}
        if getattr(x.attrs, 'units', None) == getattr(y.attrs, 'units', None)
        else {}
    )
)

This is just a mock-up, I think the real version should:

  • take distance_coord_name as a optional kwarg (just in case a user already has something else called "distance" in their data)
  • verify proper handling of both units-on-attribute and units-in-quantity

Reference

No response

@jthielen jthielen added Type: Feature New functionality good first issue Straightforward issues suitable for new and inexperienced contributors to the project Area: Cross-sections Pertains to making cross-sections through data labels Apr 28, 2022
@eldertiger
Copy link

Seems this hasn't been added to the slices.py, it's really a nice feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Cross-sections Pertains to making cross-sections through data good first issue Straightforward issues suitable for new and inexperienced contributors to the project Type: Feature New functionality
Projects
Status: No status
Development

No branches or pull requests

2 participants