Skip to content

Conversation

@jl-wynen
Copy link
Member

This should make working with live data more efficient.

@jl-wynen jl-wynen requested a review from SimonHeybrock May 21, 2025 08:49
def subtract_background(
data: FocussedDataDspacing[SampleRun],
data: IofDspacing,
background: FocussedDataDspacing[BackgroundRun],
Copy link
Member

Choose a reason for hiding this comment

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

Shoudn't this be IofDspacing[BackgroundRun]? In other words, don' we need to parametrize IofDspacing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. But this required changing IofDspacing to a generic type. So this is a breaking change to the workflow which needs to request IofDspacing[SampleRun] now. I had coded SampleRun in some places to avoid errors from using the same type twice as an argument. E.g.,

def subtract_background(
    data: IofDspacing[RunType],
    background: IofDspacing[BackgroundRun],
) -> EmptyCanSubtractedIofDspacing[RunType]:
    ...

Would result in an instantiation that uses IofDspacing[BackgroundRun] for both arguments and Sciline doesn't like that.

Copy link
Member

Choose a reason for hiding this comment

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

Given that tests passed with this "bug" (before your latest changes): Is there a test missing that actually checked the result of the background subtraction?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have any regression tests for the final result. But they would have been broken in this case anyway.
I don't know how we can test that the background subtraction is applied correctly. Unfortunately, the data are dimensionless at this point. Do you have an idea?

Copy link
Member

Choose a reason for hiding this comment

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

Check that the workflow gives (A - B)/C, locally?

Copy link
Member Author

Choose a reason for hiding this comment

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

See new commit

@jl-wynen jl-wynen force-pushed the subtract-empty-can branch from 1864902 to 1ddd7c5 Compare May 21, 2025 13:37
@jl-wynen jl-wynen force-pushed the subtract-empty-can branch from 1ddd7c5 to 9874cc5 Compare May 21, 2025 13:58
Comment on lines 191 to 213
def test_pipeline_normalizes_and_subtracts_empty_can_as_expected(
workflow: sciline.Pipeline,
) -> None:
workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop
workflow = powder.with_pixel_mask_filenames(workflow, [])
results = workflow.compute(
[
EmptyCanSubtractedIofDspacing[SampleRun],
FocussedDataDspacing[SampleRun],
FocussedDataDspacing[VanadiumRun],
FocussedDataDspacing[BackgroundRun],
]
)
result = results[EmptyCanSubtractedIofDspacing[SampleRun]]

sample = results[FocussedDataDspacing[SampleRun]]
empty_can = results[FocussedDataDspacing[BackgroundRun]]
vanadium = results[FocussedDataDspacing[VanadiumRun]]

expected = powder.correction.normalize_by_vanadium_dspacing(
sample.bins.concatenate(-empty_can), vanadium, UncertaintyBroadcastMode.drop
)
sc.testing.assert_allclose(result, expected)
Copy link
Member

Choose a reason for hiding this comment

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

Ok, but I thought we wanted to avoid always running a full workflow in every "unit" test, due to growing run times... 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. This was easy enough to change.

@jl-wynen jl-wynen merged commit 977e559 into main May 22, 2025
4 checks passed
@jl-wynen jl-wynen deleted the subtract-empty-can branch May 22, 2025 07:03
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