-
Notifications
You must be signed in to change notification settings - Fork 1
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
Ewm7782 diffcal residual addtion #493
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #493 +/- ##
===========================================
+ Coverage 59.51% 96.53% +37.02%
===========================================
Files 64 65 +1
Lines 4836 4912 +76
===========================================
+ Hits 2878 4742 +1864
+ Misses 1958 170 -1788 ☔ View full report in Codecov by Sentry. |
For what it's worth, I've just tested this and think it's a very nice implementation. The residuals update upon recalculation as requested by Reece and continuing on from Peek Peak the workflow executes correctly. I happened to use this to compare the Lorentzian and Gaussian peak shapes (for a silicon run) and the residual very clearly shows that the latter is much better. This is a nice feature! |
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.
I think this can be turned into a recipe
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.
Done
@@ -356,7 +361,17 @@ def _renewFitPeaks(self, peakFunction): | |||
detectorPeaks=self.ingredients.groupedPeakLists, | |||
peakFunction=peakFunction, | |||
) | |||
return self.request(path="calibration/fitpeaks", payload=payload.json()) | |||
response = self.request(path="calibration/fitpeaks", payload=payload.json()) | |||
self._calculateResidual() |
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.
I think this call should occur in L294 and L301 instead
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.
Done
@mock.patch("snapred.backend.service.CalibrationService.CalculateResidualDiffCalRecipe") | ||
def test_calculateResidual(self, MockCalculateResidualDiffCalRecipe): | ||
# Arrange: set up mock request and mock recipe | ||
mockRequest = mock.Mock( | ||
spec=CalculateResidualRequest, | ||
inputWorkspace="inputWS", | ||
outputWorkspace="outputWS", | ||
fitPeaksDiagnostic="fitPeaksDiagWS", | ||
) | ||
|
||
# Mock the recipe execution result | ||
mockRecipeInstance = MockCalculateResidualDiffCalRecipe.return_value | ||
mockRecipeInstance.executeRecipe.return_value = "expected_result" | ||
|
||
# Act: call calculateResidual with the mock request | ||
result = self.instance.calculateResidual(mockRequest) | ||
|
||
# Assert: check that the recipe was called with correct parameters | ||
MockCalculateResidualDiffCalRecipe.assert_called_once_with() | ||
mockRecipeInstance.executeRecipe.assert_called_once_with( | ||
InputWorkspace=mockRequest.inputWorkspace, | ||
OutputWorkspace=mockRequest.outputWorkspace, | ||
FitPeaksDiagnosticWorkSpace=mockRequest.fitPeaksDiagnostic, | ||
) | ||
# Assert that the result is what the recipe returns | ||
self.assertEqual(result, "expected_result") # noqa: PT009 |
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.
I have been trying to transfer tests to use mock.sentinel
. I think it should be used here instead of "inputWS"
, "outputWS"
, "fitPeaksDiagWS"
, and "expected_result"
.
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.
Tried to implement this, but couldn't get it to work properly.
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.
Description of work
This work adds functionality to calculate and display a residual plot in the "peek peak" view of the Diffraction Calibration (DIFCAL) workflow in the SNAPRed application. This residual plot aids in assessing the quality of Bragg peak fitting by displaying the difference between calculated and observed data in specific regions. The addition of the residual helps users quickly gauge fit accuracy, making it particularly useful in analyzing diffraction-focused data.
Explanation of work
To achieve this, several changes and new methods were introduced:
dsp_column_f-dc_{run}
(observed data) andfit_peak_diag_{run}_2_pre_fitted
(calculated Bragg peak fit). Since the calculated workspace contains zero values outside peak regions, these were replaced withNaN
values before performing the subtraction. This ensures that the residual plot only displays values where calculations are meaningful, improving interpretability and avoiding misleading zero-based residuals.updateGraphs
Method:updateGraphs
method in the frontend "peek peak" view was modified to include the residual plot for each pixel subgroup. The residual is displayed as a green line with increased thickness for better visibility. This line plot uses a different color to distinguish it from the observed data and fit, adhering to design specifications.NaN
replacement technique for DIFCAL and leaving the full array intact for NORMCAL.peek peak view
now consistently displays observed data, the calculated fit, and the residual in each panel, with color and line style distinctions to help users easily differentiate between them.NaN
: In thefit_peak_diag_{run}_2_pre_fitted
workspace, zeros were replaced withNaN
to avoid misleading zero-based residuals outside peak regions. This change leveragesReplaceSpecialValues
, an algorithm that allows setting zero values toNaN
with a threshold.To test
Dev testing
Please first insure all pytests pass.
To test, follow the following directions:
application.yml
according to point to your local Calibration directorySNAPRed
and run diffcal workflow with the following inputs:58882
0.1
10
Silicone_NIST_001.json
Column
orAny
Run diffcal worklfow, stop at
Tweak Peak Peek
to inspect residual present within the graphs shown. Please test recalculate and other features to insure full functionality is retained.CIS testing
Please follow the steps above.
Link to EWM item
EWM # 7782
Verification
Acceptance Criteria
This list is for ease of reference, and does not replace reading the EWM story as part of the review. Verify this list matches the EWM story before reviewing.