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

extract select_ar_order #176

Merged
merged 9 commits into from Jul 12, 2022

Conversation

mathause
Copy link
Member

@mathause mathause commented Jul 1, 2022

This PR extracts ar_select_order to its own numpy and xarray wrappers. There are still some open TODOs but I like the pattern that emerges in train_gv.py.

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2022

Codecov Report

Merging #176 (d293487) into master (c08c9c9) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
+ Coverage   79.26%   79.32%   +0.05%     
==========================================
  Files          30       30              
  Lines        1389     1393       +4     
==========================================
+ Hits         1101     1105       +4     
  Misses        288      288              
Flag Coverage Δ
unittests 79.32% <100.00%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
mesmer/calibrate_mesmer/train_gv.py 83.82% <100.00%> (-0.90%) ⬇️
mesmer/core/auto_regression.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c08c9c9...d293487. Read the comment docs.

Only full models can be selected.
"""

from statsmodels.tsa.ar_model import ar_select_order
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it be better to have the import of "ar_select_order" just after the import of xarray? To have it once and for all?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right it is more common to have the imports at the beginning of the file. However, I will probably keep it here to avoid confusion because the name would be similar to select_ar_order. Tangentially relevant: #177

Just as a side remark - imports are cached in python so there is no time penalty to have it in a function as compared to the top.

@yquilcaille
Copy link
Collaborator

For information, the AR order for the global variability part can be changed, but an AR order > 1 will cause issues for the spatially correlated innovations. Equation (8) of https://doi.org/10.5194/esd-11-139-2020 would have to account for highest order, and I am not sure how one could do it.

mesmer/core/auto_regression.py Show resolved Hide resolved
Only full models can be selected.
"""

from statsmodels.tsa.ar_model import ar_select_order
Copy link
Member Author

Choose a reason for hiding this comment

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

You are right it is more common to have the imports at the beginning of the file. However, I will probably keep it here to avoid confusion because the name would be similar to select_ar_order. Tangentially relevant: #177

Just as a side remark - imports are cached in python so there is no time penalty to have it in a function as compared to the top.

Parameters
----------
data : array_like
A 1-d endogenous response variable. The independent variable.
Copy link
Member Author

Choose a reason for hiding this comment

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

To update

Parameters
----------
data : array_like
A 1-d endogenous response variable. The independent variable.
Copy link
Member Author

Choose a reason for hiding this comment

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

To update

Copy link
Member Author

@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.

Some last nits from my side, otherwise this is ready for review. @znicholls?

mesmer/calibrate_mesmer/train_gv.py Outdated Show resolved Hide resolved
mesmer/core/auto_regression.py Outdated Show resolved Hide resolved
Comment on lines +40 to +42
# remove zeros
selected_ar_order.data[selected_ar_order.data == 0] = np.NaN

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
# remove zeros
selected_ar_order.data[selected_ar_order.data == 0] = np.NaN

I think that does not actually happen.

mesmer/core/auto_regression.py Outdated Show resolved Hide resolved
tests/integration/test_auto_regression.py Outdated Show resolved Hide resolved
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.

lgtm!

@mathause mathause merged commit 199684f into MESMER-group:master Jul 12, 2022
@mathause mathause deleted the extract_select_ar_order branch July 12, 2022 06:14
@mathause
Copy link
Member Author

Thanks for the reviews!

@mathause mathause mentioned this pull request Sep 25, 2023
4 tasks
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.

auto regression: extract function to estimate the order
4 participants