Repository navigation
AdrianBenson/issue36 #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ce3a39e
refactor: update include_unknown_fields default to True and clean up …
15233e3
docs: enhance mapper argument documentation for clarity and consistency
8b0f1cc
refactor: remove calculate_calibration_factor argument from solve_lst…
9c3a730
rebase on main
ead28be
Start fixing pre commit hook issues.
c6d9770
This is a mess 1
122fd9a
Refactor: many edits and fixes to adress lint and type issues.
22bc7f5
Fix tests for keyword only args
fe7ce17
Fix tests for keyword only args and other issues
343e366
Add config for pre-commit and spell.
79ebf83
Spell checking
4a1c67a
Add newline ate file end
a12e6bb
Update for excel_file arg
1723779
Ensure checks only touch python.
67a8184
Spell checking applied to tests
ec66eba
Add pandas stubs and ty as dev dependencies. Fix typos.
5340c6d
Refactor and improve code quality across multiple modules
70789f1
strip out TypeAlias hints, replace with type =
a074697
Add numpy and matplotlib as direct dependencies.
e5b3047
Fix type errors
9998015
Spell checked docs.
b811845
Change ruff rules to default, and make final changes.
51e6ad8
Make terrain correction status messages go to stderr.
caa8421
Resolve doc build errors.
4b9f0c3
Adress review comments
7b04860
doh!
edaa439
double doh!
b98852e
White space and spelling
a5f3591
Add method to catch percentile clipping issues.
b01f5e7
Add todo notes for future work.
7a66369
Add tests
d4c69af
Don't spell check git stuff
8f6a81a
Percentile clip check method with unit tests
17b110c
Add Warner class, add ax option to plot args
c536f0b
Use Warner class everywhere
41ecfdb
bug: rm file- form _display()
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,3 +186,4 @@ docs/_build | |
| docs/source/api/generated | ||
| docs/source/api/api/* | ||
| docs/zz/* | ||
| ARCHITECTURE.md | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,5 +15,9 @@ | |
| "data-science-tools", | ||
| "git", | ||
| "en-au" | ||
| ], | ||
| "ignorePaths": [ | ||
| ".git/**", | ||
| ".gitignore" | ||
| ] | ||
| } | ||
1,226 changes: 613 additions & 613 deletions
1,226
examples/ocean_load/quicktide/okataina_qtp_input.csv
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| addopts | ||
| afactor | ||
| aimport | ||
| airgap | ||
| Aleksandr | ||
| alisonk | ||
|
|
||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,17 +23,23 @@ | |
| import pandas as pd | ||
|
|
||
| from gsolve.core._typing import GSolveSolverMethod, GSolveSolverReturn | ||
| from gsolve.core.utils import GSolveUserWarning | ||
| from gsolve.gsolve_outputs import GSolveResults | ||
|
|
||
| __all__ = ["GSolveSolverMethod", "call_gsolve_calibration", "call_gsolve_lstsq"] | ||
|
|
||
|
|
||
| _GSOLVE_SOLVER_METHODS: dict[int, str] = { | ||
| 1: "Unconstrained least squares", | ||
| 2: "Partially constrained least squares", | ||
| 3: "Constrained least squares", | ||
| } | ||
|
|
||
|
|
||
| class GSolveSolverWarning(UserWarning): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this called "automatically" when the solver is run? i.e. the checks |
||
| """Raised when gsolve may produce unreliable results.""" | ||
|
|
||
|
|
||
| def call_gsolve_lstsq( | ||
| obs: pd.DataFrame, | ||
| ref_sites: pd.DataFrame, | ||
|
|
@@ -387,13 +393,20 @@ def g_solver_lstsq( # ruff: ignore[too-many-positional-arguments] | |
| residuals = b - np.dot(A, solution[:n_parameters]) | ||
|
|
||
| # Define percentile clipping interval | ||
| # TODO: Should this be done using residual**2 and clip upper only? | ||
| perc = (100.0 - percentile_clipping) / 2 | ||
| ci_l = np.percentile(residuals[:n_obs], perc) | ||
| ci_h = np.percentile(residuals[:n_obs], 100.0 - perc) | ||
|
|
||
| # Build mask of outliers | ||
| mask = ((residuals[:n_obs] > ci_l) & (residuals[:n_obs] < ci_h)).flatten() | ||
|
|
||
| _check_post_clip_data_are_ok( | ||
| mask=mask, | ||
| obs_site_id=obs_site_id, | ||
| ties_site_id=ties_site_id, | ||
| obs_loop=obs_loop, | ||
| use_loops=use_loops, | ||
| ) | ||
| # Mask outliers | ||
| A[:n_obs, :][~mask] = 0 | ||
| b[:n_obs, :][~mask] = 0 | ||
|
|
@@ -446,3 +459,80 @@ def g_solver_lstsq( # ruff: ignore[too-many-positional-arguments] | |
| calibration_factor = None | ||
|
|
||
| return gravity, residuals, gravity_var, drift, baseline, calibration_factor, mask | ||
|
|
||
|
|
||
| def _check_post_clip_data_are_ok( | ||
| mask: np.ndarray[tuple[int]], | ||
| obs_site_id: np.ndarray[tuple[int]], | ||
| ties_site_id: np.ndarray[tuple[int]], | ||
| obs_loop: np.ndarray[tuple[int]], | ||
| use_loops: bool, | ||
| ) -> bool: | ||
| """Check if percentile clipping does damage.""" | ||
| warner = GSolveUserWarning( | ||
| prefix="After percentile clipping:", default_category=GSolveSolverWarning | ||
| ) | ||
| obs_site_id_remain = obs_site_id[mask] | ||
| obs_loop_remain = obs_loop[mask] | ||
|
|
||
| # warn about site removal | ||
| if len(dropped_sites := np.setdiff1d(obs_site_id, obs_site_id_remain)) > 0: | ||
| warner.warn(f"sites were completely removed: {dropped_sites}") | ||
|
|
||
| # ensure all tie sites made it | ||
| dropped_ties = np.intersect1d(ties_site_id, obs_site_id_remain) | ||
| if len(dropped_ties) == 0: | ||
| msg = ( | ||
| "All reference sites were completely removed due to " | ||
| f"percentile clipping: {dropped_ties}" | ||
| ) | ||
| raise ValueError(msg) | ||
|
|
||
| if len(dropped_ties) < len(ties_site_id): | ||
| warner.warn( | ||
| f"{len(dropped_ties)} of {len(ties_site_id)} reference sites " | ||
| f"were completely: {dropped_ties})" | ||
| ) | ||
|
|
||
| # if using loops and there was actually more than 1 loop | ||
| # - check that loops were not completely removed | ||
| # - check that loops have common stations or include a ref site | ||
|
|
||
| # if use_loops and have > 1 loops, then check_loops | ||
| check_loops = use_loops and not (obs_loop[0] == obs_loop).all() | ||
| if check_loops: | ||
| if len(dropped_loops := np.setdiff1d(obs_loop, obs_loop_remain)) > 0: | ||
| warner.warn(f"some loops were completely removed: {dropped_loops}") | ||
|
|
||
| # check if loops are now isolated from rest of survey | ||
| for loop_id in np.unique(obs_loop_remain): | ||
| m_pre = obs_loop == loop_id | ||
| m_post = obs_loop_remain == loop_id | ||
|
|
||
| in_other_loops_pre = np.intersect1d(obs_site_id[m_pre], obs_site_id[~m_pre]) | ||
| in_other_loops_pre = len(in_other_loops_pre) > 0 | ||
| in_other_loops_post = np.intersect1d( | ||
| obs_site_id_remain[m_post], obs_site_id_remain[~m_post] | ||
| ) | ||
| in_other_loops_post = len(in_other_loops_post) > 0 | ||
|
|
||
| has_ref_gravity_pre = np.isin(ties_site_id, obs_site_id[m_pre]).any() | ||
| has_ref_gravity_post = np.isin( | ||
| ties_site_id, obs_site_id_remain[m_post] | ||
| ).any() | ||
|
|
||
| isolated_loop_pre = not in_other_loops_pre and not has_ref_gravity_pre | ||
| isolated_loop_post = not in_other_loops_post and not has_ref_gravity_post | ||
|
|
||
| if isolated_loop_pre: | ||
| # Already isolated so, nothing will have changed | ||
| continue | ||
| if isolated_loop_post: | ||
| warner.warn( | ||
| f"loop '{loop_id}' has no sites in common with the rest of survey" | ||
| ) | ||
|
|
||
| if has_ref_gravity_pre and not has_ref_gravity_post: | ||
| warner.warn(f"all reference sites removed from loop '{loop_id}'") | ||
|
|
||
| return warner.count == 0 | ||
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.
does this file exist?