Skip to content

Commit

Permalink
Revert to Hector year reporting
Browse files Browse the repository at this point in the history
Hector 1.x reports years in outputs as end of simulation year.
1745-12-31 = 1746.0
See JGCRI/hector#177
  • Loading branch information
rgieseke committed Jan 27, 2017
1 parent 63fe7af commit fcfe7ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pyhector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def run(scenario, config_options=None):
h.add_observable("temperature", "Tgav")
h.run()
global_temp = h.get_observable("temperature", "Tgav")
start = int(parameters["core"]["startDate"])
end = int(parameters["core"]["endDate"])
return pd.Series(global_temp, index=np.arange(start, end))
# In Hector 1.x RCP output value years are given as end of simulation
# year, e.g. 1745-12-31 = 1746.0.
# See https://github.com/JGCRI/hector/issues/177
start = int(parameters["core"]["startDate"]) + 1
# End of range is non-inclusive in Python ranges.
end = int(parameters["core"]["endDate"]) + 1
index = np.arange(start, end)
return pd.Series(global_temp, index=index)
3 changes: 1 addition & 2 deletions tests/test_pyhector.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ def read_hector_output(csv_file):
Hector output data.
"""
# 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.
# given 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 Down

0 comments on commit fcfe7ab

Please sign in to comment.