コード例 #1
0
def test_constraint_forcing():
    forcing_csv = os.path.join(path, "data/MAGICC_RF_4.5.csv")
    forcing = read_hector_constraint(forcing_csv)
    output = pyhector.run(rcp45, {"forcing": {"Ftot_constrain": forcing}})
    assert_series_equal(
        output["forcing.Ftot"].loc[1765:2300], forcing.loc[1765:2300], check_names=False
    )
コード例 #2
0
def test_constraint_co2():
    lawdome_co2_csv = os.path.join(path, "data/lawdome_co2.csv")
    lawdome_co2 = read_hector_constraint(lawdome_co2_csv)
    output = pyhector.run(rcp45, {"simpleNbox": {"Ca_constrain": lawdome_co2}})
    # Simplifying the overlapping date-range (later CO2 values are yearly.)
    assert_series_equal(output["simpleNbox.Ca"].loc[1750:1960:5],
                        lawdome_co2.loc[1750:1960],
                        check_names=False)
コード例 #3
0
ファイル: test_pyhector.py プロジェクト: wk1984/pyhector
def test_constraint_forcing():
    forcing_csv = os.path.join(path, "data/MAGICC_RF_4.5.csv")
    forcing = read_hector_constraint(forcing_csv)
    output = pyhector.run(rcp45, {"temperature": {"tgav_constrain": forcing}})
    # Simplifying the overlapping date-range (later lawdome values are yearly.)
    assert_series_equal(output["temperature.Tgav"].loc[1765:2300],
                        forcing.loc[1765:2300],
                        check_names=False)
コード例 #4
0
ファイル: test_pyhector.py プロジェクト: wk1984/pyhector
def test_constraint_temperature():
    temperature_csv = os.path.join(path, "data/tgav_historical.csv")
    tgav = read_hector_constraint(temperature_csv)
    output = pyhector.run(rcp45, {"temperature": {"tgav_constrain": tgav}})
    # Simplifying the overlapping date-range (later lawdome values are yearly.)
    assert_series_equal(output["temperature.Tgav"].loc[1850:2013],
                        tgav.loc[1850:2013],
                        check_names=False)
コード例 #5
0
def test_rcps():
    # Compare output of Pyhector with original Hector output streams for RCPs.
    for name, scenario in rcps.items():
        original = read_hector_output(
            os.path.join(path, "./data/outputstream_{}.csv".format(name)))
        output = pyhector.run(scenario)
        assert_series_equal(output["temperature.Tgav"],
                            original.Tgav,
                            check_names=False)
コード例 #6
0
def hector_runner(params, comp_data, var):
    hector_output = pyhector.run(
        pyhector.rcp45, {
            "temperature": {
                "S": params[0]
            },
            "simpleNbox": {
                "beta": params[1]
            },
            "simpleNbox": {
                "q10_rh": params[2]
            }
        })
    hector_co2 = hector_output[var].loc[comp_data.index]
    return difference_quantifier(comp_data, hector_co2)
コード例 #7
0
ファイル: plot_example.py プロジェクト: shaheen19/pyhector
import os

import matplotlib.pyplot as plt
plt.style.use("ggplot")
plt.rcParams["figure.figsize"] = 10, 5
plt.rcParams["font.family"] = "serif"
plt.rcParams["font.size"] = 12

import pyhector
from pyhector import rcp26, rcp45, rcp60, rcp85

path = os.path.join(os.path.dirname(__file__), '../docs/example-plot.png')

for rcp in [rcp85, rcp60, rcp45, rcp26]:
    output = pyhector.run(rcp, {"core": {"endDate": 2100}})
    temp = output["temperature.Tgav"]
    temp = temp.loc[1850:] - temp.loc[1850:1900].mean()
    temp.plot(label=rcp.name.split("_")[0])
plt.title("Global mean temperature")
plt.ylabel("°C over pre-industrial (1850-1900 mean)")
plt.legend(loc="best")

plt.savefig(path, dpi=96)
コード例 #8
0
def test_use_base_config():
    results, params = pyhector.run(
        rcp26, base_config=pyhector._default_config, return_config=True
    )
    assert params == pyhector._default_config
コード例 #9
0
def test_output_variables_needs_date():
    # Some outputs require the "needs_date" flag to be set to True.
    needing_date = ["CH4.CH4", "N2O.N2O", "OH.TAU_OH", "ozone.O3"]
    results = pyhector.run(rcp26, outputs=needing_date)
    assert list(results.columns) == needing_date
コード例 #10
0
def test_output_variables():
    results = pyhector.run(rcp26)
    assert len(results.columns) == 3
    results = pyhector.run(rcp26, outputs="all")
    assert len(results.columns) == len(pyhector.output.keys())
コード例 #11
0
def test_default_options():
    assert pyhector._default_config["core"]["endDate"] == 2300
    pyhector.run(rcp26, {"core": {"endDate": 2100}})
    assert pyhector._default_config["core"]["endDate"] == 2300
コード例 #12
0
def test_year_changes():
    results = pyhector.run(rcp45, {"core": {"startDate": 1745}})
    # Output dates are reported as end of simulation year (1745-12-31 = 1746.0)
    assert results.index[0] == 1746
    results = pyhector.run(rcp45, {"core": {"endDate": 2250}})
    assert results.index[-1] == 2250
コード例 #13
0
import pyhector
from pyhector import rcp26, rcp45, rcp60, rcp85

# Input emissions
#print rcp26.head(5)

# Run rcp26 scenario and view default output
output = pyhector.run(rcp26)
#print output.head(5)

# Print out other outputs
output = pyhector.run(rcp26,
                      outputs=[
                          'temperature.Tgav', 'simpleNbox.Ca', 'forcing.Ftot',
                          'forcing.FCO2', 'ocean.Temp_HL'
                      ])
print output.head(5)

# Calculate mean forcing 1850-1950
#print output['forcing.Ftot'].loc[1850:1950].mean()

import matplotlib.pyplot as plt
#
# for rcp in [rcp26, rcp45, rcp60, rcp85]:
#     output = pyhector.run(rcp, {"core": {"endDate": 2100}})
#     temp = output["temperature.Tgav"]
#     # Adjust to 1850 - 1900 reference period
#     temp = temp.loc[1850:] - temp.loc[1850:1900].mean()
#     temp.plot(label=rcp.name.split("_")[0])
# plt.title("Global mean temperature")
# plt.ylabel("Degrees C over pre-industrial (1850-1900 mean)")