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

localized_covariance: add xarray wrapper #191

Merged
merged 8 commits into from
Sep 9, 2022

Conversation

mathause
Copy link
Member

xarray wrapper for find_localized_empirical_covariance and adjust_covariance_ar1. Ugly as hell but there is no good way to have the same dim more than once for a DataArray.

cc @znicholls

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@5a8c3c7). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #191   +/-   ##
=======================================
  Coverage        ?   80.24%           
=======================================
  Files           ?       33           
  Lines           ?     1473           
  Branches        ?        0           
=======================================
  Hits            ?     1182           
  Misses          ?      291           
  Partials        ?        0           
Flag Coverage Δ
unittests 80.24% <0.00%> (?)

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mathause
Copy link
Member Author

mathause commented Sep 6, 2022

@znicholls do you have time to take a look at this?

Copy link
Collaborator

@znicholls znicholls left a 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'

(sample_dim,) = set(all_dims) - {dim}
out_dims = create_equal_dim_names(sample_dim)

# TODO: not sure which one is nicer
Copy link
Collaborator

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

@@ -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?
Copy link
Collaborator

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)
Copy link
Collaborator

@znicholls znicholls Sep 6, 2022

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)

mathause and others added 3 commits September 7, 2022 14:28
@mathause mathause merged commit 76b805f into MESMER-group:main Sep 9, 2022
@mathause mathause deleted the localized_covariance_xarray branch September 9, 2022 08:17
@mathause
Copy link
Member Author

mathause commented Sep 9, 2022

Thanks for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

covariance & localisation: extract functions
3 participants