eX-Mech / pymech

A Python software suite for Nek5000 and SIMSON
https://pymech.readthedocs.io/en/stable
GNU General Public License v3.0
24 stars 24 forks source link

Error in xarray #114

Open ricardofrantz opened 3 months ago

ricardofrantz commented 3 months ago

Hey pymechs,

When trying to read a field with xarray wrapper, I have the error :

  File "/Users/r/Desktop/bffunc.py", line 1583, in rdnek3d
    ds = open_dataset(fname)
         ^^^^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/pymech/dataset.py", line 57, in open_dataset
    return _open(path, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/pymech/dataset.py", line 93, in _open_nek_dataset
    ds = xr.combine_by_coords(elem_dsets, combine_attrs="drop")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/combine.py", line 958, in combine_by_coords
    concatenated_grouped_by_data_vars = tuple(
                                        ^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/combine.py", line 959, in <genexpr>
    _combine_single_variable_hypercube(
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/combine.py", line 630, in _combine_single_variable_hypercube
    concatenated = _combine_nd(
                   ^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/combine.py", line 232, in _combine_nd
    combined_ids = _combine_all_along_first_dim(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/combine.py", line 267, in _combine_all_along_first_dim
    new_combined_ids[new_id] = _combine_1d(
                               ^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/combine.py", line 290, in _combine_1d
    combined = concat(
               ^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/concat.py", line 276, in concat
    return _dataset_concat(
           ^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/concat.py", line 513, in _dataset_concat
    align(*datasets, join=join, copy=False, exclude=[dim], fill_value=fill_value)
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/alignment.py", line 882, in align
    aligner.align()
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/alignment.py", line 582, in align
    self.reindex_all()
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/alignment.py", line 557, in reindex_all
    self.results = tuple(
                   ^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/alignment.py", line 558, in <genexpr>
    self._reindex_one(obj, matching_indexes)
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/alignment.py", line 544, in _reindex_one
    dim_pos_indexers = self._get_dim_pos_indexers(matching_indexes)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/alignment.py", line 510, in _get_dim_pos_indexers
    indexers = obj_idx.reindex_like(aligned_idx, **self.reindex_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/r/miniforge3/lib/python3.12/site-packages/xarray/core/indexes.py", line 834, in reindex_like
    raise ValueError(
ValueError: cannot reindex or align along dimension 'x' because the (pandas) index has duplicate values

Any idea what could I be doing wrong?

thanks, R

ashwinvis commented 3 months ago

Not sure. What kind of geometry are you loading?

ashwinvis commented 4 weeks ago

@ricardofrantz What happened, did you fix this?

Could you provide some example data if you need to have this fixed?