Skip to content

Indexing issues with lazy loading #46

@jurjendejong

Description

@jurjendejong

Hi all,

First thanks for this great package! Started using it as an alternative Python backend recently, and impressed by how much it simplifies my work.

Recently I came across the issue that results might differ when lazy loading.
The .diff(dim='plan') does not produce correct results.
The problem does not appear with other axis (only 'plan'), and as soon as you trigger anything to actually load the data before applying the .diff() it resolves the issue.

Similar issues occur also with .shift(plan=1).

(sorry about the formating)

`
slf_open = xr.open_dataset(selafin_3D_file, engine="selafin")
slf_load = xr.load_dataset(selafin_3D_file, engine="selafin")

#%%

Get the delta_z between all the Z layers gives different results between .open_dataset() and .load_dataset()

z_levels_open = slf_open.Z.isel(time=0).drop_vars('time')
z_levels_load = slf_load.Z.isel(time=0).drop_vars('time')

dz_open = z_levels_open.diff(dim='plan')
dz_load = z_levels_load.diff(dim='plan')

xr.testing.assert_equal(dz_open, dz_load)

--> AssertionError

#%%

But if I query the Z-data itself all seems

xr.testing.assert_equal(z_levels_open, z_levels_load)

--> No AssertionError

#%%

If I test my original problem again, it has now disappeared

dz_open = z_levels_open.diff(dim='plan')
dz_load = z_levels_load.diff(dim='plan')

xr.testing.assert_equal(dz_open, dz_load)

--> No Assertion Error

#%%

Also if I request a .load() the issue has disappeared.

z_levels_open = slf_open.Z.isel(time=0).drop_vars('time').load()
z_levels_load = slf_load.Z.isel(time=0).drop_vars('time')

dz_open = z_levels_open.diff(dim='plan')
dz_load = z_levels_load.diff(dim='plan')

xr.testing.assert_equal(dz_open, dz_load)

--> No Assertion error`

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions