scipp / scippnexus

h5py-like utility for NeXus files with seamless scipp integration
https://scipp.github.io/scippnexus/
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

Positional slicing returns different result in scippnexus than in scipp #193

Closed jokasimr closed 5 months ago

jokasimr commented 5 months ago

Example:

import h5py
import scipp as sc
import scippnexus as snx
with h5py.File('dummy.nxs', mode='w', driver="core", backing_store=False) as h5root:
    da = sc.DataArray(
        sc.array(dims=['xx', 'yy'], unit='m', values=[[1, 2], [4, 5]]),
        coords=dict(
            xx = sc.array(dims=['xx'], unit='m', values=[1.0, 2.0]),
            yy = sc.array(dims=['yy'], unit='m', values=[0.1, 0.0]),
        ),
    )
    data = snx.create_class(h5root, 'data1', snx.NXdata)                                                                                                                                                                                   
    snx.create_field(data, 'signal', da.data)
    snx.create_field(data, 'xx', da.coords['xx'])
    data.attrs['axes'] = da.dims
    data.attrs['signal'] = 'signal'                                                                                            
    data = snx.Group(data, definitions=snx.base_definitions())

    print(da['xx', 0:2])                                                                                                       
    print(data['xx', 0:2])

Output:

<scipp.DataArray>
Dimensions: Sizes[xx:2, yy:2, ]
Coordinates:
* xx                        float64              [m]  (xx)  [1, 2]
* yy                        float64              [m]  (yy)  [0.1, 0]
Data:
                              int64              [m]  (xx, yy)  [1, 2, 4, 5]

<scipp.DataArray>
Dimensions: Sizes[xx:2, yy:2, ]
Coordinates:
* xx                        float64              [m]  (xx)  [1, 2]
Data:
                              int64              [m]  (xx, yy)  [1, 2, 4, 5]

Expected result: I expected them to be the same. Actual result: Positional indexing on the scipp DataArray kept the yy coordinate but positional indexing on the NXdata object did not keep the yy coordinate.

Not sure if this is the correct behavior or not, but I think it would be more intuitive if they behaved the same.

jokasimr commented 5 months ago

Realized the mistake...