Skip to content

unable to unstack in cfradial1 io due to duplicate value in elevation dim #317

@chiaweh2

Description

@chiaweh2

Hi All,

I am currently testing opening a SPol Radar data from https://data.eol.ucar.edu/dataset/342655. The file can be open fine when using the xarray cfradial1 engine or PyART but encounter the following error when doing xd.io.open_cfradial1_datatree(file)

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/test_xradar/.venv/lib/python3.11/site-packages/xarray/core/dataset.py", line 5606, in unstack
    result = result._unstack_once(d, stacked_indexes[d], fill_value, sparse)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/test_xradar/.venv/lib/python3.11/site-packages/xarray/core/dataset.py", line 5426, in _unstack_once
    new_indexes, clean_index = index.unstack()
                               ^^^^^^^^^^^^^^^
  File "/test_xradar/.venv/lib/python3.11/site-packages/xarray/core/indexes.py", line 1131, in unstack
    raise ValueError(
ValueError: Cannot unstack MultiIndex containing duplicates. Make sure entries are unique, e.g., by  calling ``.drop_duplicates('n_points')``, before unstacking.

The traceback error point to the following line of unstacking

rslice = slice(0, current_ray_n_gates[0].values.astype(int))
ds = ds.isel(range=rslice)
ds = ds.isel(n_points=nslice)
ds_vars = ds[data_vars]
ds_vars = merge([ds_vars, ds[[dim0, "range"]]], compat="no_conflicts")
ds_vars = ds_vars.stack(n_points=[dim0, "range"])
ds_vars = ds_vars.unstack("n_points")

And like the error mentioned the stacked dim elevation in the previous line does have duplicate values shown below

Image

which resulted in the error of unable to unstack. Is the dimension here rarely or should not have duplicate values? Thank you all!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions