-
Notifications
You must be signed in to change notification settings - Fork 18
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
localized_covariance: add xarray wrapper #191
localized_covariance: add xarray wrapper #191
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #191 +/- ##
=======================================
Coverage ? 80.24%
=======================================
Files ? 33
Lines ? 1473
Branches ? 0
=======================================
Hits ? 1182
Misses ? 291
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@znicholls do you have time to take a look at this? |
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.
Sorry I looked at this last night but forgot to hit 'Submit'
mesmer/core/localized_covariance.py
Outdated
(sample_dim,) = set(all_dims) - {dim} | ||
out_dims = create_equal_dim_names(sample_dim) | ||
|
||
# TODO: not sure which one is nicer |
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.
I prefer apply_ufunc
, just for consistency with stuff that is elsewhere and so people can see how to use that functionality when dimensions don't line up perfectly
mesmer/core/utils.py
Outdated
@@ -4,6 +4,10 @@ | |||
import numpy as np | |||
import xarray as xr | |||
|
|||
# xarray cannot represent two dims with the same name -> need to give them another name | |||
# TODO: expose this via function argument or config? |
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.
I'd do function argument in this case
ar_coefs = np.random.randn(3) | ||
ar_coefs = xr.DataArray(ar_coefs, dims="cell") | ||
|
||
cov = np.cov(random_data_5x3, rowvar=False) |
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.
It's super annoying that there's not a method in xarray to calculate a covariance matrix (I get that naming the output dimensions is hard but it's such a fundamental thing, it's weird it doesn't already exist)
Co-authored-by: Zeb Nicholls <zebedee.nicholls@climate-energy-college.org>
Thanks for your review! |
isort . && black . && flake8
CHANGELOG.rst
xarray wrapper for
find_localized_empirical_covariance
andadjust_covariance_ar1
. Ugly as hell but there is no good way to have the same dim more than once for a DataArray.cc @znicholls