-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #152 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 346 369 +23
=========================================
+ Hits 346 369 +23
Continue to review full report at Codecov.
|
xcdat/spatial_avg.py
Outdated
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): |
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.
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()`
- Update variable names for prime meridian index
- Methods include `_get_longitude_weights()`, `_get_latitude_weights()`, and `_calculate_weights()`
- Fix incorrect axes refs to axis
…dat into bugfix/150-refactor-spatial-avg
- 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"`
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.
Just some minor suggestions that can be merged directly by accepting them. After that, it should be good to squash and merge.
Co-authored-by: Tom Vo <[email protected]>
Co-authored-by: Tom Vo <[email protected]>
Co-authored-by: Tom Vo <[email protected]>
Description
Checklist
If applicable: