Skip to content
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

Refactor spatial averaging with more robust handling of longitude spanning prime meridian #152

Merged
merged 20 commits into from
Nov 23, 2021

Conversation

pochedls
Copy link
Collaborator

@pochedls pochedls commented Nov 12, 2021

Description

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2021

Codecov Report

Merging #152 (7a0caac) into main (b010930) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #152   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          346       369   +23     
=========================================
+ Hits           346       369   +23     
Impacted Files Coverage Δ
xcdat/spatial_avg.py 100.00% <100.00%> (ø)
xcdat/xcdat.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b010930...7a0caac. Read the comment docs.

xcdat/spatial_avg.py Outdated Show resolved Hide resolved
xcdat/spatial_avg.py Outdated Show resolved Hide resolved
def _force_lon_linearity(
self, domain_bounds: xr.DataArray, region_bounds: np.ndarray
) -> Tuple[xr.DataArray, np.ndarray]:
def _align_longitude_to_360_axis(self, domain_bounds: xr.DataArray):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace _force_lon_linearity with _align_longitude_to_360_axis. It essentially ensures that the domain bounds neatly span from 0 to 360 degrees. If there is a grid cell that crosses the prime meridian (e.g., [-1, 1]) it breaks this into to different grid cells spanning [0, 1] and [359, 360]. In this case, the original grid cell index is returned with the function. The domain_bounds shape goes from [nlon, 2] to [nlon+1, 2]. When these weights are calculated (e.g., 1 - 0 = 1 and 360 - 359 = 1) they are summed and both weights are included with the grid cell that was indexed (so that the weight vector is length nlon).

- New methods include `_get_longitude_weights()` and `_get_latitude_weights()`
@tomvothecoder
Copy link
Collaborator

@pochedls I noticed some of my commits from #154 were merged directly to this branch before #154 was merged. Not a big deal, but there will probably some merge conflicts to handle.

- New methods include `_get_longitude_weights()`, `_get_latitude_weights()`, and `_calculate_weights()`
- Add `.copy()` for bounds dict

Refactor `_align_longitude_to_360_axis()`
- Update variable names for prime meridian index

Update `_get_weights()` to get weights for `axis` arg

Fix incorrect 'axes' refs to 'axis'

Update default val of `weights` to `"generate"`
@tomvothecoder tomvothecoder changed the title Bugfix/150 refactor spatial avg Refactor spatial averaging with more robust handling of longitude spanning prime meridian Nov 22, 2021
@tomvothecoder
Copy link
Collaborator

PR #154 has been merged into this branch so I'll do a final review of this PR.

I noticed you opened up #163. I think we should open up a separate branch and PR for that one.

xcdat/spatial_avg.py Outdated Show resolved Hide resolved
xcdat/spatial_avg.py Outdated Show resolved Hide resolved
xcdat/spatial_avg.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@tomvothecoder tomvothecoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor suggestions that can be merged directly by accepting them. After that, it should be good to squash and merge.

pochedls and others added 3 commits November 23, 2021 12:32
@pochedls pochedls merged commit 69dd39d into main Nov 23, 2021
@pochedls pochedls deleted the bugfix/150-refactor-spatial-avg branch November 23, 2021 19:14
@tomvothecoder tomvothecoder added the type: enhancement New enhancement request label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New enhancement request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Spatial Averaging: More Robust Handling of Longitude Spanning Prime Meridian
3 participants