Skip to content

Commit

Permalink
Adjust Python wrapper to year counting as start of year
Browse files Browse the repository at this point in the history
  • Loading branch information
rgieseke committed Jan 25, 2017
1 parent dfa030d commit 760da80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyhector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ def run(scenario, options=None):
global_temp = h.get_observable("temperature", "Tgav")
start = int(options["core"]["startDate"])
end = int(options["core"]["endDate"])
return pd.Series(global_temp, index=pd.Index(range(start, end + 1)))
return pd.Series(global_temp, index=pd.Index(range(start, end)))
8 changes: 5 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ def read_hector_output(csv_file):
Reads a Hector output stream csv and returns a wide DataFrame with
Hector output data.
"""
# Filter out spin-up values. RCP output streams seem to start at 1746
# though startDate ist 1745.
# Filter out spin-up values. In Hector 1.x RCP output streams years are
# written as end of simulation year. This will change in Hector 2.x.
# See https://github.com/JGCRI/hector/issues/177
start_year = 1746
output_stream = pd.read_csv(csv_file, skiprows=1)

wide = output_stream[output_stream.year >= start_year].pivot_table(
index="year", columns="variable", values="value")
wide.index = wide.index - 1 # Adjust index to year only

return wide

Expand All @@ -40,4 +42,4 @@ def test_rcps():
os.path.join(path, "./data/outputstream_{}.csv".format(name))
)
output = pyhector.run(scenario)
assert output.loc[1746:].round(2).equals(original.Tgav.round(2))
assert output.round(2).equals(original.Tgav.round(2))

0 comments on commit 760da80

Please sign in to comment.