Skip to content

Commit

Permalink
fit_harmonic_model: n_sel -> selected_order (#508)
Browse files Browse the repository at this point in the history
* fit_harmonic_model: n_sel -> order

* order -> selected_order
  • Loading branch information
mathause authored Aug 30, 2024
1 parent cc21584 commit ca88178
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions mesmer/stats/_harmonic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _fit_fourier_order_np(yearly_predictor, monthly_target, max_order):
-------
selected_order : Integer
Selected order of Fourier Series.
coeffs : array-like of size (4*n_sel,)
coeffs : array-like of size (4 * max_order,)
Fitted coefficients for the selected order of Fourier Series.
predictions : array-like of size (n_years*12,)
Predicted monthly values from final model.
Expand Down Expand Up @@ -247,9 +247,9 @@ def fit_harmonic_model(yearly_predictor, monthly_target, max_order=6, time_dim="
Returns
-------
data_vars : `xr.Dataset`
Dataset containing the selected order of Fourier Series (n_sel), the estimated
coefficients of the Fourier Series (coeffs) and the resulting predictions for
monthly values (predictions).
Dataset containing the selected order of Fourier Series (selected_order),
the estimated coefficients of the Fourier Series (coeffs) and the resulting
predictions for monthly values (predictions).
"""

Expand All @@ -269,7 +269,7 @@ def fit_harmonic_model(yearly_predictor, monthly_target, max_order=6, time_dim="
# subtract annual mean to have seasonal anomalies around 0
seasonal_deviations = monthly_target - yearly_predictor

n_sel, coeffs, preds = xr.apply_ufunc(
selected_order, coeffs, preds = xr.apply_ufunc(
_fit_fourier_order_np,
yearly_predictor,
seasonal_deviations,
Expand All @@ -283,7 +283,7 @@ def fit_harmonic_model(yearly_predictor, monthly_target, max_order=6, time_dim="
preds = yearly_predictor + preds

data_vars = {
"n_sel": n_sel,
"selected_order": selected_order,
"coeffs": coeffs,
"predictions": preds.transpose(time_dim, ...),
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_harmonic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_fit_harmonic_model():

# test if the model can recover the monthly target from perfect fourier series
result = mesmer.stats.fit_harmonic_model(yearly_predictor, monthly_target)
np.testing.assert_equal(result.n_sel.values, orders)
np.testing.assert_equal(result.selected_order.values, orders)
xr.testing.assert_allclose(result["predictions"], monthly_target)

# test if the model can recover the underlying cycle with noise on top of monthly target
Expand Down

0 comments on commit ca88178

Please sign in to comment.