Skip to content

feat: add monitor to estia workflow#543

Open
jokasimr wants to merge 11 commits into
mainfrom
add-monitor-to-estia
Open

feat: add monitor to estia workflow#543
jokasimr wants to merge 11 commits into
mainfrom
add-monitor-to-estia

Conversation

@jokasimr
Copy link
Copy Markdown
Contributor

Adds an optional monitor normalization step to the Estia workflow.

@jokasimr jokasimr requested a review from nvaytet April 27, 2026 13:43
return ess.reduce.normalization.normalize_by_monitor_histogram(
detector=detector,
monitor=monitor,
uncertainty_broadcast_mode=UncertaintyBroadcastMode.drop,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you hardcode this? Does the workflow not have this parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha maybe it does? I didn't think the workflow had the uncertainty broadcast mode parameter. I'll change it.



default_corrections = {correct_by_proton_current, correct_by_footprint}
default_corrections = {correct_by_proton_current, correct_by_footprint, 'monitor'}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you break with the established interface?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the monitor correction is not a function of the coordinates on the event data, like the footprint correction or the proton current correction.

It could be made into one, if we add the monitor intensity as a event coordinate on the data, like is done with the proton current. But then we can't use the helper from essreduce.

I agree it's a bit inconsistent, but I don't think we currently have another good solution for how to "specify what corrections should be applied" in the workflows. But I'm open to hear suggestions for alternatives.



default_corrections = {correct_by_proton_current, correct_by_footprint}
default_corrections = {correct_by_proton_current, correct_by_footprint, 'monitor'}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it makes sense to normalise by both monitor and proton charge? This would first remove the dependence on the flux and then add it back in.
I think we should require the user to specify a normalisation and either do none by default or only one of the two.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you are right.

# The monitor is missing from the Nexus files,
# so to be able to load Nexus files anyway
# this is set to None.
WavelengthMonitor[RunType]: None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you use the workflow with monitor norm? It looks to me like you need to either implement your own EstiaWorkflow to omit this parameter or manually add all monitor providers to the workflow.

In powder diffraction, we have an argument in the workflow constructor function that sets the normalisation mode: https://scipp.github.io/ess/diffraction/user-guide/dream/dream-advanced-powder-reduction.html#Normalize-by-integrated-monitor
That way, you get the appropriate graph without having to build it yourself. Plus, you don't end up with spurious dependencies on a monitor or proton charge that doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you would create the workflow using EstiaWorkflow and then .insert() the provider for WavelengthMonitor[RunType] . But I see now that you are right, setting the WavelengthMonitor parameter on the workflow removes all dependencies upstream from WavelengthMonitor from the workflow :/ so even if you add a provider for WavelengthMonitor you'd still be missing all the providers it depends on...

I'll try to do something more like what was done in the Dream workflow. I was trying to do something simpler here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you create workflows now with the latest changes?

Copy link
Copy Markdown
Contributor Author

@jokasimr jokasimr May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wf = EstiaWorkflow()

# To add monitor correction
wf[CorrectionsToApply] = wf.compute(CorrectionsToApply) | {'monitor'}

# To remove monitor correction
wf[CorrectionsToApply] = wf.compute(CorrectionsToApply) - {'monitor'}

But it's probably better to explicitly set the corrections that you want to use, instead of modifying the default setting.

@jokasimr jokasimr force-pushed the add-monitor-to-estia branch from 8051f0c to 8ddb6fe Compare April 28, 2026 14:33
@jokasimr jokasimr requested a review from jl-wynen April 30, 2026 07:36
@nvaytet nvaytet added the essreflectometry Issues for essreflectometry. label Apr 30, 2026
@jokasimr
Copy link
Copy Markdown
Contributor Author

jokasimr commented May 4, 2026

@jl-wynen was there anything else you wanted changed here?



default_corrections = {correct_by_proton_current, correct_by_footprint}
default_corrections = {correct_by_footprint, 'proton_current'}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default_corrections = {correct_by_footprint, 'proton_current'}
default_corrections = {correct_by_footprint}

because the default is set in the workflows without proton current correction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Estia workflow should have proton current correction. Right now it's unclear how to load that information from the nexus files, but I don't think we should adjust the default parameters because of that.

bdlim: BeamDivergenceLimits,
wbins: WavelengthBins,
proton_current: ProtonCurrent[RunType],
monitor: WavelengthMonitor[RunType],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a problem. You now have to always load and process both the monitor and proton charge even if you don't need them. Plus, this means that the graph visualization is not enough to understand the data flow.
So I still think normalisations should be selected on the graph level, not as a parameter.

from .types import WavelengthMonitor


def normalize_by_monitor_histogram(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this copy of the estia function? Can you move this to reflectometry.corrections?

Copy link
Copy Markdown
Contributor Author

@jokasimr jokasimr May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freia and Estia don't have the same WavelengthMonitor types. Freia has several monitors, while Estia only has one. I though it was less hassle to just duplicate it for now. This will definitely change when we get real requirements about how Freia wants to do monitor normalization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the monitor should be parametrized over the MonitorType. So can you replace the custom type with the one define din essreduce?
If you think it's too verbose to always specify the type when using an estia workflow, you can provide an alias for the type there. But we should avoid duplicating code just because typing [Monitor] is too much.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's what is already done right? I mean, there's a type alias for the essreduce monitor in estia/types.py.

The point is: I have no idea what the monitor normalization for Freia will look like, what monitor it will use, etc. It doesn't make any sense to do anything there right now. It's just a placeholder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

essreflectometry Issues for essreflectometry.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants