-
Notifications
You must be signed in to change notification settings - Fork 2
Subtract sample run by empty can #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4ad86c0
e144fad
21b8cb5
31d7336
a6812db
f066620
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,9 @@ | |
| from ._util import event_or_outer_coord | ||
| from .types import ( | ||
| AccumulatedProtonCharge, | ||
| BackgroundRun, | ||
| BackgroundSubtractedData, | ||
| BackgroundSubtractedDataTwoTheta, | ||
| CaveMonitor, | ||
| DataWithScatteringCoordinates, | ||
| FocussedDataDspacing, | ||
|
|
@@ -154,13 +157,49 @@ def _normalize_by_vanadium( | |
| return normed | ||
|
|
||
|
|
||
| def normalize_by_vanadium_dspacing_removed_empty_can( | ||
| data: BackgroundSubtractedData[SampleRun], | ||
| vanadium: FocussedDataDspacing[VanadiumRun], | ||
| uncertainty_broadcast_mode: UncertaintyBroadcastMode, | ||
| ) -> IofDspacing: | ||
| """ | ||
| Normalize sample data by a vanadium measurement and return intensity vs. d-spacing. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| data: | ||
| Sample data where events from an empty can / empty instrument measurement | ||
| have been subtracted. | ||
| vanadium: | ||
| Vanadium data. | ||
| uncertainty_broadcast_mode: | ||
| Choose how uncertainties of vanadium are broadcast to the sample data. | ||
| Defaults to ``UncertaintyBroadcastMode.fail``. | ||
|
|
||
| Returns | ||
| ------- | ||
| : | ||
| ``data / vanadium``. | ||
| May contain a mask "zero_vanadium" which is ``True`` | ||
| for bins where vanadium is zero. | ||
|
|
||
| See also | ||
| -------- | ||
| normalize_by_vanadium_dspacing: | ||
| The same function but using data where no empty can has been subtracted. | ||
| """ | ||
| return IofDspacing( | ||
| _normalize_by_vanadium(data, vanadium, uncertainty_broadcast_mode) | ||
| ) | ||
|
|
||
|
|
||
| def normalize_by_vanadium_dspacing( | ||
| data: FocussedDataDspacing[SampleRun], | ||
| vanadium: FocussedDataDspacing[VanadiumRun], | ||
| uncertainty_broadcast_mode: UncertaintyBroadcastMode, | ||
| ) -> IofDspacing: | ||
| """ | ||
| Normalize sample data by a vanadium measurement and return intensity vs d-spacing. | ||
| Normalize sample data by a vanadium measurement and return intensity vs. d-spacing. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
@@ -178,19 +217,62 @@ def normalize_by_vanadium_dspacing( | |
| ``data / vanadium``. | ||
| May contain a mask "zero_vanadium" which is ``True`` | ||
| for bins where vanadium is zero. | ||
|
|
||
| See also | ||
| -------- | ||
| normalize_by_vanadium_dspacing_removed_empty_can: | ||
| The same function but using data where events from an empty can / | ||
| empty instrument measurement have been subtracted. | ||
| """ | ||
| return IofDspacing( | ||
| _normalize_by_vanadium(data, vanadium, uncertainty_broadcast_mode) | ||
| ) | ||
|
|
||
|
|
||
| def normalize_by_vanadium_dspacing_and_two_theta_removed_empty_can( | ||
| data: BackgroundSubtractedDataTwoTheta[SampleRun], | ||
| vanadium: FocussedDataDspacingTwoTheta[VanadiumRun], | ||
| uncertainty_broadcast_mode: UncertaintyBroadcastMode, | ||
| ) -> IofDspacingTwoTheta: | ||
| """ | ||
| Normalize sample data by a vanadium measurement and return intensity vs. | ||
| (d-spacing, 2theta). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| data: | ||
| Sample data where events from an empty can / empty instrument measurement | ||
| have been subtracted. | ||
| vanadium: | ||
| Vanadium data. | ||
| uncertainty_broadcast_mode: | ||
| Choose how uncertainties of vanadium are broadcast to the sample data. | ||
| Defaults to ``UncertaintyBroadcastMode.fail``. | ||
|
|
||
| Returns | ||
| ------- | ||
| : | ||
| ``data / vanadium``. | ||
| May contain a mask "zero_vanadium" which is ``True`` | ||
| for bins where vanadium is zero. | ||
|
|
||
| See also | ||
| -------- | ||
| normalize_by_vanadium_dspacing_and_two_theta: | ||
| The same function but using data where no empty can has been subtracted. | ||
| """ | ||
| return IofDspacingTwoTheta( | ||
| _normalize_by_vanadium(data, vanadium, uncertainty_broadcast_mode) | ||
| ) | ||
|
|
||
|
|
||
| def normalize_by_vanadium_dspacing_and_two_theta( | ||
| data: FocussedDataDspacingTwoTheta[SampleRun], | ||
| vanadium: FocussedDataDspacingTwoTheta[VanadiumRun], | ||
| uncertainty_broadcast_mode: UncertaintyBroadcastMode, | ||
| ) -> IofDspacingTwoTheta: | ||
| """ | ||
| Normalize sample data by a vanadium measurement and return intensity vs | ||
| Normalize sample data by a vanadium measurement and return intensity vs. | ||
| (d-spacing, 2theta). | ||
|
|
||
| Parameters | ||
|
|
@@ -209,6 +291,12 @@ def normalize_by_vanadium_dspacing_and_two_theta( | |
| ``data / vanadium``. | ||
| May contain a mask "zero_vanadium" which is ``True`` | ||
| for bins where vanadium is zero. | ||
|
|
||
| See also | ||
| -------- | ||
| normalize_by_vanadium_dspacing_and_two_theta_removed_empty_can: | ||
| The same function but using data where events from an empty can / | ||
| empty instrument measurement have been subtracted. | ||
| """ | ||
| return IofDspacingTwoTheta( | ||
| _normalize_by_vanadium(data, vanadium, uncertainty_broadcast_mode) | ||
|
|
@@ -335,6 +423,22 @@ def _shallow_copy(da: sc.DataArray) -> sc.DataArray: | |
| return out | ||
|
|
||
|
|
||
| def subtract_background( | ||
| data: FocussedDataDspacing[SampleRun], | ||
| background: FocussedDataDspacing[BackgroundRun], | ||
| ) -> BackgroundSubtractedData[SampleRun]: | ||
| return BackgroundSubtractedData[SampleRun](data.bins.concatenate(-background)) | ||
|
Comment on lines
+426
to
+430
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we need the background subtraction to work also for histogrammed data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. For now, I have not seen histogrammed data at this point in the workflow. |
||
|
|
||
|
|
||
| def subtract_background_two_theta( | ||
| data: FocussedDataDspacingTwoTheta[SampleRun], | ||
| background: FocussedDataDspacingTwoTheta[BackgroundRun], | ||
| ) -> BackgroundSubtractedDataTwoTheta[SampleRun]: | ||
| return BackgroundSubtractedDataTwoTheta[SampleRun]( | ||
| data.bins.concatenate(-background) | ||
| ) | ||
|
|
||
|
|
||
| class RunNormalization(enum.Enum): | ||
| """Type of normalization applied to each run.""" | ||
|
|
||
|
|
@@ -356,7 +460,15 @@ def insert_run_normalization( | |
| workflow.insert(normalize_by_proton_charge) | ||
|
|
||
|
|
||
| def add_empty_can_subtraction(workflow: sciline.Pipeline) -> None: | ||
| """Insert providers to subtract empty can events from sample data.""" | ||
| workflow.insert(normalize_by_vanadium_dspacing_removed_empty_can) | ||
| workflow.insert(normalize_by_vanadium_dspacing_and_two_theta_removed_empty_can) | ||
|
|
||
|
|
||
| providers = ( | ||
| subtract_background, | ||
| subtract_background_two_theta, | ||
| normalize_by_proton_charge, | ||
| normalize_by_vanadium_dspacing, | ||
| normalize_by_vanadium_dspacing_and_two_theta, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to incorrectly use the file without coherent scattering.