refactor: add ocean and land geocenter functions to class - #192
Merged
Conversation
refactor: change assertions to value errors test: add geocenter tests
There was a problem hiding this comment.
Pull request overview
Refactors geocenter-related functionality by moving seasonal land/ocean geocenter models into the geocenter class (with additional constructor-style helpers), and replaces a few runtime assert checks with explicit ValueErrors. Adds initial test coverage for geocenter seasonal modeling and from_harmonics.
Changes:
- Add
geocenter.land_seasonal()/geocenter.ocean_seasonal()seasonal model classmethods and convert some constructors to classmethods (from_harmonics,from_matrix). - Replace selected
assertstatements withValueErrorfor more reliable runtime validation. - Add new geocenter tests and expand output metadata in degree-1 processing scripts.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_geocenter.py | Adds tests for land seasonal geocenter modeling and geocenter.from_harmonics. |
| gravity_toolkit/time.py | Replaces an assert with ValueError for datetime unit validation. |
| gravity_toolkit/time_series/lomb_scargle.py | Replaces an assert with ValueError for OMEGA range validation. |
| gravity_toolkit/scripts/monte_carlo_degree_one.py | Uses new geocenter.land_seasonal and updates geocenter construction patterns; adds time_coverage_duration. |
| gravity_toolkit/scripts/calc_degree_one.py | Uses new geocenter.land_seasonal and updates geocenter construction patterns; adds time_coverage_duration. |
| gravity_toolkit/read_SLR_harmonics.py | Replaces an assert with a ValueError including a clearer mismatch message. |
| gravity_toolkit/harmonic_summation.py | Replaces longitude coverage asserts with explicit ValueErrors. |
| gravity_toolkit/geocenter.py | Adds seasonal land/ocean geocenter model helpers and converts from_harmonics/from_matrix to classmethods. |
| doc/source/_assets/gravity-refs.bib | Adds bibliography entry for Chen et al. (1999) referenced by new seasonal model docs. |
Suppressed comments (1)
gravity_toolkit/geocenter.py:891
- Same issue as
land_seasonal:mean(apply=True)updates only C10/C11/S11, so X/Y/Z keep any non-zero mean and become inconsistent with the mean-removed harmonics. Recompute cartesian components after mean removal (or subtract the mean in X/Y/Z before converting).
temp = cls(time=time, **XYZ).from_cartesian()
# remove the mean geocenter motion from the seasonal component
temp.mean(apply=True)
# return the seasonal geocenter motion
return temp
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+854
to
+858
| temp = cls(time=time, **XYZ).from_cartesian() | ||
| # remove the mean geocenter motion from the seasonal component | ||
| temp.mean(apply=True) | ||
| # return the seasonal geocenter motion | ||
| return temp |
Comment on lines
994
to
998
| if temp.ndim == 2: | ||
| self.C10 = np.copy(temp.clm[1, 0]) | ||
| self.C11 = np.copy(temp.clm[1, 1]) | ||
| self.S11 = np.copy(temp.slm[1, 1]) | ||
| C10 = np.copy(temp.clm[1, 0]) | ||
| C11 = np.copy(temp.clm[1, 1]) | ||
| S11 = np.copy(temp.slm[1, 1]) | ||
| elif temp.ndim == 3: |
| ) | ||
| end_time = f'{calendar_year[-1]:4.0f}-{calendar_month[-1]:02.0f}' | ||
| fid.write(' {0:22}: {1}\n'.format('time_coverage_end', end_time)) | ||
| duration = f'{month[-1] - month[0]:02.0f} months' |
| ) | ||
| end_time = f'{calendar_year[-1]:4.0f}-{calendar_month[-1]:02.0f}' | ||
| fid.write(' {0:22}: {1}\n'.format('time_coverage_end', end_time)) | ||
| duration = f'{month[-1] - month[0]:02.0f} months' |
Comment on lines
+861
to
+865
| def ocean_seasonal(cls, time): | ||
| """ | ||
| Model the seasonal component of geocenter motion induced by ocean | ||
| variations as estimated by :cite:t:`Chen:1999ki` | ||
|
|
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.
refactor: change assertions to value errors
test: add geocenter tests