Skip to content

Conversation

@erogluorhan
Copy link
Member

@erogluorhan erogluorhan commented Feb 11, 2026

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-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/

@erogluorhan erogluorhan added bug Something isn't working redesign Content relating to the ongoing redesign labels Feb 11, 2026
@erogluorhan erogluorhan marked this pull request as ready for review February 11, 2026 23:46
@erogluorhan
Copy link
Member Author

erogluorhan commented Feb 11, 2026

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:

Source data d['Elevation']:
image

remap = d['Elevation'].remap.bilinear(destination_grid=target_grid, remap_to="nodes"):
image

remap = d['Elevation'].remap.bilinear(destination_grid=target_grid, remap_to="faces"):
image

AFTER

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):

image

remap = d['Elevation'].remap.bilinear(destination_grid=target_grid, remap_to="faces"):
image

, and this is what _repr_ of remap looks like:

<xarray.UxDataArray 'Elevation' (n_face: 24)> Size: 192B
array([   0.        ,    0.        ,    0.        ,    0.        ,
          0.        ,    0.        ,    0.        , 2334.99019305,
       2443.21600575, 2403.05130305, 2546.70042427,    0.        ,
          0.        , 2247.70454272, 1790.09868875, 1705.08767541,
       2434.87824971,    0.        ,    0.        ,    0.        ,
          0.        ,    0.        ,    0.        ,    0.        ])
Coordinates:
    Mesh2_face_x  (n_face) float64 192B -115.6 -115.4 -115.3 ... -115.1 -115.0
    Mesh2_face_y  (n_face) float64 192B 50.61 50.61 50.61 ... 51.06 51.06 51.06
Dimensions without coordinates: n_face
Attributes:
    _QuantizeBitGroomNumberOfSignificantDigits:  4
    mesh:                                        Mesh2
    location:                                    face

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working redesign Content relating to the ongoing redesign

Projects

None yet

Development

Successfully merging this pull request may close these issues.

conflicting sizes for dimension 'n_face' when regridding

1 participant