Skip to content

topological_mean doesn't preserve coordinate dtype #1447

@Chrismarsh

Description

@Chrismarsh

Version

2025.11.0

How did you install UXarray?

Source

What happened?

topological_mean doesn't preserve the dtype of the input coordinates:

Remap to nodes:

>>> remap = ds_in.remap.bilinear(destination_grid=target_grid, remap_to="nodes")
>>> print(remap)


<xarray.UxDataset> Size: 2MB
Dimensions:             (time: 2, met: 2, n_node: 35, n_face: 142546)
Coordinates:
  * time                (time) datetime64[ns] 16B 2018-04-28 2023-03-22
  * met                 (met) object 16B 'hrdps' 'capa'
    Mesh2_face_x        (n_face) float64 1MB -115.1 -115.0 ... -115.4 -115.4
    Mesh2_face_y        (n_face) float64 1MB 50.62 50.64 50.63 ... 50.87 50.87
Dimensions without coordinates: n_node, n_face
Data variables:
    Elevation           (time, met, n_node) float64 1kB dask.array<chunksize=(1, 1, 35), meta=np.ndarray>
    snowdepthavg_vert   (time, met, n_node) float64 1kB dask.array<chunksize=(1, 1, 35), meta=np.ndarray>
    param_CanopyHeight  (time, met, n_node) float64 1kB dask.array<chunksize=(1, 1, 35), meta=np.ndarray>

where time and met look like:

>>>print(remap.met)
print(remap.time)


<xarray.UxDataArray 'met' (met: 2)> Size: 16B
array(['hrdps', 'capa'], dtype=object)
Coordinates:
  * met      (met) object 16B 'hrdps' 'capa'
<xarray.UxDataArray 'time' (time: 2)> Size: 16B
array(['2018-04-28T00:00:00.000000000', '2023-03-22T00:00:00.000000000'],
      dtype='datetime64[ns]')
Coordinates:
  * time     (time) datetime64[ns] 16B 2018-04-28 2023-03-22
Attributes:
    standard_name:  time
    long_name:      Time

Then remap the nodes back to the face

>>> tmp=remap['Elevation'].topological_mean(destination="face")
>>> tmp.time.values
array([0, 1])
>>> tmp.met.values
array([0, 1])

What did you expect to happen?

to keep the coordinate values

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    📚 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions