-
Notifications
You must be signed in to change notification settings - Fork 101
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
Move exceptions to new module #1845
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
__all__ = [ | ||
"TimingModelError", | ||
"MissingParameter", | ||
"MissingTOAs", | ||
"MissingBinaryError", | ||
"UnknownBinaryModel", | ||
] | ||
|
||
|
||
# originally from fitter.py | ||
class DegeneracyWarning(UserWarning): | ||
pass | ||
|
||
|
||
class ConvergenceFailure(ValueError): | ||
pass | ||
|
||
|
||
class MaxiterReached(ConvergenceFailure): | ||
pass | ||
|
||
|
||
class StepProblem(ConvergenceFailure): | ||
pass | ||
|
||
|
||
class CorrelatedErrors(ValueError): | ||
def __init__(self, model): | ||
trouble_components = [ | ||
c.__class__.__name__ | ||
for c in model.NoiseComponent_list | ||
if c.introduces_correlated_errors | ||
] | ||
super().__init__( | ||
f"Model has correlated errors and requires a GLS-based fitter; " | ||
f"remove {trouble_components} if you want to use WLS" | ||
) | ||
self.trouble_components = trouble_components | ||
|
||
|
||
# from timing_model.py | ||
class MissingTOAs(ValueError): | ||
"""Some parameter does not describe any TOAs.""" | ||
|
||
def __init__(self, parameter_names): | ||
if isinstance(parameter_names, str): | ||
parameter_names = [parameter_names] | ||
if len(parameter_names) == 1: | ||
msg = f"Parameter {parameter_names[0]} does not correspond to any TOAs: you might need to run `model.find_empty_masks(toas, freeze=True)`" | ||
elif len(parameter_names) > 1: | ||
msg = f"Parameters {' '.join(parameter_names)} do not correspond to any TOAs: you might need to run `model.find_empty_masks(toas, freeze=True)`" | ||
else: | ||
raise ValueError("Incorrect attempt to construct MissingTOAs") | ||
super().__init__(msg) | ||
self.parameter_names = parameter_names | ||
|
||
|
||
class PropertyAttributeError(ValueError): | ||
pass | ||
|
||
|
||
class TimingModelError(ValueError): | ||
"""Generic base class for timing model errors.""" | ||
|
||
pass | ||
|
||
|
||
class MissingParameter(TimingModelError): | ||
"""A required model parameter was not included. | ||
|
||
Parameters | ||
---------- | ||
module | ||
name of the model class that raised the error | ||
param | ||
name of the missing parameter | ||
msg | ||
additional message | ||
|
||
""" | ||
|
||
def __init__(self, module, param, msg=None): | ||
super().__init__(msg) | ||
self.module = module | ||
self.param = param | ||
self.msg = msg | ||
|
||
def __str__(self): | ||
result = f"{self.module}.{self.param}" | ||
if self.msg is not None: | ||
result += "\n " + self.msg | ||
return result | ||
|
||
|
||
class AliasConflict(TimingModelError): | ||
"""If the same alias is used for different parameters.""" | ||
|
||
pass | ||
|
||
|
||
class UnknownParameter(TimingModelError): | ||
"""Signal that a parameter name does not match any PINT parameters and their aliases.""" | ||
|
||
pass | ||
|
||
|
||
class UnknownBinaryModel(TimingModelError): | ||
"""Signal that the par file requested a binary model not in PINT.""" | ||
|
||
def __init__(self, message, suggestion=None): | ||
super().__init__(message) | ||
self.suggestion = suggestion | ||
|
||
def __str__(self): | ||
base_message = super().__str__() | ||
if self.suggestion: | ||
return f"{base_message} Perhaps use {self.suggestion}?" | ||
return base_message | ||
|
||
|
||
class MissingBinaryError(TimingModelError): | ||
"""Error for missing BINARY parameter.""" | ||
|
||
pass | ||
|
||
|
||
# from utils.py | ||
class PINTPrecisionError(RuntimeError): | ||
pass | ||
|
||
|
||
class PrefixError(ValueError): | ||
pass | ||
|
||
|
||
# from models.parameter.py | ||
class InvalidModelParameters(ValueError): | ||
pass | ||
|
||
|
||
# models.model_builder.py | ||
class ComponentConflict(ValueError): | ||
"""Error for multiple components can be select but no other indications.""" | ||
|
||
|
||
# observatories.__init__.py | ||
class ClockCorrectionError(RuntimeError): | ||
"""Unspecified error doing clock correction.""" | ||
|
||
pass | ||
|
||
|
||
class NoClockCorrections(ClockCorrectionError): | ||
"""Clock corrections are expected but none are available.""" | ||
|
||
pass | ||
|
||
|
||
class ClockCorrectionOutOfRange(ClockCorrectionError): | ||
"""Clock corrections are available but the requested time is not covered.""" | ||
|
||
pass |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Can you please add docstrings explaining what each of these exceptions mean?
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 don't think I necessarily can, since I didn't write them. I could probably infer some from usage but that would take a while.