Skip to content

Conversation

@jokasimr
Copy link
Contributor

Adding the correction to the workflow graph was more messy than I expected.

Workflow/graph related issues

The guidelines say that Lorentz correction should be applied to CorrectedDetector.

But at that step in the workflow the events don't have dspacing (and Lorentz correction is a function of dspacing).
I don't know if this is a bug in EssDiffraction or if it is a bug in the guidelines.
I worked around the issue by removing CorrectedDetector, going directly from WavelengthDetector to DspacingDetector.

However, this makes the provider add_coords_masks_and_apply_corrections do a lot of things at once.
And it takes a lot of arguments that are not really related, so it's not very useful for understanding what the provider does.

The other option would be to add more domain types where each step is done separately. But that would add a lot of unnecessary domain types to the graph.

There's a tension between making the graphs show relevant intermediate results, and making the graphs explain what is being done to the data.

Issues in apply_lorentz_correction

The existing apply_lorentz_correction function could not be applied to data with variances.
For now I just replaced it with something that works with variances.

@jokasimr jokasimr requested a review from jl-wynen November 19, 2025 10:17
@jl-wynen
Copy link
Member

I there a reason why we can't compute a dspacing coord earlier and assign it to WavelengthDetector? Then we could merge WavelengthDetector and DspacingDetector and apply the corrections afterwards. (Note that we are not binning in any of these steps anyway.)

@jokasimr
Copy link
Contributor Author

jokasimr commented Nov 19, 2025

I there a reason why we can't compute a dspacing coord earlier and assign it to WavelengthDetector? Then we could merge WavelengthDetector and DspacingDetector and apply the corrections afterwards. (Note that we are not binning in any of these steps anyway.)

Yeah that's also a possibility. It has the same drawbacks as the other version, and it makes the name WavelengthDetector a bit strange. But I agree it's a nicer split overall!

Another option is to also remove WavelengthDetector and do everything in one step:
Compute the coords, add the masks, and do the lorentz correction.

# See scipp/essreduce#249
out.bins.coords.pop("event_time_offset", None)
return DspacingDetector[RunType](out)
return CorrectedDetector[RunType](out)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have to keep tof coord because it is used by masking in later step.

I don't really see any reason to drop event_time_offset here except for performance.
Maybe that's reason enough.
On the other hand, that makes users unable to investigate correlations between event_time_offset and other coordinate if they want, which might be annoying.

@jokasimr jokasimr marked this pull request as ready for review November 19, 2025 14:48
graph: ElasticCoordTransformGraph[RunType],
calibration: CalibrationData,
) -> DspacingDetector[RunType]:
) -> CorrectedDetector[RunType]:
Copy link
Member

Choose a reason for hiding this comment

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

The types don't make sense. If the function was used as a provider like this, it would receive data that already contains d-spacing. And it the return type would clash with or bypass corrections. So I think you should just use sc.DataArray here.

@jokasimr jokasimr requested a review from jl-wynen November 20, 2025 13:49
graph: ElasticCoordTransformGraph[RunType],
calibration: CalibrationData,
) -> DspacingDetector[RunType]:
) -> sc.DataArray | sc.Dataset:
Copy link
Member

Choose a reason for hiding this comment

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

How can this be a dataset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. The type checker told me it could be.

Copy link
Member

Choose a reason for hiding this comment

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

It's definitely wrong. The input is a data array and all definitions of out are also data arrays.

@jokasimr jokasimr merged commit 42502ee into main Nov 26, 2025
4 checks passed
@jokasimr jokasimr deleted the apply-lorentz branch November 26, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants