DREAM instrument view#

This notebook is a simple example of how to use the instrument view for the DREAM instrument.

  • The DREAM-specific instrument view is capable of slicing the data with a slider widget along a dimension (e.g. tof) by using the dim argument.

  • There are also checkboxes to hide/show the different elements that make up the DREAM detectors.

We begin with relevant imports. We will be using tutorial data downloaded with pooch. If you get an error about a missing module pooch, you can install it with !pip install pooch:

[1]:
import scipp as sc
from ess import dream
import ess.dream.data  # noqa: F401

Load the data#

We load a dataset from a Geant4 simulation (stored as a .csv file). In each detector bank, the data is organised by wire, strip, module, segment, and counter. The high resolution detector also has an additional sector dimension.

[2]:
dg = dream.io.load_geant4_csv(dream.data.get_path("data_dream0_new_hkl_Si_pwd.csv.zip"))
dg = dg["instrument"]  # Extract the instrument data

# Extract the events from nested data groups
dg = sc.DataGroup({key: detector["events"] for key, detector in dg.items()})
dg
Downloading file 'data_dream0_new_hkl_Si_pwd.csv.zip' from 'https://public.esss.dk/groups/scipp/ess/dream/1/data_dream0_new_hkl_Si_pwd.csv.zip' to '/home/runner/.cache/ess/dream/1'.
[2]:
  • mantle
    scipp
    DataArray
    (module: 7,
     segment: 6,
     counter: 2,
     wire: 32,
     strip: 256)
    DataArrayView
    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)
    DataArrayView
    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)
    DataArrayView
    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)
    DataArrayView
    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)
    DataArrayView
    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:

[4]:
tof_edges = sc.linspace("tof", 1.0e7, 1.0e8, 51, unit="ns", dtype=int)
data = 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:

[5]:
full_view = dream.instrument_view(data, dim="tof")
full_view
[5]:

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:

[7]:
mantle_view = dream.instrument_view(dg["mantle"].hist(tof=50), dim="tof")
mantle_view
[7]:

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.

Below, we display the first module in the backward end-cap detector:

[9]:
dream.instrument_view(dg["endcap_backward"]["module", 0].hist(tof=1))
[9]: