DREAM powder data reduction#
Audience: Instrument users, beginners
Prerequisites: Basic knowledge of Scipp
This notebook demonstrates the basic powder data reduction workflow for DREAM in high-flux mode. The workflow
converts the data to \(d\)-spacing,
focuses into a single bin per \(d\)-spacing (i.e., removes dependency on voxel position),
normalizes by a monitor histogram,
normalizes by a vanadium measurement,
and saves the results to a time-of-flight CIF file for use by EasyDiffraction.
Only the mantle detector of DREAM is used in this workflow for simplicity. See DREAM advanced powder data reduction for more options.
This notebook uses data from a McStas + GEANT4 simulation but can be adapted to other data. The data is available through the ESSdiffraction package but accessing it requires the pooch
package. 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, powder
import ess.dream.data # noqa: F401
from ess.powder.types import *
Create and configure the workflow#
We begin by creating the Dream (Geant4) workflow object which is a skeleton for reducing Dream data, with pre-configured steps.
[2]:
workflow = dream.DreamGeant4Workflow(
run_norm=powder.RunNormalization.monitor_histogram,
)
We then need to set the missing parameters which are specific to each experiment (the keys are types defined in ess.powder.types).
[3]:
workflow[Filename[SampleRun]] = dream.data.simulated_diamond_sample()
workflow[Filename[VanadiumRun]] = dream.data.simulated_vanadium_sample()
workflow[Filename[EmptyCanRun]] = dream.data.simulated_empty_can()
workflow[CalibrationFilename] = None
workflow[MonitorFilename[SampleRun]] = dream.data.simulated_monitor_diamond_sample()
workflow[MonitorFilename[VanadiumRun]] = dream.data.simulated_monitor_vanadium_sample()
workflow[MonitorFilename[EmptyCanRun]] = dream.data.simulated_monitor_empty_can()
workflow[CaveMonitorPosition] = sc.vector([0.0, 0.0, -4220.0], unit="mm")
workflow[dream.InstrumentConfiguration] = dream.InstrumentConfiguration.high_flux
# Select a detector bank:
workflow[NeXusDetectorName] = "mantle"
# We drop uncertainties where they would otherwise lead to correlations:
workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop
# Edges for binning in d-spacing:
workflow[DspacingBins] = sc.linspace("dspacing", 0.3, 2.3434, 201, unit="angstrom")
# Do not mask any pixels / voxels:
workflow = powder.with_pixel_mask_filenames(workflow, [])
Use the reduction workflow#
We then call workflow.compute(target) to compute the result.
EmptyCanSubtractedIofDspacing
is the normalized intensity as a function of \(d\)-spacing.ReducedEmptyCanSubtractedTofCIF
encode the same data but converted back to time-of-flight and ready to be written to a CIF file.
If we didn’t want to subtract an empty can measurement from the sample measurement, we would instead request IofDspacing[SampleRun]
and ReducedTofCIF
.
[4]:
results = workflow.compute([
EmptyCanSubtractedIofDspacing[SampleRun],
ReducedEmptyCanSubtractedTofCIF
])
intensity = results[EmptyCanSubtractedIofDspacing[SampleRun]]
cif_data = results[ReducedEmptyCanSubtractedTofCIF]
The intensity is still binned data, so we need to histogram it before we can plot it:
[5]:
histogram = intensity.hist()
fig = histogram.plot(title=intensity.coords['detector'].value.capitalize())
fig.ax.set_ylabel(f"I(d) [{histogram.unit}]")
fig
[5]:
We can now save the result to disk:
[6]:
cif_data.comment = """This file was generated with the basic DREAM data reduction user guide
in the documentation of ESSdiffraction.
See https://scipp.github.io/essdiffraction/
"""
cif_data.save("reduced.cif")
Visualize the workflow#
We can visualize the workflow as a graph. This can help us understand how the data was reduced.
[7]:
workflow.visualize(ReducedEmptyCanSubtractedTofCIF, graph_attr={"rankdir": "LR"})
[7]:
The workflow is a Sciline pipeline. See the documentation of Sciline for more information and how to modify and extend the workflow.
Some comments about the workflow structure:
Everything up to
DetectorData
andMonitorData
can be summarized as loading raw data.The workflow contains a
GravityVector
. This is only used for defining a coordinate system, there is no gravity correction.Everything after
IofDspacing
deals with writing the output to CIF. If you want to customize the file, you may insert different parameters for the inputs toReducedTofCIF
.
Next, consider reading DREAM advanced powder data reduction guide which demonstrates some builtin options for customizing the workflow and how to compute alternative results.