scipp / esspolarization

Polarization data reduction for the European Spallation Source
https://scipp.github.io/esspolarization/
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Run esssans workflow on polarized ISIS data #38

Open astellhorn opened 5 months ago

astellhorn commented 5 months ago

Executive summary

We need to read in the 4-period (4 spin channel) ISIS data into the esssans workflow to test at which point of the unpolarized workflow we can insert the polarization workflow. Subsequently, testfunctions from the esspolarization workflow shall be tested on the polarized data inserted into esssans

Context and background knowledge

Johannes has rewritten codes in the esssans workflow such that instead of one single SampleRun file now the 4-period polarization data can be inserted. For that, we do not call iofq[SampleRun], but e.g. iofq['++' / '+-' / '-+' / '--']. He has written it into the issue "fix-add-monitors"

Inputs

As example file for a "sample run" for the esssans workflow I take the polarized data ZOOM00022717.nxs. All other files are taken over from the example set for esssans. According to the ISIS ZOOM beamline scientist, the 'ZOOM00022717.nxs' data is to bea read out on monitor 5, as it is a 'SANS' mode data. ('TRANS' mode data instead would be read out on monitor 4). Also, according to Simon, pl[ReturnEvents] now has to be set to True to take the data in eventmode. Data is read in via mantid and locally saved files.

Methodology

Use esssans, but divide data into keys of ['++' / '+-' / '-+' / '--']

Outputs

Some functions, e.g. iofq['++' / '+-' / '-+' / '--'] work, but others, e.g. isis.plot_flat_detector_xy(results[MaskedData['++']]) not - which. syntax to use?

Which interfaces are required?

Jupyter notebook

Test cases

testdata ZOOM00022717.nxs from Diego Alba Venero, saved locally

Comments

Open questions:

jokasimr commented 5 months ago

I can't answer all questions here, but I can answer a few:

Why doesisis.plot_flat_detector_xy(results['++']) or isis.plot_flat_detector_xy(results[MaskedData['++']]) not work and what would be the correct syntax / how should I insert it?

The correct syntax in esssans to load period N from the mantid nexus file is:

# Note that this is currently only available on the main branch, not in the latest release
from ess.isissans.types import Period  # or ... import *
pipeline[Period] = N
pipeline.compute(MaskedData[SampleRun])

In the file I sent you there is a special definition that looks something like:

PolarizationSetting = NewType('PolarizationSetting', str)

def polarization_to_period(polarization: PolarizationSetting) -> Period:
    # Note the order might be incorrect
    return ['++', '+-', '-+', '--'].index(polarization)

pipeline.insert(polarization_to_period)

what it does is it adds a new provider (polarization_to_period) that associates the PolarizationSetting parameter value to a Period parameter value. If you have that definition in your notebook then you can write:

# pipeline[Period] = N
pipeline[PolarizationSetting] = '++'  # equivalent to Period=0
pipeline.compute(MaskedData[SampleRun])

Same question: Why does pl.compute(IofQ['++']) not work?

Similarly here, you need to do something like

pipeline[PolarizationSetting] = '+-'
# or you can do
# pipeline[Period] = 1
pipeline.compute(IofQ[SampleRun])
SimonHeybrock commented 5 months ago

IMPORTANT: to try functions from the previous esssans workflow (e.g. plot(iofq.items())), pl[ReturnEvents] has to be set back to False

When returning events you can still plot, but you need to hist() first, for example:

pl[ReturnEvents] = True
iofq = pl.compute(IofQ[SampeRun])
iofq.hist().plot()

Working with event data is quite different from regular data, make sure to read all of the relevant documentation, as this will be essential for doing the polarization correction: https://scipp.github.io/user-guide/binned-data.html.

astellhorn commented 5 months ago

Thank you! Now it works to plot (i) Qx-Qy dependend data like IofQ[SampleRun] via data.hist().plot() and (ii) spectrum-data (binned, but as function of spectrum, not 2D), like CalibratedMaskedData[SampleRun] via the plot_flat_detector_xq function.