-
Notifications
You must be signed in to change notification settings - Fork 234
Figure.meca: Add the private _FocalMechanismConvention class to simplify codes #3551
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
Conversation
af5ba53 to
c67368c
Compare
c67368c to
cc554e9
Compare
pygmt/src/_common.py
Outdated
| if convention in self._conventions: | ||
| # Convention is given via 'convention' and 'component' parameters. | ||
| if component not in {"full", "deviatoric", "dc"}: | ||
| msg = ( | ||
| f"Invalid component '{component}' for focal mechanism convention " | ||
| f"'{convention}'." | ||
| ) | ||
| raise GMTInvalidInput(msg) | ||
|
|
||
| self.convention = convention | ||
| self.code = self._conventions[convention] | ||
| if isinstance(self.code, dict): | ||
| self.code = self.code[component] | ||
| elif convention in self._codes: | ||
| # Convention is given as a single-letter code. | ||
| self.code = convention | ||
| self.convention = self._codes[convention] | ||
| else: | ||
| msg = f"Invalid focal mechanism convention '{convention}'." | ||
| raise GMTInvalidInput(msg) |
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.
Wondering if some of the pattern matching on 'convention' long names (e.g. akl) or single-letter aliases (e.g. a) could be simplified using StrEnum, but not sure how to handle the extra logic around 'component's. Haven't looked into it too closely, but there's supposedly ways to extend Enums with extra methods - https://realpython.com/python-enum/#adding-and-tweaking-member-methods.
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.
Yes, using StrEnum can simplify the code logic. The _FocalMechanismConvention class has been refactored in c59b8a3.
CodSpeed Performance ReportMerging #3551 will not alter performanceComparing Summary
|
Co-authored-by: Michael Grund <[email protected]>
yvonnefroehlich
left a comment
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.
Just some minor formulation and highlighting suggestions.
Co-authored-by: Yvonne Fröhlich <[email protected]>
Functions
convention_code,convention_name,convention_paramsare defined inmeca.pyand they can also be used when wrappingcoupe(#2019). So it's better to move these shared functions intopygmt/src/_common.pyas proposed in #3357.Instead of simply moving the functions, this PR adds the private
_FocalMechanismConventionclass which does the same thing as the three functions. With this new class, theFigure.mecasource codes can be simplified.It's likely the
Figure.mecamethod can be further simplified, but will leave it to future PRs to make this PR small for reviewing.