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 as follows, but it didn't work either since so-called destination_dim was redesigned to be remap_to in the past, and its Literals wouldn;t be in destination_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:

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`

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 several helper functions were needed for this purpose, a separate module and class made more sense.

Expected Usage

No expected usage of additional code, but when our remap functions are called, the coordinate variables under data variable will be remapped properly as well.

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.

This is what I get now when I run your remap code with remap_to="face" (and remap_to="nodes" also works, but please see the logic for that I've described in the first message of the PR):

<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

Also this:

image

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