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

Load NXdetector pixel_mask into DataArray.masks #157

Closed SimonHeybrock closed 9 months ago

SimonHeybrock commented 11 months ago

See https://manual.nexusformat.org/classes/base_classes/NXdetector.html#nxdetector-pixel-mask-field. We should turn this into masks of a scipp.DataArray (the the detector is loaded as a DataArray).

Scipp only really works with boolean masks. Therefore, we should inspect the bitmask, and split it into individual masks. Only bits that are actually in use should result in creation of a corresponding mask.

jokasimr commented 10 months ago

I've started looking at this and I have some questions:

  1. Do you have an example of a Nexus file that has the pixel-mask field assigned? I looked at one of the test cases from the scippnexus documentation but did not find the field:
    from scippnexus import data
    filename = data.get_path('PG3_4844_event.nxs')
    import scippnexus as snx
    f = snx.File(filename)
    detector = f['entry/instrument/bank102']
    list(detector.keys())
    ['azimuthal_angle',
    'data_x_y',
    'distance',
    'event_id',
    'event_index',
    'event_time_offset',
    'event_time_zero',
    'local_name',
    'origin',
    'pixel_id',
    'polar_angle',
    'total_counts',
    'x_pixel_offset',
    'y_pixel_offset']
  2. How do we determine which bits are in use? If it is set to 0 in the entire array?