Skip to content

Commit

Permalink
Merge pull request #529 from openeemeter/fix/linear_fit_bug
Browse files Browse the repository at this point in the history
fix linear fit bug
  • Loading branch information
travis-recurve authored Jan 7, 2025
2 parents e319e70 + 75e48bb commit e5cd92d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions eemeter/eemeter/models/daily/base_models/c_hdd_tidd.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def _c_hdd_tidd_x0(T, obs, alpha, settings, smooth):
idx_hdd = np.argwhere(T <= c_hdd_bp).flatten()
idx_cdd = np.argwhere(T >= c_hdd_bp).flatten()

hdd_beta, _ = linear_fit(obs[idx_hdd], T[idx_hdd], alpha)
hdd_beta, _ = linear_fit(T[idx_hdd], obs[idx_hdd], alpha)
if hdd_beta > 0:
hdd_beta = 0

cdd_beta, _ = linear_fit(obs[idx_cdd], T[idx_cdd], alpha)
cdd_beta, _ = linear_fit(T[idx_cdd], obs[idx_cdd], alpha)
if cdd_beta < 0:
cdd_beta = 0

Expand Down Expand Up @@ -347,11 +347,11 @@ def bp_obj_fcn(x, grad=[]):
idx_hdd = np.argwhere(T <= c_hdd_bp).flatten()
idx_cdd = np.argwhere(T >= c_hdd_bp).flatten()

hdd_beta, _ = linear_fit(obs[idx_hdd], T[idx_hdd], alpha)
hdd_beta, _ = linear_fit(T[idx_hdd], obs[idx_hdd], alpha)
if hdd_beta > 0:
hdd_beta = 0

cdd_beta, _ = linear_fit(obs[idx_cdd], T[idx_cdd], alpha)
cdd_beta, _ = linear_fit(T[idx_cdd], obs[idx_cdd], alpha)
if cdd_beta < 0:
cdd_beta = 0

Expand Down
2 changes: 1 addition & 1 deletion eemeter/eemeter/models/daily/utilities/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def linear_fit(x, y, alpha):
slope = res.slope
intercept = res.intercept
else:
slope, intercept, _, _ = theilslopes(x, y, alpha=0.95)
slope, intercept, _, _ = theilslopes(y, x, alpha=0.95)

return slope, intercept

Expand Down
4 changes: 2 additions & 2 deletions tests/daily_model/utilities/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_linear_fit():
y = np.array([2, 4, 6, 8, 10])
alpha = 0.95
slope, intercept = linear_fit(x, y, alpha)
res = theilslopes(x, y, alpha=0.95)
res = theilslopes(y, x, alpha=0.95)
assert slope == res[0]
assert intercept == res[1]

Expand All @@ -137,7 +137,7 @@ def test_linear_fit():
with pytest.raises(ValueError):
res = linregress(x, y)
assert slope == 0
assert intercept == 10
assert intercept == x[0]


def test_get_smooth_coeffs():
Expand Down

0 comments on commit e5cd92d

Please sign in to comment.