Tolerate malformed residual lines in PRIDE-PPPAR .res files - #35
Open
mikegottlieb84 wants to merge 1 commit into
Open
Tolerate malformed residual lines in PRIDE-PPPAR .res files#35mikegottlieb84 wants to merge 1 commit into
mikegottlieb84 wants to merge 1 commit into
Conversation
PRIDE-PPPAR writes phase residuals in fixed-width columns. An unusually large residual (e.g. an unresolved ambiguity/cycle slip) can overflow its column and run into the neighbouring field with no separating space (e.g. "0.0000-1641.5825"), which breaks get_wrms_from_res's whitespace split and raises ValueError. That exception was caught by a broad except in kin_to_kin_position_df, which nulled out the wrms column for every epoch in the file rather than just the malformed one. Catch the per-line parse error, skip just that satellite's contribution to the epoch's WRMS, and guard against an epoch ending up with zero valid weights (return NaN for that epoch instead of raising ZeroDivisionError).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves robustness of PRIDE-PPPAR .res parsing by making per-epoch WRMS computation resilient to malformed fixed-width residual lines that overflow into adjacent fields, preventing a single bad satellite record from blanking WRMS for an entire file.
Changes:
- Catch per-line parse failures while reading residual/weight fields and skip only the malformed satellite contribution.
- Log a warning when skipping an unparsable residual line (instead of failing the epoch/file).
- Return
NaNfor an epoch WRMS when no valid weights were accumulated (avoids division-by-zero).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
82
to
+86
| while not line.startswith("TIM"): | ||
| phase_residual = float(line_data[1]) | ||
| phase_weight = float(line_data[3].replace("D", "E")) | ||
| sumOfSquares += phase_residual**2 * phase_weight | ||
| sumOfWeights += phase_weight | ||
| try: | ||
| phase_residual = float(line_data[1]) | ||
| phase_weight = float(line_data[3].replace("D", "E")) | ||
| except (ValueError, IndexError): |
Comment on lines
+83
to
+87
| try: | ||
| phase_residual = float(line_data[1]) | ||
| phase_weight = float(line_data[3].replace("D", "E")) | ||
| except (ValueError, IndexError): | ||
| # PRIDE-PPPAR writes residuals in fixed-width columns; an |
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.
PRIDE-PPPAR writes phase residuals in fixed-width columns. An unusually large residual (e.g. an unresolved ambiguity/cycle slip) can overflow its column and run into the neighbouring field with no separating space (e.g. "0.0000-1641.5825"), which breaks get_wrms_from_res's whitespace split and raises ValueError. That exception was caught by a broad except in kin_to_kin_position_df, which nulled out the wrms column for every epoch in the file rather than just the malformed one.
Catch the per-line parse error, skip just that satellite's contribution to the epoch's WRMS, and guard against an epoch ending up with zero valid weights (return NaN for that epoch instead of raising ZeroDivisionError).