Instrument view#

A simple version of the Mantid instrument view is available in scippneutron.

It currently does not support detector ‘picking’ and manual drawing of masks, nor does it render the actual shape of the detectors (currently it represents them as 2-D squares), but basic functionalities such as spatial slicing, as well as navigation through the time-of-flight dimension via a slider, are provided.

[1]:
import scipp as sc
import scippneutron as scn
from scippneutron import data

Load the data#

We load an example dataset for the Dream (ESS) instrument. In each detector bank, the data is organised by wire, strip, module, segment, and counter.

[2]:
dg = data.example_dream_data()
dg
[2]:
  • mantle
    scipp
    DataArray
    (module: 7,
     segment: 6,
     counter: 2,
     wire: 32,
     strip: 256)
    float64
    counts
    binned data [len=13, len=8, ..., len=0, len=0]
  • high_resolution
    scipp
    DataArray
    (sector: 4,
     module: 9,
     segment: 8,
     counter: 2,
     wire: 16,
     strip: 32)
    float64
    counts
    binned data [len=0, len=0, ..., len=0, len=0]
  • sans
    scipp
    DataArray
    (sector: 4,
     module: 9,
     segment: 8,
     counter: 2,
     wire: 16,
     strip: 32)
    float64
    counts
    binned data [len=0, len=0, ..., len=0, len=0]
  • endcap_backward
    scipp
    DataArray
    (sumo: 4,
     module: 13,
     segment: 10,
     counter: 2,
     wire: 16,
     strip: 16)
    float64
    counts
    binned data [len=13, len=10, ..., len=4, len=3]
  • endcap_forward
    scipp
    DataArray
    (sumo: 4,
     module: 13,
     segment: 10,
     counter: 2,
     wire: 16,
     strip: 16)
    float64
    counts
    binned data [len=0, len=0, ..., len=0, len=1]

Full instrument view#

We first histogram the data along the time-of-flight (tof) dimension, making sure the same bins are used for all elements:

[3]:
tof_edges = sc.linspace("tof", 1.0e7, 1.0e8, 51, unit="ns", dtype=int)
histogram = dg.hist(tof=tof_edges)

We now use the instrument_view function to show the 3D view of the instrument pixels, specifying that we wish to have a slider along the tof dimension:

[4]:
full_view = scn.instrument_view(histogram, dim="tof")
full_view
[4]:

Note that it is possible to use any dimension for the slider instead of tof, such as wavelength (if present in the data).

Displaying individual detector elements#

It is also possible to view a single detector element, selecting e.g. mantle from the original data:

[5]:
mantle_view = scn.instrument_view(histogram["mantle"], dim="tof")
mantle_view
[5]:

The instrument view is designed to be flexible in terms of what it accepts as input. This means that you can easily inspect, for example, a single module by using the usual slicing notation for data arrays.

The dim argument can also be omitted; in this case a reduction operation (sum by default) along all non-position dimensions is applied to the data before displaying.

Below, we display the first module in the backward end-cap detector, without a tof slider:

[6]:
scn.instrument_view(dg["endcap_backward"]["module", 0].hist())
[6]:

Spatial slicing#

A tool for selecting parts of the displayed detectors is available by clicking the ‘layers’ (last) button in the toolbar.

Adding and moving selection regions can help inspect data inside volumetric detectors:

[7]:
mantle_view = scn.instrument_view(histogram["mantle"], dim="tof")
mantle_view
[7]: