You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While looking into #1445, I noticed that the coordinates in a variable (UxDataArray) were never handled properly as part of our remapping functions in remap/utils/_construct_remapped_ds(). There was only an attempt to remove coords matching the destination dimension as follows, but even that didn't work since so-called destination_dim was redesigned to be remap_to in the past, and its Literals wouldn't be in destination_coords. Also, it doesn't seem like the best way to handle the source coords.
destination_coords = deepcopy(source.coords)
if destination_dim in destination_coords:
del destination_coords[destination_dim]
This PR now introduces a new module spatial_coords_remap.py with the class SpatialCoordsRemapper to perform the following logic to handle remapping of coordinate variables in UxDataArray accordingly with the selected remap_to:
1. If `remap_to` matches the `source` dimension (e.g. `source` on face centers` and `remap_to="faces"` etc.)
- Swap values of spatial coords with values of the corresponding coords from `destination_grid`
2. Else (if `remap_to` doesn't match `source` dim (e.g. `source` on face centers but `remap_to="nodes"` etc.))
- Swap values of spatial coords with values of the coords from `destination_grid` that are defined on the `remap_to` dimension.
- Rename these coords to reflect new element type (e.g. 'face_x' → 'node_x')
These could be done under remap/utils.py, but since it involves several helper functions, doing it through a separate module and class made more sense to me.
Expected Usage
No expected usage of additional code, but when our remap functions are called, the coordinate variables under data variable will now be remapped properly.
Results
See below comment for before and after of the changes here.
PR Checklist
General
An issue is linked created and linked
Add appropriate labels
Filled out Overview and Expected Usage (if applicable) sections
Testing
Adequate tests are created if there is new functionality
Tests cover all possible logical paths in your function
Tests are not too basic (such as simply calling a function and nothing else)
Documentation
Docstrings have been added to all new functions
Docstrings have updated with any function changes
Internal functions have a preceding underscore (_) and have been added to docs/internal_api/index.rst
User functions have been added to docs/user_api/index.rst
Examples
Any new notebook examples added to docs/examples/ folder
Clear the output of all cells before committing
New notebook files added to docs/examples.rst toctree
New notebook files added to new entry in docs/gallery.yml with appropriate thumbnail photo in docs/_static/thumbnails/
Ho @Chrismarsh; I think I got things to work properly in this PR.
BEFORE
Even though remap_to="nodes" looked like working without errors in your code, coords were still not being handled properly throughout our remapping. See the "Elevation" source data and the resulting remapped data that lacks the coordinates below:
With the work in this PR, this is what I get now when I run your remap code:
remap = d['Elevation'].remap.bilinear(destination_grid=target_grid, remap_to="nodes")
(Note the changes from "face" to "node" strings in the coord names now since the destination dimension differs from the source dimension. If there was no string in the coord name that indicated dimension name, there wouldn't be any changes though):
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workingredesignContent relating to the ongoing redesign
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1445
Overview
While looking into #1445, I noticed that the coordinates in a variable (UxDataArray) were never handled properly as part of our remapping functions in
remap/utils/_construct_remapped_ds(). There was only an attempt to remove coords matching the destination dimension as follows, but even that didn't work since so-calleddestination_dimwas redesigned to beremap_toin the past, and itsLiteralswouldn't be indestination_coords. Also, it doesn't seem like the best way to handle the source coords.This PR now introduces a new module
spatial_coords_remap.pywith the classSpatialCoordsRemapperto perform the following logic to handle remapping of coordinate variables inUxDataArrayaccordingly with the selectedremap_to:These could be done under
remap/utils.py, but since it involves several helper functions, doing it through a separate module and class made more sense to me.Expected Usage
No expected usage of additional code, but when our remap functions are called, the coordinate variables under data variable will now be remapped properly.
Results
See below comment for before and after of the changes here.
PR Checklist
General
Testing
Documentation
_) and have been added todocs/internal_api/index.rstdocs/user_api/index.rstExamples
docs/examples/folderdocs/examples.rsttoctreedocs/gallery.ymlwith appropriate thumbnail photo indocs/_static/thumbnails/