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

Add autocorr accessor to _BaseAccessor class #65

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

suhaani-agarwal
Copy link
Contributor

@suhaani-agarwal suhaani-agarwal commented Feb 26, 2025

This is related to arviz-devs/arviz-plots#153.
Added an autocorr accessor to the _BaseAccessor class, similar to the existing hdi and ess accessors.


📚 Documentation preview 📚: https://arviz-stats--65.org.readthedocs.build/en/65/

Comment on lines 127 to 130
def autocorr(self, max_lag=None, dims=None, **kwargs):
"""Compute autocorrelation for all variables in the dataset."""
kwargs["max_lag"] = max_lag
return self._apply("autocorr", dims=dims, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def autocorr(self, max_lag=None, dims=None, **kwargs):
"""Compute autocorrelation for all variables in the dataset."""
kwargs["max_lag"] = max_lag
return self._apply("autocorr", dims=dims, **kwargs)
def autocorr(self, dims=None, **kwargs):
"""Compute autocorrelation for all variables in the dataset."""
return self._apply("autocorr", dims=dims, **kwargs)

Copy link
Contributor

Choose a reason for hiding this comment

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

compute everything and then handle max_lag when plotting.

@aloctavodia
Copy link
Contributor

You also need to add something like this to datarray.py

def autocorr(self, da, dims=None):
    """Compute autocorrelation on DataArray input."""
    dims = validate_dims(dims)
    return apply_ufunc(
        self.array_class.autocorr,
        da,
        input_core_dims=[dims],
        output_core_dims=[dims],
    )

@suhaani-agarwal
Copy link
Contributor Author

I have added the autocorr function in dataarray.py and made the changes you asked. @aloctavodia kindly review. Pls let me know if any further changes are required

@aloctavodia aloctavodia merged commit 2999412 into arviz-devs:main Feb 27, 2025
1 check failed
@suhaani-agarwal suhaani-agarwal deleted the autocorr-accessor branch February 27, 2025 14:28
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.

2 participants