Repository navigation
Check peak-range files in one place and set d0 in autoreduction (#1147) - #1158
Merged
Merged
Conversation
Autoreduction fitted peaks without applying the d0 of the peak-range file, so its project files stored a NaN d-reference and the strain/stress viewer showed all-NaN strain with no message. The peak fitting tool already maps an empty d0 list to 1.0; that rule now lives in pyrs.peaks.peak_ranges. - add read_peak_range_json(): empty or wrong-length d0 list -> DEFAULT_D0 (1.0, a placeholder, not a measured d0); anything else malformed raises PeakRangeFileError naming the file and peak - PeakFittingModel.load_peak_range_json delegates to it (valid files load as before) - the peak fitting window reports a bad file and keeps the ranges on screen instead of failing - docs/ground_truths.md: root causes of #1147 (NaN sample positions in 47% of autoreduced files; NaN d-reference) and proposed, unapplied fixes Fitted parameters are unaffected; only the stored d reference changes (NaN -> 1.0) for files fitted through the new function. Defects recorded, not fixed: - DD-34: calculate_sub_run_time_average returns NaN for vx/vy/vz when the raw log starts with a NaN placeholder - DD-35: strain/stress viewer selectedPeak setter lets StrainField errors escape a Qt slot and abort the process Assisted-by: Claude
Review of the first #1147 commit found inputs that escaped the one-type contract the peak fitting window and autoreduction rely on: - a FIFO path hung the caller; a device or huge file was read without bound - deeply nested JSON raised RecursionError; a 5000-digit number raised ValueError; a 400-digit number raised OverflowError - a None, int, bytes or NUL-containing path raised TypeError or ValueError - a repeated key silently dropped the first peak - a null or non-printable peak label became the label "None" or was accepted - keys and values were echoed raw into messages (control characters, no limit) The file is now opened without blocking, must be a regular file under 1 MB, is decoded as UTF-8 (a BOM is accepted) and parsed with a duplicate-key check; every failure is a PeakRangeFileError. A file with no peaks is an error. Tests: every bad-input case now expects PeakRangeFileError (not ValueError), adds a regression test for each input above, and the GUI test asserts that nothing on screen changed. Not done, left for a decision: the texture-fitting reader and the writers share this file format but not its checks; the 1.0 default is not flagged to callers. Assisted-by: Claude
Follow-up to the review of the first #1147 commits: - the texture fitting tool's from_json/to_json and the peak fitting tool's save now use the same checked reader and a new checked writer, write_peak_range_json, so a file PyRS writes is one it reads; a bad file or table is reported through the existing failure paths and leaves the table and disk unchanged (the texture reader used to turn a null d0 into 1.0) - a defaulted d0 (empty or wrong-length list) logs a warning naming the file and peak, since 1.0 is a placeholder - apply_d0() stores a peak's d0 on its fitted PeakCollection, so a caller cannot forget the step that set_d_reference's NaN default hides - two peaks may not share a label (the label is the peak tag) - error messages keep the file name when the path is long Tests: writer, apply_d0, warning, duplicate labels, the texture model's fit-range files, the peak fitting model's save, and a GUI test for a bad save. Defect recorded, not fixed: - DD-36: TextureFittingViewer.load calls TextureFittingModel.from_json with one argument instead of two, so the "Load Stress state" action raises TypeError out of a Qt slot Assisted-by: Claude
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #1158 +/- ##
==========================================
+ Coverage 87.12% 87.23% +0.11%
==========================================
Files 106 107 +1
Lines 16655 16786 +131
==========================================
+ Hits 14510 14644 +134
+ Misses 2145 2142 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1147.
Problem
Autoreduction fits peaks from a peak-range JSON but never applied its
d0, so the project file stored a NaN d-reference. The strain/stress viewer then loaded it without error and showed NaN strain everywhere, with no message. The peak fitting tool already mapped an emptyd0list to 1.0; autoreduction did not.What this changes
pyrs/peaks/peak_ranges.py(new): one checked reader,read_peak_range_json, and writer,write_peak_range_json. An empty or wrong-lengthd0list becomesDEFAULT_D0 = 1.0(a placeholder, not a measured d0; a warning naming the file and peak is logged). Anything else malformed raisesPeakRangeFileError.apply_d0(peak_collection, peak): stores the d0 on a fittedPeakCollection, so a caller cannot forget the step thatset_d_reference's NaN default hides.PeakRangeFileError. This covers a FIFO or directory, an oversized or non-UTF-8 file, deeply nested JSON, huge numbers, a repeated key, a bad or duplicate label, and a bad window or d0. Messages name the file and peak and carry no raw control characters.nulld0 into 1.0.docs/ground_truths.md: root causes of Explore why peak-fit autoreduced data cannot be loaded into the stress/strain visualization #1147;docs/deferred_defects.md: DD-34 to DD-36.Not in this PR
calculate_sub_run_time_average), is only proposed inground_truths.mdand recorded as DD-34.peak_ranges.d referencechanges (NaN to 1.0) for files fitted throughapply_d0.Review
Design, test and security reviews were run on the first commits; their bugs are fixed here (see the second and third commits). Findings left as design choices are noted in the commit messages.
Testing
pixi run test-unit: 1391 passed.tests/ui/test_peak_fitting.py,tests/ui/test_texture_fitting.py: 35 passed (offscreen).Companion PRs carry the same change to
qaandmain.Assisted-by: Claude