-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add private _FocalMechanismConvention class for handling focal mechanism conventions and refactor Figure.meca #3551
base: main
Are you sure you want to change the base?
Conversation
af5ba53
to
c67368c
Compare
c67368c
to
cc554e9
Compare
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.
Functions
convention_code
,convention_name
,convention_params
are defined inmeca.py
and they can also be used when wrappingcoupe
(#2019). So it's better to move these shared functions intopygmt/src/_common.py
as proposed in #3357.Instead of simply moving the functions, this PR adds the private
_FocalMechanismConvention
class which does the same thing as the three functions. With this new class, theFigure.meca
source codes can be simplified.It's likely the
Figure.meca
method can be further simplified, but will leave it to future PRs to make this PR small for reviewing.