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

Implement DataTree in auto_regression #570

Merged

Conversation

veni-vidi-vici-dormivi
Copy link
Collaborator

@veni-vidi-vici-dormivi veni-vidi-vici-dormivi commented Nov 30, 2024

I implement DataTree as data format for our _scen_ens functions.
Towards #106

  • Tests added
  • Fully documented, including CHANGELOG.rst

mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.37%. Comparing base (9ebcd27) to head (fb1eae2).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #570      +/-   ##
==========================================
+ Coverage   77.93%   78.37%   +0.44%     
==========================================
  Files          49       49              
  Lines        2986     3047      +61     
==========================================
+ Hits         2327     2388      +61     
  Misses        659      659              
Flag Coverage Δ
unittests 78.37% <100.00%> (+0.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@mathause mathause left a comment

Choose a reason for hiding this comment

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

I will need another pass but looks good so far.

mesmer/stats/_auto_regression.py Show resolved Hide resolved
mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
mesmer/stats/_auto_regression.py Outdated Show resolved Hide resolved
tests/unit/test_auto_regression_scen_ens.py Outdated Show resolved Hide resolved
tests/unit/test_auto_regression_scen_ens.py Outdated Show resolved Hide resolved
tests/unit/test_auto_regression_scen_ens.py Outdated Show resolved Hide resolved
mesmer/stats/_auto_regression.py Show resolved Hide resolved
Copy link
Member

@mathause mathause left a comment

Choose a reason for hiding this comment

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

Thanks

tests/unit/test_auto_regression_scen_ens.py Show resolved Hide resolved
@@ -521,7 +681,9 @@ def _draw_innovations_correlated_np(
return innovations


def fit_auto_regression(data, dim, lags):
def fit_auto_regression(
data: xr.DataArray, dim: str, lags: int | Sequence[int]
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually support arbitrary lags? No: #164 but also ok to leave.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, we do:

@pytest.mark.parametrize("lags", [1, 2, [2]])
def test_fit_auto_regression_xr_1D(lags):
data = trend_data_1D()
res = mesmer.stats.fit_auto_regression(data, "time", lags=lags)
lags = lags if not np.ndim(lags) == 0 else np.arange(lags) + 1
_check_dataset_form(
res,
"_fit_auto_regression_result",
required_vars=["intercept", "coeffs", "variance"],
)
_check_dataarray_form(res.intercept, "intercept", ndim=0, shape=())
_check_dataarray_form(
res.coeffs, "coeffs", ndim=1, required_dims={"lags"}, shape=(len(lags),)
)
_check_dataarray_form(res.variance, "variance", ndim=0, shape=())
expected = xr.DataArray(lags, coords={"lags": lags})
xr.testing.assert_allclose(res.lags, expected)

The test with lags = [2] only fits the lag 2, without also fitting 1.

@veni-vidi-vici-dormivi veni-vidi-vici-dormivi merged commit 72d83a5 into MESMER-group:main Dec 12, 2024
11 checks passed
@veni-vidi-vici-dormivi veni-vidi-vici-dormivi deleted the dt_autoreg branch December 12, 2024 15:52
veni-vidi-vici-dormivi added a commit to veni-vidi-vici-dormivi/mesmer that referenced this pull request Dec 12, 2024
* implement datatree in autoregression

* tests

* make _scen_ens functions public

* adjust tests to new names

* refactor and test errors

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Mathias Hauser <[email protected]>
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