Skip to content

Commit

Permalink
Fix linting issues in methods.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neilgrant committed Jan 28, 2025
1 parent 8e5a53d commit 7e51f36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/aneris/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def default_method_choice(
# or under the absolute threshold
if (abs(row.dH) > 0.5) & (row.dH_abs < row.dH_abs_thresh):
# If dH is large, but dH_abs is small, this suggests
# The data being harmonised is a small ~near zero component
# The data being harmonised is a small ~near zero component
# (under 20% of the parent variable)
if row.dH < 0:
# If dH is negative (model data > historical data)
Expand All @@ -452,10 +452,10 @@ def default_method_choice(
else:
# If dH is positive (model data < historical data)
# Then we use the offset method, as the ratio method can substantially
# Increase the values and lead to strange pathways, e.g.
# Increase the values and lead to strange pathways, e.g.
# When the variable is small in historical data but growing rapidly (e.g. synfuels)
return offset_method

# If dH_abs is large, this suggests that the component being harmonised is not ~near zero
# In this context we can just rely on the ratio method throughout
elif abs(row.dH) < 0.5:
Expand Down
11 changes: 7 additions & 4 deletions tests/test_harmonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,19 @@ def test_harmonize_linear_interpolation():
@pytest.mark.ipopt
def test_harmonize_budget():
df = _df.copy()
df.columns = df.columns.astype(int)
hist = _hist.copy()
hist.columns = hist.columns.astype(int)

methods = _methods.copy()

h = harmonize.Harmonizer(df, hist)
methods["method"] = "budget"
res = h.harmonize(year="2015", overrides=methods["method"])
res = h.harmonize(year=2015, overrides=methods["method"])

# base year
obs = res["2015"]
exp = _hist["2015"]
obs = res[2015]
exp = hist[2015]
npt.assert_array_almost_equal(obs, exp)

# carbon budget conserved
Expand All @@ -295,5 +298,5 @@ def _carbon_budget(emissions):

npt.assert_array_almost_equal(
_carbon_budget(res),
_carbon_budget(df) - _carbon_budget(hist.loc[:, "2010":"2015"]),
_carbon_budget(df) - _carbon_budget(hist.loc[:, 2010:2015]),
)

0 comments on commit 7e51f36

Please sign in to comment.