data-exp-lab / yt_xarray

An interface for yt and xarray
MIT License
3 stars 2 forks source link

BUG: callable with time selection results in an index error #86

Closed chrishavlin closed 7 months ago

chrishavlin commented 7 months ago

When an isel is applied to reduce dimensions, the callable needs to adjust the domain dims appropriately when fetching the xarray data:

from cf_xarray.datasets import airds
import yt
import yt_xarray
ds_yt = airds.yt.load_grid('air', sel_dict={'time':0}, geometry='geographic', use_callable=True)
slc = yt.SlicePlot(ds_yt, 'altitude', 'air')
Traceback (most recent call last):
  File "/Users/chavlin/.pyenv/versions/yt_xarray/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-ab0c8dd2561b>", line 5, in <module>
    slc = yt.SlicePlot(ds_yt, 'altitude', 'air')
  File "/Users/chavlin/.pyenv/versions/3.10.11/envs/yt_xarray/lib/python3.10/site-packages/yt/visualization/plot_window.py", line 1833, in __init__
    slc.get_data(fields)
  File "/Users/chavlin/.pyenv/versions/3.10.11/envs/yt_xarray/lib/python3.10/site-packages/yt/data_objects/selection_objects/data_selection_objects.py", line 205, in get_data
    read_fluids, gen_fluids = self.index._read_fluid_fields(
  File "/Users/chavlin/.pyenv/versions/3.10.11/envs/yt_xarray/lib/python3.10/site-packages/yt/geometry/geometry_handler.py", line 241, in _read_fluid_fields
    fields_to_return = self.io._read_fluid_selection(
  File "/Users/chavlin/.pyenv/versions/3.10.11/envs/yt_xarray/lib/python3.10/site-packages/yt/frontends/stream/io.py", line 51, in _read_fluid_selection
    ind += g.select(selector, ds, rv[field], ind)  # caches
  File "/Users/chavlin/.pyenv/versions/3.10.11/envs/yt_xarray/lib/python3.10/site-packages/yt/data_objects/index_subobjects/grid_patch.py", line 414, in select
    dest[offset : offset + count, i] = source[tuple(sl)][np.squeeze(mask)]
IndexError: boolean index did not match indexed array along dimension 1; dimension is 0 but corresponding boolean dimension is 50
chrishavlin commented 7 months ago

note, might only be a problem for 2d data.