-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from scipp/zoom
Zoom data reduction
- Loading branch information
Showing
11 changed files
with
692 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
direct_beam | ||
i_of_q | ||
io | ||
isis | ||
logging | ||
loki | ||
sans2d | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ maxdepth: 2 | |
sans2d | ||
loki-direct-beam | ||
zoom | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ba4d302c", | ||
"metadata": {}, | ||
"source": [ | ||
"# Zoom data reduction\n", | ||
"\n", | ||
"## Introduction\n", | ||
"\n", | ||
"This notebook is an example of how ESSsans can be used to reduce data from [Zoom at ISIS](https://www.isis.stfc.ac.uk/Pages/Zoom.aspx).\n", | ||
"The following description is kept relatively brief, for more context see the rest of the documentation.\n", | ||
"In particular the [Sans2d](./sans2d.ipynb) notebook may be useful." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "53e2278d", | ||
"metadata": {}, | ||
"source": [ | ||
"There are a few things that are not yet handled:\n", | ||
"\n", | ||
"- TOF or wavelength masks\n", | ||
"- Position corrections from user file" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "09234b87", | ||
"metadata": {}, | ||
"source": [ | ||
"## Setup\n", | ||
"\n", | ||
"### Imports and configuration" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "319162e9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import scipp as sc\n", | ||
"import sciline\n", | ||
"import esssans as sans\n", | ||
"import esssans.isis\n", | ||
"from esssans.types import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "64783c51", | ||
"metadata": {}, | ||
"source": [ | ||
"### Setup input files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9e7cfc82", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"params = {\n", | ||
" sans.types.DirectBeamFilename: 'Direct_Zoom_4m_8mm_100522.txt',\n", | ||
" sans.isis.CalibrationFilename: '192tubeCalibration_11-02-2019_r5_10lines.nxs',\n", | ||
" sans.isis.Filename[sans.types.SampleRun]: 'ZOOM00034786.nxs',\n", | ||
" sans.isis.Filename[sans.types.EmptyBeamRun]: 'ZOOM00034787.nxs',\n", | ||
"}\n", | ||
"masks = [\n", | ||
" 'andru_test.xml',\n", | ||
" 'left_beg_18_2.xml',\n", | ||
" 'right_beg_18_2.xml',\n", | ||
" 'small_bs_232.xml',\n", | ||
" 'small_BS_31032023.xml',\n", | ||
" 'tube_1120_bottom.xml',\n", | ||
" 'tubes_beg_18_2.xml',\n", | ||
"]\n", | ||
"masks = sciline.ParamTable(str, {sans.isis.PixelMaskFilename: masks}, index=masks)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8a8a4e01", | ||
"metadata": {}, | ||
"source": [ | ||
"### Setup reduction parameters" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "50f11eb2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"params[NeXusMonitorName[Incident]] = 'monitor3'\n", | ||
"params[NeXusMonitorName[Transmission]] = 'monitor5'\n", | ||
"\n", | ||
"band = sc.linspace('wavelength', 1.75, 16.5, num=2, unit='angstrom')\n", | ||
"params[WavelengthBands] = band\n", | ||
"params[WavelengthBins] = sc.geomspace(\n", | ||
" 'wavelength', start=band[0], stop=band[-1], num=141\n", | ||
")\n", | ||
"\n", | ||
"params[QBins] = sc.geomspace(dim='Q', start=0.004, stop=0.8, num=141, unit='1/angstrom')\n", | ||
"params[NonBackgroundWavelengthRange] = sc.array(\n", | ||
" dims=['wavelength'], values=[0.7, 17.1], unit='angstrom'\n", | ||
")\n", | ||
"params[CorrectForGravity] = True\n", | ||
"params[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.upper_bound" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0b47024f", | ||
"metadata": {}, | ||
"source": [ | ||
"### Setup reduction pipeline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fdcaec37", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"providers = sans.providers + sans.isis.providers\n", | ||
"providers = providers + (\n", | ||
" sans.isis.transmission_from_background_run,\n", | ||
" sans.isis.transmission_from_sample_run,\n", | ||
")\n", | ||
"pipeline = sciline.Pipeline(providers, params=params)\n", | ||
"pipeline.set_param_table(masks)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "951aec10", | ||
"metadata": {}, | ||
"source": [ | ||
"If Mantid is available, we can use it to load data files.\n", | ||
"**You must configure the** `DataFolder` **below to point to the directory containing the data files.**\n", | ||
"Otherwise, we fall back to load intermediate data files that have been prepared for the concrete example in this notebook.\n", | ||
"If you want to use the workflow with different files you must have Mantid installed:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "66237b3e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"try:\n", | ||
" from mantid import ConfigService\n", | ||
" import esssans.isis.mantidio\n", | ||
"\n", | ||
" cfg = ConfigService.Instance()\n", | ||
" cfg.setLogLevel(3) # Silence verbose load via Mantid\n", | ||
"\n", | ||
" pipeline[sans.isis.DataFolder] = 'zoom_data'\n", | ||
" for provider in sans.isis.mantidio.providers:\n", | ||
" pipeline.insert(provider)\n", | ||
"except ImportError:\n", | ||
" import esssans.isis.data\n", | ||
"\n", | ||
" for provider in sans.isis.data.providers:\n", | ||
" pipeline.insert(provider)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "703ffc1e", | ||
"metadata": {}, | ||
"source": [ | ||
"## Reduction\n", | ||
"\n", | ||
"### The reduction workflow" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cae69232", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"iofq = pipeline.get(IofQ[SampleRun])\n", | ||
"iofq.visualize(graph_attr={'rankdir': 'LR'}, compact=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "77687728", | ||
"metadata": {}, | ||
"source": [ | ||
"### Running the workflow" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "558327ff", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"da = iofq.compute()\n", | ||
"da.plot(norm='log', scale={'Q': 'log'})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5a7526fc", | ||
"metadata": {}, | ||
"source": [ | ||
"### Inspecting intermediate results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bb922379", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"monitors = (\n", | ||
" WavelengthMonitor[SampleRun, Incident],\n", | ||
" WavelengthMonitor[SampleRun, Transmission],\n", | ||
")\n", | ||
"parts = (CleanSummedQ[SampleRun, Numerator], CleanSummedQ[SampleRun, Denominator])\n", | ||
"iofqs = (IofQ[SampleRun],)\n", | ||
"keys = monitors + (MaskedData[SampleRun],) + parts + iofqs\n", | ||
"\n", | ||
"results = pipeline.compute(keys)\n", | ||
"\n", | ||
"display(sc.plot({str(key): results[key] for key in monitors}, norm='log'))\n", | ||
"\n", | ||
"display(\n", | ||
" sans.isis.plot_flat_detector_xy(\n", | ||
" results[MaskedData[SampleRun]], norm='log', figsize=(6, 10)\n", | ||
" )\n", | ||
")\n", | ||
"\n", | ||
"parts = {str(key): results[key] for key in parts}\n", | ||
"parts = {key: val if val.bins is None else val.hist() for key, val in parts.items()}\n", | ||
"display(sc.plot(parts, norm='log', scale={'Q': 'log'}))\n", | ||
"\n", | ||
"iofqs = {str(key): results[key] for key in iofqs}\n", | ||
"iofqs = {key: val if val.bins is None else val.hist() for key, val in iofqs.items()}\n", | ||
"display(sc.plot(iofqs, norm='log', scale={'Q': 'log'}))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
|
||
|
||
from ..sans2d.general import ( | ||
get_detector_data, | ||
get_monitor, | ||
lab_frame_transform, | ||
sans2d_tube_detector_pixel_shape, | ||
) | ||
from . import io, masking | ||
from .common import transmission_from_background_run, transmission_from_sample_run | ||
from .io import CalibrationFilename, DataFolder, Filename, PixelMaskFilename | ||
from .masking import PixelMask | ||
from .visualization import plot_flat_detector_xy | ||
|
||
providers = ( | ||
( | ||
get_detector_data, | ||
get_monitor, | ||
lab_frame_transform, | ||
sans2d_tube_detector_pixel_shape, | ||
) | ||
+ io.providers | ||
+ masking.providers | ||
) | ||
|
||
del get_detector_data | ||
del get_monitor | ||
del lab_frame_transform | ||
del sans2d_tube_detector_pixel_shape | ||
|
||
__all__ = [ | ||
'CalibrationFilename', | ||
'DataFolder', | ||
'Filename', | ||
'io', | ||
'masking', | ||
'PixelMask', | ||
'PixelMaskFilename', | ||
'providers', | ||
'transmission_from_background_run', | ||
'transmission_from_sample_run', | ||
'plot_flat_detector_xy', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
""" | ||
""" | ||
|
||
from ..types import BackgroundRun, LoadedFileContents, SampleRun, TransmissionRun | ||
|
||
|
||
def transmission_from_sample_run( | ||
data: LoadedFileContents[SampleRun], | ||
) -> LoadedFileContents[TransmissionRun[SampleRun]]: | ||
""" | ||
Use transmission from a sample run, instead of dedicated run. | ||
""" | ||
return LoadedFileContents[TransmissionRun[SampleRun]](data) | ||
|
||
|
||
def transmission_from_background_run( | ||
data: LoadedFileContents[BackgroundRun], | ||
) -> LoadedFileContents[TransmissionRun[BackgroundRun]]: | ||
""" | ||
Use transmission from a background run, instead of dedicated run. | ||
""" | ||
return LoadedFileContents[TransmissionRun[BackgroundRun]](data) |
Oops, something went wrong.