Repository navigation
Figure.meca: Add the private _FocalMechanismConvention class to simplify codes - #3551
Merged
Merged
Conversation
seisman
force-pushed
the
refactor/meca-convention
branch
from
October 23, 2024 13:02
af5ba53 to
c67368c
Compare
seisman
force-pushed
the
refactor/meca-convention
branch
from
October 23, 2024 13:08
c67368c to
cc554e9
Compare
weiji14
reviewed
Oct 23, 2024
Comment on lines
+196
to
+215
| 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) |
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
Yes, using StrEnum can simplify the code logic. The _FocalMechanismConvention class has been refactored in c59b8a3.
seisman
marked this pull request as ready for review
December 20, 2024 16:15
CodSpeed Performance ReportMerging #3551 will not alter performanceComparing Summary
|
michaelgrund
reviewed
Jan 7, 2025
Co-authored-by: Michael Grund <[email protected]>
Co-authored-by: Yvonne Fröhlich <[email protected]>
13 of 54 tasks
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.
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.