def test_datapoints_bug_no_limit():
    columns = [
        "Year", "World", "OECD90", "Eastern Europe", "Asia (Sans Japan)",
        "Middle East and Africa", "Latin America"
    ]
    limit = pd.DataFrame(120.0, index=range(2014, 2061), columns=columns)
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': datadir.joinpath('ca_100.csv'),
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': datadir.joinpath('ca_300.csv'),
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='Average of All Custom Scenarios',
        total_adoption_limit=limit)
    result = ca.adoption_data_per_region()
    # scenario2 will be reduced to 120, (100 + 120) / 2 = 110
    assert result.loc[2040, 'World'] == pytest.approx(110)
    assert result.loc[2050, 'World'] == pytest.approx(110)
    assert result.loc[2060, 'World'] == pytest.approx(110)
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': datadir.joinpath('ca_100.csv'),
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': datadir.joinpath('ca_300.csv'),
            'include': True,
            'bug_no_limit': True
        },
    ]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='Average of All Custom Scenarios',
        total_adoption_limit=limit)
    result = ca.adoption_data_per_region()
    # scenario2 will not be limited, (100 + 300) / 2 = 200 which is then limited to 200.
    assert result.loc[2040, 'World'] == pytest.approx(120)
    assert result.loc[2050, 'World'] == pytest.approx(120)
    assert result.loc[2060, 'World'] == pytest.approx(120)
def test_avg_high_low_with_limit_per_source():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': datadir.joinpath('ca_100.csv'),
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': datadir.joinpath('ca_300.csv'),
            'include': True
        },
    ]
    limit = pd.read_csv(datadir.joinpath('ca_200.csv'), index_col=0)
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='',
                                       low_sd_mult=0.1,
                                       high_sd_mult=0.1,
                                       total_adoption_limit=limit)
    avg, high, low = ca._avg_high_low()
    # if the limit is not applied to each individual source before averaging, then the average
    # of 100.0 and 300.0 will be 200.0. Applying a limit of 200.0 to the computed average will
    # not change anything.
    # After applying the limit of 200.0 to ca_300.csv, the average of 100.0 and 200.0
    # will be 150.0.
    assert ((avg == 150.0).all().all())
    assert ((high == 155.0).all().all())
    assert ((low == 145.0).all().all())
def test_avg_high_low_with_limit():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': path1,
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': path2,
            'include': True
        },
    ]
    limit = pd.read_csv(datadir.joinpath('ca_limit_trr.csv'), index_col=0)
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='',
                                       low_sd_mult=1.0,
                                       high_sd_mult=1.5,
                                       total_adoption_limit=limit)
    high_scen = pd.read_csv(datadir.joinpath('ca_highx1p5_trr.csv'),
                            index_col=0)
    _, highs, _ = ca._avg_high_low()
    pd.testing.assert_frame_equal(highs.loc[:2026, :],
                                  high_scen.loc[:2026, :],
                                  check_exact=False,
                                  check_dtype=False)
    pd.testing.assert_frame_equal(highs.loc[2027:, :],
                                  limit.loc[2027:, :],
                                  check_dtype=False)
Ejemplo n.º 4
0
def test_growth():
    growth_initial = pd.DataFrame(
        [[2018, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0]],
        columns=[
            'Year', 'World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
            'Middle East and Africa', 'Latin America', 'USA', 'EU', 'India',
            'China'
        ]).set_index('Year')
    data_sources = [{
        'name': 'growth scenario',
        'growth_rate': 0.1,
        'growth_initial': growth_initial,
        'include': True
    }]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources, soln_adoption_custom_name='growth scenario')
    result = ca.scenarios['growth scenario']['df']
    # expected values generated by modifying an Excel Custom PDS Adoption scenario to have a
    # 10% growth rate and initial values in the dataframe above. As Excel only handles the
    # World region for growth computations, we iteratively set the World to each value above.
    assert result.loc[2012, 'World'] == 1.0
    assert result.loc[2015, 'World'] == 1.0
    assert result.loc[2018, 'World'] == 1.0
    assert result.loc[2030, 'World'] == pytest.approx(12.2172551998265)
    assert result.loc[2040, 'World'] == pytest.approx(21.5649678663485)
    assert result.loc[2050, 'World'] == pytest.approx(30.9126805328706)
    assert result.loc[2060, 'World'] == pytest.approx(40.2603931993926)
    assert result.loc[2060, 'OECD90'] == pytest.approx(80.5207863987853)
    assert result.loc[2060,
                      'Eastern Europe'] == pytest.approx(120.781179598178)
    assert result.loc[2060,
                      'Asia (Sans Japan)'] == pytest.approx(161.041572797571)
    assert result.loc[2060, 'Middle East and Africa'] == pytest.approx(
        201.301965996963)
    assert result.loc[2060, 'Latin America'] == pytest.approx(241.562359196356)
def test_start_year_in_range():
    datapoints = pd.DataFrame(
        [[1990, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2010, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2020, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2030, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2040, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2050, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2060, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
         [2070, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]],
        columns=[
            'Year', 'World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
            'Middle East and Africa', 'Latin America', 'USA', 'EU', 'India',
            'China'
        ]).set_index('Year')
    data_sources = [{
        'name': 'implied world',
        'datapoints': datapoints,
        'include': True
    }]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources, soln_adoption_custom_name='implied world')
    result = ca.scenarios['implied world']['df']
    assert result.first_valid_index() == 2012
    assert result.last_valid_index() == 2060
Ejemplo n.º 6
0
def test_adjust_main_regions():
    df = pd.read_csv(datadir.joinpath('af_high_ca_no_limits.csv'), index_col=0)
    ca = customadoption.CustomAdoption(data_sources=[],
                                       soln_adoption_custom_name='')
    ca._adjust_main_regions(df)
    diff = df.loc[:, MAIN_REGIONS].sum(axis=1) - df.loc[:, 'World']
    assert diff.sum() == pytest.approx(0)
def test_avg_high_low_different_multipliers():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': path1,
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': path2,
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='',
                                       low_sd_mult=0.5,
                                       high_sd_mult=1.5)
    high_scen = pd.read_csv(datadir.joinpath('ca_highx1p5_trr.csv'),
                            index_col=0)
    low_scen = pd.read_csv(datadir.joinpath('ca_lowx0p5_trr.csv'), index_col=0)
    _, highs, lows = ca._avg_high_low()
    pd.testing.assert_frame_equal(highs,
                                  high_scen,
                                  check_exact=False,
                                  check_dtype=False)
    pd.testing.assert_frame_equal(lows,
                                  low_scen,
                                  check_exact=False,
                                  check_dtype=False)
def test_datapoints_maximum():
    datapoints = pd.DataFrame([[2020, 20.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2050, 50.0, 0.0, 0.0, 0.0, 0.0, 0.0]],
                              columns=[
                                  "Year", "World", "OECD90", "Eastern Europe",
                                  "Asia (Sans Japan)",
                                  "Middle East and Africa", "Latin America"
                              ]).set_index("Year")
    data_sources = [
        {
            'name': 'datapoints scenario',
            'datapoints': datapoints,
            'include': True,
            'maximum': 33.5
        },
    ]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='datapoints scenario')
    result = ca.scenarios['datapoints scenario']['df']
    assert result.loc[2020, 'World'] == pytest.approx(20)
    assert result.loc[2030, 'World'] == pytest.approx(30)
    assert result.loc[2031, 'World'] == pytest.approx(31)
    assert result.loc[2032, 'World'] == pytest.approx(32)
    assert result.loc[2033, 'World'] == pytest.approx(33)
    assert result.loc[2034, 'World'] == pytest.approx(33.5)
    assert result.loc[2035, 'World'] == pytest.approx(33.5)
    assert result.loc[2040, 'World'] == pytest.approx(33.5)
    assert result.loc[2050, 'World'] == pytest.approx(33.5)
    assert result.loc[2060, 'World'] == pytest.approx(33.5)
def test_avg_high_low_multiple_scenarios():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': path1,
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': path2,
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='')
    avg_scen = pd.read_csv(datadir.joinpath('ca_avg_trr.csv'), index_col=0)
    low_scen = pd.read_csv(datadir.joinpath('ca_low_trr.csv'), index_col=0)
    avgs, _, lows = ca._avg_high_low()
    pd.testing.assert_frame_equal(avgs,
                                  avg_scen,
                                  check_exact=False,
                                  check_dtype=False)
    pd.testing.assert_frame_equal(lows,
                                  low_scen,
                                  check_exact=False,
                                  check_dtype=False)
def test_bad_CSV_file():
    path1 = str(datadir.joinpath('ca_scenario_no_world_trr.csv'))
    data_sources = [
        {
            'name': 'scenario no world',
            'filename': path1,
            'include': True
        },
    ]
    with pytest.raises(AssertionError):  # test validation
        ca = customadoption.CustomAdoption(data_sources=data_sources,
                                           soln_adoption_custom_name='')
def test_adoption_data_per_region():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': path1,
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': path2,
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='Average of All Custom PDS Scenarios')
    expected = pd.read_csv(datadir.joinpath('ca_avg_trr.csv'), index_col=0)
    expected.name = 'adoption_data_per_region'
    result = ca.adoption_data_per_region()
    pd.testing.assert_frame_equal(result, expected, check_exact=False)

    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='Low of All Custom PDS Scenarios')
    expected = pd.read_csv(datadir.joinpath('ca_low_trr.csv'), index_col=0)
    expected.name = 'adoption_data_per_region'
    result = ca.adoption_data_per_region()
    pd.testing.assert_frame_equal(result, expected, check_exact=False)

    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='scenario 2')
    expected = pd.read_csv(path2, index_col=0)
    expected.name = 'adoption_data_per_region'
    expected.index = expected.index.astype(int)
    result = ca.adoption_data_per_region()
    pd.testing.assert_frame_equal(result, expected, check_exact=False)
def test_data_basis_algorithmic():
    datapoints = pd.DataFrame([[2020, 20.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2021, 21.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2022, 22.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2023, 23.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2024, 24.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2025, 25.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2026, 26.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2027, 27.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2028, 28.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2029, 29.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2030, 30.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2031, 31.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2032, 32.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2033, 33.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2034, 34.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2035, 35.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2036, 36.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2037, 37.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2038, 38.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2039, 39.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2040, 40.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2041, 41.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2042, 42.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2043, 43.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2044, 44.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2045, 45.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2046, 46.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2047, 47.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2048, 48.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2049, 49.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2050, 50.0, 0.0, 0.0, 0.0, 0.0, 0.0]],
                              columns=[
                                  "Year", "World", "OECD90", "Eastern Europe",
                                  "Asia (Sans Japan)",
                                  "Middle East and Africa", "Latin America"
                              ]).set_index("Year")
    data_sources = [{
        'name': 'algorithmic scenario',
        'datapoints': datapoints,
        'include': True
    }]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='algorithmic scenario')
    assert ca.scenarios['algorithmic scenario']['data_basis'] == [
        'algorithmic'
    ]
Ejemplo n.º 13
0
def test_scenarios():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': path1,
            'include': True
        },
        {
            'name': 'scenario 2',
            'filename': path2,
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='')
    assert len(ca.scenarios) == 2
def test_adoption_data_with_NaN():
    path_to_nan = str(datadir.joinpath('ca_scenario_with_NaN.csv'))
    data_sources = [
        {
            'name': 'scenario with nan',
            'filename': path_to_nan,
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='scenario with nan')
    avgs, _, _ = ca._avg_high_low()
    assert not pd.isna(avgs.loc[2030, 'World'])
    assert pd.isna(avgs.loc[2012, 'World'])
    assert pd.isna(avgs.loc[2030, 'OECD90'])
def test_datapoints_datapoints_degree_3():
    # Taken from Drawdown_RRS-BIOSEQAgri_Model_v1.1b_Conservation_Agriculture_28Feb2020.xlsm
    data_sources = [{
        'name':
        'degree3',
        'include':
        True,
        'datapoints_degree':
        3,
        'datapoints':
        pd.DataFrame([
            [
                2018, 108.9261700401280, 43.7005755429800, 9.0409602615725,
                8.9347309927289, 1.1134178930081, 46.1364853498384
            ],
            [
                2030, 376.2654577367930, 32.8311338312219, 104.3539285279180,
                158.0238892381100, 32.9622589705103, 48.0942471690326
            ],
            [
                2050, 282.1990933025950, 24.6233503734164, 78.2654463959384,
                118.5179169285820, 24.7216942278827, 36.0706853767745
            ],
            [
                2080, 163.3892550601920, 65.5508633144700, 13.5614403923587,
                13.4020964890934, 1.6701268395122, 69.2047280247576
            ],
        ],
                     columns=[
                         "Year", "World", "OECD90", "Eastern Europe",
                         "Asia (Sans Japan)", "Middle East and Africa",
                         "Latin America"
                     ]).set_index("Year")
    }]
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='degree3')
    result = ca.scenarios['degree3']['df']
    # expected from Drawdown_RRS-BIOSEQAgri_Model_v1.1b_Conservation_Agriculture_28Feb2020.xlsm
    # 'Custom PDS Adoption' scenario 7 "Likely max CA based on Prestele BottomUp Map, polynominal"
    assert result.loc[2025, 'World'] == pytest.approx(306.494563043118)
    assert result.loc[2030,
                      'Eastern Europe'] == pytest.approx(104.353928521276000)
    assert result.loc[2035,
                      'Latin America'] == pytest.approx(45.687040837481600)
    assert result.loc[2045, 'Asia (Sans Japan)'] == pytest.approx(
        148.444525264204000)
    assert result.loc[2055, 'World'] == pytest.approx(217.292268067598000)
def test_report():
    data_sources = []
    for i in range(1, 3):
        name = f'af_ca{i}'
        data_sources.append({
            'name': name,
            'filename': datadir.joinpath(name + '.csv'),
            'include': True
        })
    lims = pd.read_csv(datadir.joinpath('af_tla.csv'), index_col=0)
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='',
                                       total_adoption_limit=lims)
    report, data = ca.report()
    print(report.iloc[1, :].values)
    assert list(report.iloc[0, :].values) == [True, True, True, False]
    assert list(report.iloc[1, :].values) == [False, False, np.nan, np.nan]
def test_datapoints_no_negative():
    datapoints = pd.DataFrame([[2020, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               [2021, 100.0, 0.0, 0.0, 0.0, 0.0, 0.0]],
                              columns=[
                                  "Year", "World", "OECD90", "Eastern Europe",
                                  "Asia (Sans Japan)",
                                  "Middle East and Africa", "Latin America"
                              ]).set_index("Year")
    data_sources = [{
        'name': 'datapoints scenario',
        'datapoints': datapoints,
        'include': True
    }]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='datapoints scenario')
    result = ca.scenarios['datapoints scenario']['df']
    assert result.loc[2015,
                      'World'] == pytest.approx(0.0)  # i.e. not negative.
def test_datapoints_with_implied_main_region():
    datapoints = pd.DataFrame(
        [[2020, np.nan, 10.0, 10.0, 10.0, 10.0, 10.0, 1.0, 3.0, 5.0, 7.0],
         [2050, np.nan, 10.0, 10.0, 10.0, 10.0, 10.0, 1.0, 3.0, 5.0, 7.0]],
        columns=[
            'Year', 'World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
            'Middle East and Africa', 'Latin America', 'USA', 'EU', 'India',
            'China'
        ]).set_index('Year')
    data_sources = [{
        'name': 'implied world',
        'datapoints': datapoints,
        'include': True
    }]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources, soln_adoption_custom_name='implied world')
    result = ca.scenarios['implied world']['df']
    assert result.loc[2025, 'World'] == 50.0
    assert result.loc[2035, 'World'] == 50.0
def test_avg_high_low_one_scenario():
    data_sources = [
        {
            'name': 'scenario 1',
            'filename': path1,
            'include': True
        },
    ]
    ca = customadoption.CustomAdoption(data_sources=data_sources,
                                       soln_adoption_custom_name='')
    scen_1 = pd.read_csv(path1, index_col=0)
    avgs, _, lows = ca._avg_high_low()
    pd.testing.assert_frame_equal(avgs,
                                  scen_1,
                                  check_exact=False,
                                  check_dtype=False)
    pd.testing.assert_frame_equal(lows,
                                  scen_1,
                                  check_exact=False,
                                  check_dtype=False)
def test_datapoints_datapoints_degree_1():
    # Taken from Drawdown_RRS-BIOSEQ_Model_v1.1_MASTER_Afforestation-Jan2020.xlsm
    data_sources = [{
        'name':
        'Regional linear trend',
        'include':
        True,
        'datapoints_degree':
        1,
        'datapoints':
        pd.DataFrame([
            [1990, np.nan, 96.8914, 44.1631, 106.1562, 16.5338, 14.9281],
            [2000, np.nan, 97.2555, 44.2605, 107.5489, 16.7251, 15.2771],
            [2005, np.nan, 97.6355, 44.3794, 109.8028, 16.9607, 15.6649],
            [2010, np.nan, 97.8700, 44.4540, 111.5210, 17.1760, 16.0730],
            [
                2014, np.nan, 98.1783330003811, 44.5558196042818,
                113.7890763825080, 17.4259450169749, 16.5131623025461
            ],
        ],
                     columns=[
                         "Year", "World", "OECD90", "Eastern Europe",
                         "Asia (Sans Japan)", "Middle East and Africa",
                         "Latin America"
                     ]).set_index("Year")
    }]
    ca = customadoption.CustomAdoption(
        data_sources=data_sources,
        soln_adoption_custom_name='Regional linear trend')
    assert ca.scenarios['Regional linear trend']['data_basis'] == ['polyfit']
    result = ca.scenarios['Regional linear trend']['df']
    # expected values also from Drawdown_RRS-BIOSEQ_Model_v1.1_MASTER_Afforestation-Jan2020.xlsm
    # 'Custom PDS Adoption' in the first scenario 'Regional linear trend'
    assert result.loc[2040, 'OECD90'] == pytest.approx(99.5072653875209)
    assert result.loc[2050,
                      'Eastern Europe'] == pytest.approx(45.1173882050357)
    assert result.loc[2055, 'World'] == pytest.approx(309.3451120801650)
Ejemplo n.º 21
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TAM
        tamconfig_list = [
            [
                'param', 'World', 'PDS World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'source_until_2014', self.ac.source_until_2014,
                self.ac.source_until_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'source_after_2014', self.ac.ref_source_post_2014,
                self.ac.pds_source_post_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'trend', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly'
            ],
            [
                'growth', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'
            ],
            [
                'low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ],
            [
                'high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ]
        ]
        tamconfig = pd.DataFrame(tamconfig_list[1:],
                                 columns=tamconfig_list[0],
                                 dtype=np.object).set_index('param')
        tam_ref_data_sources = {
            'Baseline Cases': {
                'Based on: CES ITU AMPERE Baseline':
                THISDIR.joinpath('tam',
                                 'tam_based_on_CES_ITU_AMPERE_Baseline.csv'),
                'Based on: CES ITU AMPERE 550':
                THISDIR.joinpath('tam', 'tam_based_on_CES_ITU_AMPERE_550.csv'),
                'Based on: CES ITU AMPERE 450':
                THISDIR.joinpath('tam', 'tam_based_on_CES_ITU_AMPERE_450.csv'),
            },
        }
        self.tm = tam.TAM(tamconfig=tamconfig,
                          tam_ref_data_sources=tam_ref_data_sources,
                          tam_pds_data_sources=tam_ref_data_sources)
        ref_tam_per_region = self.tm.ref_tam_per_region()
        pds_tam_per_region = self.tm.pds_tam_per_region()

        adconfig_list = [
            [
                'param', 'World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'trend', self.ac.soln_pds_adoption_prognostication_trend,
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly'
            ],
            [
                'growth', self.ac.soln_pds_adoption_prognostication_growth,
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium'
            ],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        ]
        adconfig = pd.DataFrame(adconfig_list[1:],
                                columns=adconfig_list[0],
                                dtype=np.object).set_index('param')
        ad_data_sources = {}
        self.ad = adoptiondata.AdoptionData(ac=self.ac,
                                            data_sources=ad_data_sources,
                                            adconfig=adconfig)

        # Custom PDS Data
        ca_pds_data_sources = [
            {
                'name':
                'Aggressive, Low',
                'include':
                True,
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Aggressive_Low.csv')
            },
            {
                'name':
                'Conservative, Low',
                'include':
                True,
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Conservative_Low.csv')
            },
            {
                'name':
                'Aggressive, high',
                'include':
                True,
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Aggressive_high.csv')
            },
            {
                'name':
                'Aggressive, high, early',
                'include':
                True,
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Aggressive_high_early.csv')
            },
            {
                'name':
                'Drawdown Book Ed.1 Scenario 1',
                'include':
                False,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Drawdown_Book_Ed_1_Scenario_1.csv')
            },
            {
                'name':
                'Drawdown Book Ed.1 Scenario 2',
                'include':
                False,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Drawdown_Book_Ed_1_Scenario_2.csv')
            },
            {
                'name':
                'Drawdown Book Ed.1 Scenario 3',
                'include':
                False,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Drawdown_Book_Ed_1_Scenario_3.csv')
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=pds_tam_per_region)

        ref_adoption_data_per_region = None

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None
        elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
            pds_adoption_data_per_region = self.ad.adoption_data_per_region()
            pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
            pds_adoption_is_single_source = self.ad.adoption_is_single_source()

        ht_ref_adoption_initial = pd.Series(
            [3.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7, 2.5],
            index=dd.REGIONS)
        ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (
            ht_ref_adoption_initial / ref_tam_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2014] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_regions, ht_percentages = zip(
            *self.ac.pds_adoption_final_percentage)
        ht_pds_adoption_final_percentage = pd.Series(list(ht_percentages),
                                                     index=list(ht_regions))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2014] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=ref_tam_per_region,
            pds_adoption_limits=pds_tam_per_region,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=ref_tam_per_region,
            pds_total_adoption_units=pds_tam_per_region,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            bug_cfunits_double_count=True)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            fc_convert_iunit_factor=1000000.0)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=1.0)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            soln_pds_direct_co2_emissions_saved(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            soln_pds_direct_ch4_co2_emissions_saved(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            soln_pds_direct_n2o_co2_emissions_saved(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            fuel_in_liters=False)

        self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014,
                                                                      'World'],
                           soln_avg_annual_use=self.ac.soln_avg_annual_use,
                           conv_avg_annual_use=self.ac.conv_avg_annual_use)
Ejemplo n.º 22
0
  def __init__(self, scenario=None):
    if scenario is None:
      scenario = list(scenarios.keys())[0]
    self.scenario = scenario
    self.ac = scenarios[scenario]

    # TAM
    tamconfig_list = [
      ['param', 'World', 'PDS World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
       'Middle East and Africa', 'Latin America', 'China', 'India', 'EU', 'USA'],
      ['source_until_2014', self.ac.source_until_2014, self.ac.source_until_2014,
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'],
      ['source_after_2014', self.ac.ref_source_post_2014, self.ac.pds_source_post_2014,
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'],
      ['trend', '3rd Poly', '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly'],
      ['growth', 'Medium', 'Medium', 'Medium', 'Medium',
       'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'],
      ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
      ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
    tamconfig = pd.DataFrame(tamconfig_list[1:], columns=tamconfig_list[0], dtype=np.object).set_index('param')
    tam_ref_data_sources = {
      'Baseline Cases': {
          'Custom calculated from (GBPN, Urge-Vorsatz Factored by IEA Building  Data)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_UrgeVorsatz_Factored_by_IEA_Building_Data.csv'),
          'IEA 6DS (2016), Residential & Commercial Water Heating': THISDIR.joinpath('tam', 'tam_IEA_6DS_2016_Residential_Commercial_Water_Heating.csv'),
          'GBPN Energy for water heating, Urban & Rural / All buildings, All Vintages, Frozen efficiency (Water Heating Thermal energy use in TWHth)': THISDIR.joinpath('tam', 'tam_GBPN_Energy_for_water_heating_Urban_Rural_All_buildings_All_Vintages_Frozen_efficiency_W_e86b69eb.csv'),
      },
      'Conservative Cases': {
          'Custom calculated from (GBPN and Urge-Vorsatz)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_and_UrgeVorsatz.csv'),
          'IEA 4DS (2016), Residential & Commercial Water Heating': THISDIR.joinpath('tam', 'tam_IEA_4DS_2016_Residential_Commercial_Water_Heating.csv'),
      },
      'Region: OECD90': {
        'Baseline Cases': {
          'Custom calculated from (GBPN, Urge-Vorsatz Factored by IEA Building  Data)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_UrgeVorsatz_Factored_by_IEA_Building_Data.csv'),
          'Custom calculated from (GBPN and Urge-Vorsatz)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_and_UrgeVorsatz.csv'),
          'GBPN Energy for water heating, Urban & Rural / All buildings, All Vintages, Frozen efficiency (Water Heating Thermal energy use in TWHth)': THISDIR.joinpath('tam', 'tam_GBPN_Energy_for_water_heating_Urban_Rural_All_buildings_All_Vintages_Frozen_efficiency_W_e86b69eb.csv'),
        },
      },
      'Region: Eastern Europe': {
        'Baseline Cases': {
          'Custom calculated from (GBPN, Urge-Vorsatz Factored by IEA Building  Data)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_UrgeVorsatz_Factored_by_IEA_Building_Data.csv'),
          'Custom calculated from (GBPN and Urge-Vorsatz)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_and_UrgeVorsatz.csv'),
          'GBPN Energy for water heating, Urban & Rural / All buildings, All Vintages, Frozen efficiency (Water Heating Thermal energy use in TWHth)': THISDIR.joinpath('tam', 'tam_GBPN_Energy_for_water_heating_Urban_Rural_All_buildings_All_Vintages_Frozen_efficiency_W_e86b69eb.csv'),
        },
      },
      'Region: Asia (Sans Japan)': {
        'Baseline Cases': {
          'Custom calculated from (GBPN, Urge-Vorsatz Factored by IEA Building  Data)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_UrgeVorsatz_Factored_by_IEA_Building_Data.csv'),
          'Custom calculated from (GBPN and Urge-Vorsatz)': THISDIR.joinpath('tam', 'tam_Custom_calculated_from_GBPN_and_UrgeVorsatz.csv'),
          'GBPN Energy for water heating, Urban & Rural / All buildings, All Vintages, Frozen efficiency (Water Heating Thermal energy use in TWHth)': THISDIR.joinpath('tam', 'tam_GBPN_Energy_for_water_heating_Urban_Rural_All_buildings_All_Vintages_Frozen_efficiency_W_e86b69eb.csv'),
        },
      },
    }
    tam_pds_data_sources = {
      'Baseline Cases': {
          'Drawdown TAM: PDS1 - post-Low-Flow': THISDIR.joinpath('tam', 'tam_pds_Drawdown_TAM_PDS1_postLowFlow.csv'),
      },
      'Conservative Cases': {
          'Drawdown TAM: PDS2 - post-Low-Flow': THISDIR.joinpath('tam', 'tam_pds_Drawdown_TAM_PDS2_postLowFlow.csv'),
      },
      'Ambitious Cases': {
          'Drawdown TAM: PDS3 - post-Low-Flow': THISDIR.joinpath('tam', 'tam_pds_Drawdown_TAM_PDS3_postLowFlow.csv'),
      },
    }
    self.tm = tam.TAM(tamconfig=tamconfig, tam_ref_data_sources=tam_ref_data_sources,
      tam_pds_data_sources=tam_pds_data_sources)
    ref_tam_per_region=self.tm.ref_tam_per_region()
    pds_tam_per_region=self.tm.pds_tam_per_region()

    adconfig_list = [
      ['param', 'World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
       'Middle East and Africa', 'Latin America', 'China', 'India', 'EU', 'USA'],
      ['trend', self.ac.soln_pds_adoption_prognostication_trend, '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly'],
      ['growth', self.ac.soln_pds_adoption_prognostication_growth, 'Medium',
       'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
       'Medium', 'Medium', 'Medium'],
      ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
      ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
    adconfig = pd.DataFrame(adconfig_list[1:], columns=adconfig_list[0], dtype=np.object).set_index('param')
    ad_data_sources = {
      'Conservative Cases': {
          'IEA (2012) Technology Roadmap Solar Heating and Cooling - Cons': THISDIR.joinpath('ad', 'ad_IEA_2012_Technology_Roadmap_Solar_Heating_and_Cooling_Cons.csv'),
      },
      'Ambitious Cases': {
          'Solar Heat Worldwide http://www.iea-shc.org/solar-heat-worldwide': THISDIR.joinpath('ad', 'ad_Solar_Heat_Worldwide_httpwww_ieashc_orgsolarheatworldwide.csv'),
      },
    }
    self.ad = adoptiondata.AdoptionData(ac=self.ac, data_sources=ad_data_sources,
        adconfig=adconfig)

    # Custom PDS Data
    ca_pds_data_sources = [
      {'name': 'Conservative, based on IEA 2012', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Conservative_based_on_IEA_2012.csv')},
      {'name': 'Aggressive, High Growth, early', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Aggressive_High_Growth_early.csv')},
      {'name': 'Aggressive, High Growth, based on IEA', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Aggressive_High_Growth_based_on_IEA.csv')},
      {'name': 'Aggressive, High Growth, late', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Aggressive_High_Growth_late.csv')},
      {'name': 'Aggressive, V. High Growth, late', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Aggressive_V__High_Growth_late.csv')},
      {'name': 'Aggressive, V. High Growth', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Aggressive_V__High_Growth.csv')},
      {'name': 'Conservative Growth, late', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Conservative_Growth_late.csv')},
      {'name': 'Conservative Growth, early', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Conservative_Growth_early.csv')},
      {'name': 'Low Growth', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Low_Growth.csv')},
    ]
    self.pds_ca = customadoption.CustomAdoption(data_sources=ca_pds_data_sources,
        soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
        high_sd_mult=1.0, low_sd_mult=1.0,
        total_adoption_limit=pds_tam_per_region)

    ref_adoption_data_per_region = None

    if False:
      # One may wonder why this is here. This file was code generated.
      # This 'if False' allows subsequent conditions to all be elif.
      pass
    elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
      pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region()
      pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region()
      pds_adoption_is_single_source = None
    elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
      pds_adoption_data_per_region = self.ad.adoption_data_per_region()
      pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
      pds_adoption_is_single_source = self.ad.adoption_is_single_source()

    ht_ref_adoption_initial = pd.Series(
      [335.463, 56.493, 2.374, 240.305, 9.948,
       9.113, 231.838, 6.4350000000000005, 23.777, 17.233],
       index=dd.REGIONS)
    ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (ht_ref_adoption_initial / ref_tam_per_region.loc[2014])
    ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
    ht_ref_datapoints.loc[2014] = ht_ref_adoption_initial
    ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
    ht_pds_adoption_initial = ht_ref_adoption_initial
    ht_regions, ht_percentages = zip(*self.ac.pds_adoption_final_percentage)
    ht_pds_adoption_final_percentage = pd.Series(list(ht_percentages), index=list(ht_regions))
    ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[2050]
    ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
    ht_pds_datapoints.loc[2014] = ht_pds_adoption_initial
    ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
    self.ht = helpertables.HelperTables(ac=self.ac,
        ref_datapoints=ht_ref_datapoints, pds_datapoints=ht_pds_datapoints,
        pds_adoption_data_per_region=pds_adoption_data_per_region,
        ref_adoption_limits=ref_tam_per_region, pds_adoption_limits=pds_tam_per_region,
        pds_adoption_trend_per_region=pds_adoption_trend_per_region,
        pds_adoption_is_single_source=pds_adoption_is_single_source)

    self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

    self.ua = unitadoption.UnitAdoption(ac=self.ac,
        ref_total_adoption_units=ref_tam_per_region, pds_total_adoption_units=pds_tam_per_region,
        soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
        soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
        repeated_cost_for_iunits=False,
        bug_cfunits_double_count=False)
    soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
    soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
    conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
    soln_net_annual_funits_adopted=self.ua.soln_net_annual_funits_adopted()

    self.fc = firstcost.FirstCost(ac=self.ac, pds_learning_increase_mult=2,
        ref_learning_increase_mult=2, conv_learning_increase_mult=2,
        soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
        soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
        conv_ref_tot_iunits=conv_ref_tot_iunits,
        soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
        soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
        conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
        fc_convert_iunit_factor=1000000000.0)

    self.oc = operatingcost.OperatingCost(ac=self.ac,
        soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
        soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
        soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
        conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
        soln_pds_annual_world_first_cost=self.fc.soln_pds_annual_world_first_cost(),
        soln_ref_annual_world_first_cost=self.fc.soln_ref_annual_world_first_cost(),
        conv_ref_annual_world_first_cost=self.fc.conv_ref_annual_world_first_cost(),
        single_iunit_purchase_year=2017,
        soln_pds_install_cost_per_iunit=self.fc.soln_pds_install_cost_per_iunit(),
        conv_ref_install_cost_per_iunit=self.fc.conv_ref_install_cost_per_iunit(),
        conversion_factor=1000000000.0)

    self.c4 = ch4calcs.CH4Calcs(ac=self.ac,
        soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

    self.c2 = co2calcs.CO2Calcs(ac=self.ac,
        ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
        soln_pds_net_grid_electricity_units_saved=self.ua.soln_pds_net_grid_electricity_units_saved(),
        soln_pds_net_grid_electricity_units_used=self.ua.soln_pds_net_grid_electricity_units_used(),
        soln_pds_direct_co2_emissions_saved=self.ua.soln_pds_direct_co2_emissions_saved(),
        soln_pds_direct_ch4_co2_emissions_saved=self.ua.soln_pds_direct_ch4_co2_emissions_saved(),
        soln_pds_direct_n2o_co2_emissions_saved=self.ua.soln_pds_direct_n2o_co2_emissions_saved(),
        soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
        soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
        conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
        conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
        conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
        soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
        fuel_in_liters=False)

    self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014, 'World'],
        soln_avg_annual_use=self.ac.soln_avg_annual_use,
        conv_avg_annual_use=self.ac.conv_avg_annual_use)
Ejemplo n.º 23
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TLA
        self.ae = aez.AEZ(solution_name=self.name)
        self.tla_per_region = tla.tla_per_region(
            self.ae.get_land_distribution())

        # Custom PDS Data
        ca_pds_data_sources = [
            {
                'name':
                'Conservative-Low, Linear Trend',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_ConservativeLow_Linear_Trend.csv')
            },
            {
                'name':
                'Conservative-Medium, Linear Trend',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_ConservativeMedium_Linear_Trend.csv')
            },
            {
                'name':
                'High-linear trend',
                'include':
                True,
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Highlinear_trend.csv')
            },
            {
                'name':
                'High-high early growth, linear trend',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Highhigh_early_growth_linear_trend.csv')
            },
            {
                'name':
                'High, very high early growth, linear trend',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_High_very_high_early_growth_linear_trend.csv'
                )
            },
            {
                'name':
                'Max, high early growth, linear trend',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Max_high_early_growth_linear_trend.csv')
            },
            {
                'name':
                'Aggressive Max, urgent adoption',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Aggressive_Max_urgent_adoption.csv')
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=self.tla_per_region)

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None

        ht_ref_adoption_initial = pd.Series(
            [3.27713, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            index=dd.REGIONS)
        ht_ref_adoption_final = self.tla_per_region.loc[2050] * (
            ht_ref_adoption_initial / self.tla_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2014] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_regions, ht_percentages = zip(
            *self.ac.pds_adoption_final_percentage)
        ht_pds_adoption_final_percentage = pd.Series(list(ht_percentages),
                                                     index=list(ht_regions))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * self.tla_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2014] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=self.tla_per_region,
            pds_adoption_limits=self.tla_per_region,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=self.tla_per_region,
            pds_total_adoption_units=self.tla_per_region,
            electricity_unit_factor=1000000.0,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            bug_cfunits_double_count=True)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_first_cost_uses_tot_units=True,
            fc_convert_iunit_factor=land.MHA_TO_HA)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=land.MHA_TO_HA)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            direct_ch4_co2_emissions_saved_land(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2eq_emissions_saved=self.ua.
            direct_co2eq_emissions_saved_land(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            direct_co2_emissions_saved_land(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            direct_n2o_co2_emissions_saved_land(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            direct_ch4_co2_emissions_saved_land(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            tot_red_in_deg_land=self.ua.
            cumulative_reduction_in_total_degraded_land(),
            pds_protected_deg_land=self.ua.
            pds_cumulative_degraded_land_protected(),
            ref_protected_deg_land=self.ua.
            ref_cumulative_degraded_land_protected(),
            regime_distribution=self.ae.get_land_distribution())
Ejemplo n.º 24
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TAM
        tamconfig_list = [
            [
                'param', 'World', 'PDS World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'source_until_2014', self.ac.source_until_2014,
                self.ac.source_until_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'source_after_2014', self.ac.ref_source_post_2014,
                self.ac.pds_source_post_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'trend', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly'
            ],
            [
                'growth', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'
            ],
            [
                'low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ],
            [
                'high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ]
        ]
        tamconfig = pd.DataFrame(tamconfig_list[1:],
                                 columns=tamconfig_list[0],
                                 dtype=np.object).set_index('param')
        tam_ref_data_sources = {
            'Baseline Cases': {
                'Based on: IEA ETP 2014 6DS':
                THISDIR.joinpath('tam', 'tam_based_on_IEA_ETP_2014_6DS.csv'),
            },
            'Conservative Cases': {
                'Based on: IEA ETP 2014 4DS':
                THISDIR.joinpath('tam', 'tam_based_on_IEA_ETP_2014_4DS.csv'),
            },
            'Ambitious Cases': {
                'Based on: IEA ETP 2014 2DS':
                THISDIR.joinpath('tam', 'tam_based_on_IEA_ETP_2014_2DS.csv'),
            },
        }
        self.tm = tam.TAM(tamconfig=tamconfig,
                          tam_ref_data_sources=tam_ref_data_sources,
                          tam_pds_data_sources=tam_ref_data_sources)
        ref_tam_per_region = self.tm.ref_tam_per_region()
        pds_tam_per_region = self.tm.pds_tam_per_region()

        # Custom PDS Data
        wb = xlrd.open_workbook(filename=THISDIR.joinpath('trucksdata.xlsx'))
        adoption1 = pd.read_excel(io=wb,
                                  sheet_name='AdoptionFactoring1',
                                  header=0,
                                  index_col=0,
                                  usecols='B:C',
                                  dtype='float',
                                  engine='xlrd',
                                  skiprows=11,
                                  nrows=51)
        adoption2 = pd.read_excel(io=wb,
                                  sheet_name='AdoptionFactoring2',
                                  header=0,
                                  index_col=0,
                                  usecols='B:H,J:M',
                                  dtype='float',
                                  engine='xlrd',
                                  skiprows=10,
                                  nrows=50)
        adoption3 = pd.read_excel(io=wb,
                                  sheet_name='AdoptionFactoring3',
                                  header=0,
                                  index_col=0,
                                  usecols='B:D',
                                  dtype='float',
                                  engine='xlrd',
                                  skiprows=9,
                                  nrows=51)

        ds1_df = pd.DataFrame(index=range(2012, 2061), columns=dd.REGIONS)
        ds1_df['World'] = adoption1.loc[2014:, 'Global']

        ds2_df = adoption2.loc[2012:2060].dropna(axis=0).rename(
            axis='columns',
            mapper={
                'Asia (sans Japan)': 'Asia (Sans Japan)',
                'Middle East & Africa': 'Middle East and Africa',
                'OECD': 'OECD90',
                'EU27': 'EU'
            }).fillna(0.0)
        ds2_df.index = ds2_df.index.astype(int)

        ds3_df = pd.DataFrame(index=range(2012, 2061), columns=dd.REGIONS)
        ds3_df['World'] = adoption3['Adoption tonne-km']

        # Excel Custom PDS Adoption overrides these with real data
        for df in [ds1_df, ds2_df, ds3_df]:
            df.loc[2014, 'World'] = 304732.461811978
            df.loc[2015, 'World'] = 475099.277763475
            df.loc[2016, 'World'] = 660286.809851347
            df.loc[2017, 'World'] = 853343.225192547
            df.loc[2018, 'World'] = 1055789.45303526

        ca_pds_data_sources = [
            {
                'name':
                'PDS1 - Based on ICCT+RMI Freight Work Adoption estimates',
                'include':
                True,
                'description':
                ('ICCT estimates the total freight work each five years, and RMI estimates '
                 'that by 2050 50% of trucks globally may have efficient technologies. We '
                 "therefore interpolate and extrapolate ICCT's freight work data and project "
                 'linear adoption globally from current adoption of truck freight work '
                 "(approximately 5%) to RMI's projection in 2050. "),
                'dataframe':
                ds1_df
            },
            {
                'name':
                'PDS2 - Based on an ICCT Truck Sales extrapolation',
                'include':
                True,
                'description':
                ("We use the number of truck sales estimated for each of ICCT's 16 regions "
                 '(interpolated and extrapolated for each) to estimate the number of truck '
                 'with efficiency packages installed. ICCT has an estimate of the year when '
                 'truck fuel efficiency legislation becomes mandatory for each region. '
                 ),
                'dataframe':
                ds2_df
            },
            {
                'name':
                'PDS3 - Based on IEA Freight Work - 100% Adoption of Trucks by 2035',
                'include':
                True,
                'description':
                ("IEA's estimated Truck freight work data are interpolated and extrapolated "
                 'and we apply an increasing fraction of adoption rising to 100% in 2050. '
                 ),
                'dataframe':
                ds3_df
            },
            {
                'name':
                'Book Ed.1 Scenario 1',
                'include':
                False,
                'description':
                ('ICCT estimates the total freight work each five years, and RMI estimates '
                 'that by 2050 50% of trucks globally may have efficient technologies. We '
                 "therefore interpolate and extrapolate ICCT's freight work data and project "
                 'linear adoption globally from current adoption of truck freight work '
                 "(approximately 5%) to RMI's projection in 2050. "),
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Book_Ed_1_Scenario_1.csv')
            },
            {
                'name':
                'Book Ed.1 Scenario 3',
                'include':
                False,
                'description':
                ('IEA"s estimated Truck freight work data are interpolated and extrapolated '
                 'and we apply an increasing fraction of adoption rising to 100% (of global '
                 'truck freight market only) in 2050. '),
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Book_Ed_1_Scenario_3.csv')
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=self.ac.soln_pds_adoption_custom_high_sd_mult,
            low_sd_mult=self.ac.soln_pds_adoption_custom_low_sd_mult,
            total_adoption_limit=pds_tam_per_region)

        # Custom REF Data
        ca_ref_data_sources = [
            {
                'name':
                'Drawdown Book Reference Scenario',
                'include':
                True,
                'description':
                ('This scenario uses the inputs that were used for the Scenario developed for '
                 'the Drawdown Book Edition 1. The scenario assumes a fixed percent of the '
                 'TAM is adopted for Efficient trucks as the TAM grows. '),
                'filename':
                THISDIR.joinpath(
                    'ca_ref_data',
                    'custom_ref_ad_Drawdown_Book_Reference_Scenario.csv')
            },
            {
                'name':
                'Efficient Truck Share of Market is Fixed',
                'include':
                True,
                'description':
                ('Drawdown calculations for REF adoption of Efficient Trucks based on fixed '
                 'percent of growth of trucking. The 2014 - 2018 values are taken from '
                 'estimates of historical data '),
                'filename':
                THISDIR.joinpath(
                    'ca_ref_data',
                    'custom_ref_ad_Efficient_Truck_Share_of_Market_is_Fixed.csv'
                )
            },
        ]
        self.ref_ca = customadoption.CustomAdoption(
            data_sources=ca_ref_data_sources,
            soln_adoption_custom_name=self.ac.soln_ref_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=ref_tam_per_region)

        ref_adoption_data_per_region = self.ref_ca.adoption_data_per_region()

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None

        ht_ref_adoption_initial = pd.Series(list(
            self.ac.ref_base_adoption.values()),
                                            index=dd.REGIONS)
        ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (
            ht_ref_adoption_initial / ref_tam_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2018] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_pds_adoption_final_percentage = pd.Series(
            list(self.ac.pds_adoption_final_percentage.values()),
            index=list(self.ac.pds_adoption_final_percentage.keys()))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2018] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=ref_tam_per_region,
            pds_adoption_limits=pds_tam_per_region,
            ref_adoption_data_per_region=ref_adoption_data_per_region,
            use_first_pds_datapoint_main=False,
            copy_pds_to_ref=True,
            copy_ref_datapoint=False,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(
            ac=self.ac, grid_emissions_version=3)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=ref_tam_per_region,
            pds_total_adoption_units=pds_tam_per_region,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            repeated_cost_for_iunits=False,
            bug_cfunits_double_count=False)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            fc_convert_iunit_factor=1.0)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=1.0)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            soln_pds_direct_co2_emissions_saved(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            soln_pds_direct_ch4_co2_emissions_saved(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            soln_pds_direct_n2o_co2_emissions_saved(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            fuel_in_liters=False)

        self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014,
                                                                      'World'],
                           soln_avg_annual_use=self.ac.soln_avg_annual_use,
                           conv_avg_annual_use=self.ac.conv_avg_annual_use)
Ejemplo n.º 25
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TLA
        self.ae = aez.AEZ(solution_name=self.name,
                          cohort=2020,
                          regimes=dd.THERMAL_MOISTURE_REGIMES8)
        if self.ac.use_custom_tla:
            self.c_tla = tla.CustomTLA(
                filename=THISDIR.joinpath('custom_tla_data.csv'))
            custom_world_vals = self.c_tla.get_world_values()
        else:
            custom_world_vals = None
        self.tla_per_region = tla.tla_per_region(
            self.ae.get_land_distribution(),
            custom_world_values=custom_world_vals)

        adconfig_list = [
            [
                'param', 'World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'trend', self.ac.soln_pds_adoption_prognostication_trend,
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium'
            ],
            [
                'growth', self.ac.soln_pds_adoption_prognostication_growth,
                'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE',
                'NOTE'
            ],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        ]
        adconfig = pd.DataFrame(adconfig_list[1:],
                                columns=adconfig_list[0],
                                dtype=np.object).set_index('param')
        ad_data_sources = {
            'Raw Data for ALL LAND TYPES': {
                'FAO 2010': THISDIR.joinpath('ad', 'ad_FAO_2010.csv'),
            },
        }
        self.ad = adoptiondata.AdoptionData(ac=self.ac,
                                            data_sources=ad_data_sources,
                                            main_includes_regional=True,
                                            adconfig=adconfig)

        # Custom PDS Data
        ca_pds_columns = ['Year'] + dd.REGIONS
        adoption_2014 = self.ac.ref_base_adoption['World']
        tla_2050 = self.tla_per_region.loc[2050, 'World']
        ds4_percent_adoption_2050 = 0.85
        ds4_adoption_2050 = ds4_percent_adoption_2050 * tla_2050
        ca_pds_data_sources = [
            {
                'name':
                'Low growth, linear trend',
                'include':
                True,
                'datapoints_degree':
                1,
                # This scenario projects the future adoption of bamboo based on historical regional
                # growth reported for the 1990-2010 period in the Global Forest Resource Assessment
                # 2010 report, published by the FAO.
                'datapoints':
                pd.DataFrame([
                    [
                        1990, np.nan, 0.0, 0.0, 15.412, 3.688, 10.399, 0.0,
                        0.0, 0.0, 0.0
                    ],
                    [
                        2000, np.nan, 0.0, 0.0, 16.311, 3.656, 10.399, 0.0,
                        0.0, 0.0, 0.0
                    ],
                    [
                        2005, np.nan, 0.0, 0.0, 16.943, 3.640, 10.399, 0.0,
                        0.0, 0.0, 0.0
                    ],
                    [
                        2010, np.nan, 0.0, 0.0, 17.360, 3.627, 10.399, 0.0,
                        0.0, 0.0, 0.0
                    ],
                ],
                             columns=ca_pds_columns).set_index('Year')
            },
            {
                'name':
                'Medium growth, linear trend',
                'include':
                True,
                # This scenario projects the future adoption of bamboo based on the highest
                # historical regional annual growth rate, based on 1990-2010 FAO data. The highest
                # annual growth rate was reported in the Asia region (0.0974 Mha/year). Thus, it
                # was assumed that bamboo plantation in other regions will grow by half of the
                # growth rate calculated in Asia (0.05 Mha/year), while bamboo plantation in Asia
                # continues to grow with the same rate.
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Medium_growth_linear_trend.csv')
            },
            {
                'name':
                'High growth, linear trend',
                'include':
                True,
                # This scenario projects the future adoption of bamboo based on the highest
                # historical regional annual growth rate, based on 1990-2010 FAO data. The highest
                # annual growth rate was reported in the Asia region. Thus, it was assumed that
                # bamboo plantation in other regions will grow at the same growth rate calculated
                # in Asia (0.0974 Mha/year), while bamboo plantation in Asia continues to grow at
                # double this rate (0.19 Mha/year).
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_High_growth_linear_trend.csv')
            },
            {
                'name':
                'Max growth, linear trend',
                'include':
                True,
                # Considering the limited total land available for bamboo, this scenario
                # projects an aggressive adoption of bamboo plantation and projects a worldwide
                # 85% adoption of bamboo plantation by 2050.
                'datapoints':
                pd.DataFrame([
                    [
                        2014, adoption_2014, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                        0.0, 0.0
                    ],
                    [
                        2050, ds4_adoption_2050, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                        0.0, 0.0, 0.0
                    ],
                ],
                             columns=ca_pds_columns).set_index('Year')
            },
            {
                'name':
                'Song et al. 2013',
                'include':
                True,
                # "Annual increase in global bamboo forests based on a global historical annual
                # expansion of bamboo forests of 3%, as reported in Song et al. 2013 (see p.7
                # of publication).
                'filename':
                THISDIR.joinpath('ca_pds_data',
                                 'custom_pds_ad_Song_et_al__2013.csv')
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=self.tla_per_region)

        # Manual adjustment made in spreadsheet for Drawdown 2020.
        for s in self.pds_ca.scenarios.values():
            df = s['df']
            df.loc[2014] = [
                32.8913636108367000, 0.0, 0.0, 18.0440250214314000,
                3.9611495064729000, 10.8861890829324000, 0.0, 0.0, 0.0, 0.0
            ]
            df.loc[2015] = [
                33.0453659423780000, 0.0, 0.0, 18.1703910504150000,
                3.9772571687142000, 10.8977177232488000, 0.0, 0.0, 0.0, 0.0
            ]
            df.loc[2016] = [
                33.2014226143695000, 0.0, 0.0, 18.2979284861039000,
                3.9938159101118100, 10.9096782181539000, 0.0, 0.0, 0.0, 0.0
            ]
            df.loc[2017] = [
                33.3595689913150000, 0.0, 0.0, 18.4266654288099000,
                4.0108468526825300, 10.9220567098226000, 0.0, 0.0, 0.0, 0.0
            ]
            df.loc[2018] = [
                33.5198404377181000, 0.0, 0.0, 18.5566299788448000,
                4.0283711184431500, 10.9348393404302000, 0.0, 0.0, 0.0, 0.0
            ]

        # Custom REF Data
        ca_ref_data_sources = [
            {
                'name':
                '[Type Scenario 1 Name Here (REF CASE)...]',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_ref_data',
                    'custom_ref_ad_Type_Scenario_1_Name_Here_REF_CASE_.csv')
            },
        ]
        self.ref_ca = customadoption.CustomAdoption(
            data_sources=ca_ref_data_sources,
            soln_adoption_custom_name=self.ac.soln_ref_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=self.tla_per_region)

        if self.ac.soln_ref_adoption_basis == 'Custom':
            ref_adoption_data_per_region = self.ref_ca.adoption_data_per_region(
            )
        else:
            ref_adoption_data_per_region = None

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None
        elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
            pds_adoption_data_per_region = self.ad.adoption_data_per_region()
            pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
            pds_adoption_is_single_source = self.ad.adoption_is_single_source()

        ht_ref_adoption_initial = pd.Series(list(
            self.ac.ref_base_adoption.values()),
                                            index=dd.REGIONS)
        ht_ref_adoption_final = self.tla_per_region.loc[2050] * (
            ht_ref_adoption_initial / self.tla_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2018] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_pds_adoption_final_percentage = pd.Series(
            list(self.ac.pds_adoption_final_percentage.values()),
            index=list(self.ac.pds_adoption_final_percentage.keys()))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * self.tla_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2018] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=self.tla_per_region,
            pds_adoption_limits=self.tla_per_region,
            ref_adoption_data_per_region=ref_adoption_data_per_region,
            use_first_pds_datapoint_main=False,
            adoption_base_year=2018,
            copy_pds_to_ref=False,
            copy_ref_datapoint=False,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=self.tla_per_region,
            pds_total_adoption_units=self.tla_per_region,
            electricity_unit_factor=1000000.0,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            bug_cfunits_double_count=True)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_first_cost_uses_tot_units=True,
            fc_convert_iunit_factor=land.MHA_TO_HA)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=land.MHA_TO_HA)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            direct_ch4_co2_emissions_saved_land(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2eq_emissions_saved=self.ua.
            direct_co2eq_emissions_saved_land(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            direct_co2_emissions_saved_land(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            direct_n2o_co2_emissions_saved_land(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            direct_ch4_co2_emissions_saved_land(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            annual_land_area_harvested=self.ua.
            soln_pds_annual_land_area_harvested(),
            regime_distribution=self.ae.get_land_distribution(),
            regimes=dd.THERMAL_MOISTURE_REGIMES8)
Ejemplo n.º 26
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TAM
        tamconfig_list = [
            [
                'param', 'World', 'PDS World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'source_until_2014', self.ac.source_until_2014,
                self.ac.source_until_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'source_after_2014', self.ac.ref_source_post_2014,
                self.ac.pds_source_post_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'trend', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly'
            ],
            [
                'growth', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'
            ],
            [
                'low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ],
            [
                'high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ]
        ]
        tamconfig = pd.DataFrame(tamconfig_list[1:],
                                 columns=tamconfig_list[0],
                                 dtype=np.object).set_index('param')
        tam_ref_data_sources = {
            'Baseline Cases': {
                'IEA, 2013, "Transition to Sustainable Buildings" – see TAM Factoring':
                THISDIR.joinpath(
                    'tam',
                    'tam_IEA_2013_Transition_to_Sustainable_Buildings_see_TAM_Factoring.csv'
                ),
                'Ürge-Vorsatz et al. (2015) – see TAM Factoring':
                THISDIR.joinpath(
                    'tam',
                    'tam_ÜrgeVorsatz_et_al__2015_see_TAM_Factoring.csv'),
            },
            'Region: USA': {
                'Baseline Cases': {
                    'Annual Energy Outlook 2016, U.S. Energy Information Administration, 2016.':
                    THISDIR.joinpath(
                        'tam',
                        'tam_Annual_Energy_Outlook_2016_U_S__Energy_Information_Administration_2016_.csv'
                    ),
                },
            },
        }
        tam_pds_data_sources = {
            'Baseline Cases': {
                'Drawdown TAM: Adjusted GBPN Data - Commercial Floor Area':
                THISDIR.joinpath(
                    'tam',
                    'tam_pds_Drawdown_TAM_Adjusted_GBPN_Data_Commercial_Floor_Area.csv'
                ),
            },
        }
        self.tm = tam.TAM(tamconfig=tamconfig,
                          tam_ref_data_sources=tam_ref_data_sources,
                          tam_pds_data_sources=tam_pds_data_sources)
        ref_tam_per_region = self.tm.ref_tam_per_region()
        pds_tam_per_region = self.tm.pds_tam_per_region()

        adconfig_list = [
            [
                'param', 'World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'trend', self.ac.soln_pds_adoption_prognostication_trend,
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly'
            ],
            [
                'growth', self.ac.soln_pds_adoption_prognostication_growth,
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium'
            ],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        ]
        adconfig = pd.DataFrame(adconfig_list[1:],
                                columns=adconfig_list[0],
                                dtype=np.object).set_index('param')
        ad_data_sources = {}
        self.ad = adoptiondata.AdoptionData(ac=self.ac,
                                            data_sources=ad_data_sources,
                                            adconfig=adconfig)

        # Custom PDS Data
        ca_pds_data_sources = [
            {
                'name':
                'PDS1 - Adoption based on Navigant Sales and World Green Buildings Council Targets',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_PDS1_Adoption_based_on_Navigant_Sales_and_World_Green_Buildings_Council_Targets.csv'
                )
            },
            {
                'name':
                'PDS2 - Adoption based on Navigant Sales and World Green Buildings Council Targets',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_PDS2_Adoption_based_on_Navigant_Sales_and_World_Green_Buildings_Council_Targets.csv'
                )
            },
            {
                'name':
                'PDS3 - Adoption based on Navigant Sales and World Green Buildings Council Targets',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_PDS3_Adoption_based_on_Navigant_Sales_and_World_Green_Buildings_Council_Targets.csv'
                )
            },
            {
                'name':
                'Drawdown Book (Edition 1) Scenario 3',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Drawdown_Book_Edition_1_Scenario_3.csv')
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=pds_tam_per_region)

        ref_adoption_data_per_region = None

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None
        elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
            pds_adoption_data_per_region = self.ad.adoption_data_per_region()
            pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
            pds_adoption_is_single_source = self.ad.adoption_is_single_source()

        ht_ref_adoption_initial = pd.Series(
            [1.9734999131249993, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            index=dd.REGIONS)
        ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (
            ht_ref_adoption_initial / ref_tam_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2014] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_regions, ht_percentages = zip(
            *self.ac.pds_adoption_final_percentage)
        ht_pds_adoption_final_percentage = pd.Series(list(ht_percentages),
                                                     index=list(ht_regions))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2014] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=ref_tam_per_region,
            pds_adoption_limits=pds_tam_per_region,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=ref_tam_per_region,
            pds_total_adoption_units=pds_tam_per_region,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            repeated_cost_for_iunits=False,
            bug_cfunits_double_count=False)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            fc_convert_iunit_factor=1.0)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=1.0)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            soln_pds_direct_co2_emissions_saved(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            soln_pds_direct_ch4_co2_emissions_saved(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            soln_pds_direct_n2o_co2_emissions_saved(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            fuel_in_liters=False)

        self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014,
                                                                      'World'],
                           soln_avg_annual_use=self.ac.soln_avg_annual_use,
                           conv_avg_annual_use=self.ac.conv_avg_annual_use)
Ejemplo n.º 27
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TAM
        tamconfig_list = [
            [
                'param', 'World', 'PDS World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'source_until_2014', self.ac.source_until_2014,
                self.ac.source_until_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'source_after_2014', self.ac.ref_source_post_2014,
                self.ac.pds_source_post_2014, 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'
            ],
            [
                'trend', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly'
            ],
            [
                'growth', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'
            ],
            [
                'low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ],
            [
                'high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
                1.0, 1.0
            ]
        ]
        tamconfig = pd.DataFrame(tamconfig_list[1:],
                                 columns=tamconfig_list[0],
                                 dtype=np.object).set_index('param')
        tam_ref_data_sources = {
            'Baseline Cases': {
                'Based on IEA (2016), "Energy Technology Perspectives - 6DS", IEA/OECD':
                THISDIR.joinpath(
                    'tam',
                    'tam_based_on_IEA_2016_Energy_Technology_Perspectives_6DS_IEAOECD.csv'
                ),
                'Based on ICCT (2012) "Global Transport Roadmap Model", http://www.theicct.org/global-transportation-roadmap-model':
                THISDIR.joinpath(
                    'tam',
                    'tam_based_on_ICCT_2012_Global_Transport_Roadmap_Model_httpwww_theicct_orgglobaltransportatio_8916596a.csv'
                ),
            },
            'Conservative Cases': {
                'Based on IEA (2016), "Energy Technology Perspectives - 4DS", IEA/OECD':
                THISDIR.joinpath(
                    'tam',
                    'tam_based_on_IEA_2016_Energy_Technology_Perspectives_4DS_IEAOECD.csv'
                ),
            },
            'Ambitious Cases': {
                'Based on IEA (2016), "Energy Technology Perspectives - 2DS", IEA/OECD':
                THISDIR.joinpath(
                    'tam',
                    'tam_based_on_IEA_2016_Energy_Technology_Perspectives_2DS_IEAOECD.csv'
                ),
            },
        }
        self.tm = tam.TAM(tamconfig=tamconfig,
                          tam_ref_data_sources=tam_ref_data_sources,
                          tam_pds_data_sources=tam_ref_data_sources)
        ref_tam_per_region = self.tm.ref_tam_per_region()
        pds_tam_per_region = self.tm.pds_tam_per_region()

        adconfig_list = [
            [
                'param', 'World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'trend', self.ac.soln_pds_adoption_prognostication_trend,
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly'
            ],
            [
                'growth', self.ac.soln_pds_adoption_prognostication_growth,
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium'
            ],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        ]
        adconfig = pd.DataFrame(adconfig_list[1:],
                                columns=adconfig_list[0],
                                dtype=np.object).set_index('param')
        ad_data_sources = {
            'Conservative Cases': {
                'Navigant Research':
                THISDIR.joinpath('ad', 'ad_Navigant_Research.csv'),
                'Based on: IEA ETP 2016 4DS':
                THISDIR.joinpath('ad', 'ad_based_on_IEA_ETP_2016_4DS.csv'),
                'Based on Clean Energy Manufacturing Analysis Center':
                THISDIR.joinpath(
                    'ad',
                    'ad_based_on_Clean_Energy_Manufacturing_Analysis_Center.csv'
                ),
            },
            'Ambitious Cases': {
                'Based on: IEA ETP 2016 2DS':
                THISDIR.joinpath('ad', 'ad_based_on_IEA_ETP_2016_2DS.csv'),
                'Interpolation Based on World Energy Council 2011 - Global Transport Scenarios 2050':
                THISDIR.joinpath(
                    'ad',
                    'ad_Interpolation_based_on_World_Energy_Council_2011_Global_Transport_Scenarios_2050.csv'
                ),
            },
        }
        self.ad = adoptiondata.AdoptionData(ac=self.ac,
                                            data_sources=ad_data_sources,
                                            adconfig=adconfig)

        # Custom PDS Data
        wb = xlrd.open_workbook(
            filename=THISDIR.joinpath('hybridcarsdata.xlsx'))
        raw_sales = pd.read_excel(io=wb,
                                  sheet_name='HEV Sales',
                                  header=0,
                                  index_col=0,
                                  usecols='A:K',
                                  dtype='float',
                                  engine='xlrd',
                                  skiprows=7,
                                  nrows=43)
        hev_sales = raw_sales.rename(
            axis='columns',
            mapper={
                'World ': 'World',
                'OECD90 (US, EU Japan, Canada)': 'OECD90',
                'Asia sans Japan (China, India & Other.)': 'Asia (Sans Japan)',
                'Middle East & Africa': 'Middle East and Africa'
            }).fillna(0.0)
        lifetime = int(np.ceil(self.ac.soln_lifetime_replacement))
        sales_extended = hev_sales.copy()
        for year in range(2019, 2061):
            sales_extended.loc[year, :] = 0.0
        vehicle_retirements = sales_extended.shift(periods=lifetime,
                                                   fill_value=0.0)
        hev_stock = (hev_sales - vehicle_retirements).cumsum()
        pass_km_adoption = hev_stock * self.ac.soln_avg_annual_use

        # HybridCars.xlsm 'Data Interpolator'!H1582, Adoption Data
        # Project Drawdown Analysis based on Market Reports and a Drop in HEV
        # in later years (replaced by EVs) - PDS2
        predict = pd.read_csv(THISDIR.joinpath('ca_pds_data',
                                               'pass_km_datapoints_PDS2.csv'),
                              skipinitialspace=True,
                              comment='#',
                              index_col=0,
                              squeeze=True)
        pass_km_predicted = interpolation.poly_degree3_trend(
            predict)['adoption']
        pass_km_predicted.update(
            predict.loc[:2018])  # Early years adjusted to be actual values
        integration_pds2 = pd.read_csv(THISDIR.joinpath(
            'tam', 'integration_PDS2.csv'),
                                       skipinitialspace=True,
                                       comment='#',
                                       index_col=0)
        tam_limit_pds2 = 0.95 * (integration_pds2['URBAN'] +
                                 integration_pds2['NONURBAN']) * 1e9
        world = pd.concat([
            pass_km_adoption.loc[2012:2016, 'World'],
            pass_km_predicted.loc[2017:]
        ])
        ds1_df = pd.DataFrame(0, columns=dd.REGIONS, index=range(2012, 2061))
        ds1_df['World'] = world.clip(upper=tam_limit_pds2, lower=0.0, axis=0)

        # Data Source 2
        predict = pd.read_csv(THISDIR.joinpath('ca_pds_data',
                                               'pass_km_datapoints_PDS3.csv'),
                              skipinitialspace=True,
                              comment='#',
                              index_col=0,
                              squeeze=True)
        pass_km_predicted = interpolation.poly_degree3_trend(
            predict)['adoption']
        pass_km_predicted.update(
            predict.loc[:2018])  # Early years adjusted to be actual values
        integration_pds3 = pd.read_csv(THISDIR.joinpath(
            'tam', 'integration_PDS3.csv'),
                                       skipinitialspace=True,
                                       comment='#',
                                       index_col=0)
        intg_limit = (integration_pds3['URBAN'] +
                      integration_pds3['NONURBAN']) * 1e9
        tam_limit_pds3 = pd.concat([(intg_limit.loc[:2035] * 0.95),
                                    (intg_limit.loc[2036:] * 0.9)])
        world = pd.concat([
            pass_km_adoption.loc[2012:2016, 'World'],
            pass_km_predicted.loc[2017:]
        ])
        ds2_df = pd.DataFrame(0, columns=dd.REGIONS, index=range(2012, 2061))
        ds2_df['World'] = world.clip(upper=tam_limit_pds3, lower=0.0, axis=0)

        ca_pds_data_sources = [
            {
                'name':
                'PDS2-Transition to EVs in Cities',
                'include':
                True,
                'description':
                ('Considering that Electric Vehicles (BEV or PHEV)  are a better technology '
                 'from a lifetime emissions perspective, HEV are considered as a transition '
                 'technology in the PDS2  where the target is drawdown by 2050 particularly '
                 'within cities where there is minimal range anxiety. In this Drawdown '
                 'scenario, then, the focus is on growing EV after all higher priority '
                 'solutions (like non-motorized transportation) in cities are grown to their '
                 "maximum potential. For HEV's then, the adoption is projected to only occur "
                 'where BEV or PHEV cars cannot easily be used, such as for long distance '
                 'intercity trips until perhaps around 2025 when EV battery technology can be '
                 'assumed to be adequate enough to eliminate all range anxiety. The HEV '
                 'adoption is projected to continue its growth until around 2025 when it '
                 'starts to decline and trend to zero by or before 2050. Sales data for '
                 'multiple key countries and regions were used to estimate the actual global '
                 "sales. Using the model's lifetime data, the older HEVs are removed from the "
                 'fleet while aggregating the total sales to get the total stock per year. '
                 'With these, the projected sales from IEA are used to project increments to '
                 'the existing stock to 2050 (latest data vailable). Stock data are converted '
                 "to usage with model's Advanced Controls input.  All scenarios are limited "
                 'by integrated TAM after removing adoptions of higher priority solutions. '
                 ),
                'dataframe':
                ds1_df
            },
            {
                'name':
                'PDS3-Transition to EVs',
                'include':
                True,
                'description':
                ('Considering that Electric Vehicles (BEV or PHEV)  are a better technology '
                 'from a lifetime emissions perspective, HEV are considered as a transition '
                 'technology in the PDS3  where the target is maximizing emissions reduction. '
                 'In this scenario, then, the focus is on growing EV after all higher '
                 'priority solutions (like non-motorized transportation)  are grown to their '
                 'maximum potential. As soon as possible, HEV sales will rapidly decline. '
                 'Sales data for multiple key countries and regions were used to estimate the '
                 "actual global sales. Using the model's lifetime data, the older HEVs are "
                 'removed from the fleet while aggregating the total sales to get the total '
                 "stock per year.  Stock data are converted to usage with model's Advanced "
                 'Controls input.  All scenarios are limited by integrated TAM after removing '
                 'adoptions of higher priority solutions. '),
                'dataframe':
                ds2_df
            },
            {
                'name':
                'Drawdown Book - Edition 1- Quick Doubling of Hybrid Car Occupancy',
                'include':
                True,
                'description':
                ('We take the Average of two Ambitious adoption scenarios (on Adoption Data '
                 'tab): Interpolation of IEA 2016 ETP 2DS(2016), and World Energy Council '
                 '(2011) (both with annual use of ICCT Roadmap Model). We then double the HEV '
                 'car occupancy from 2017 and interpolate back to current adoption for 2014. '
                 ),
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Drawdown_Book_Edition_1_Quick_Doubling_of_Hybrid_Car_Occupancy.csv'
                )
            },
            {
                'name':
                'PDS1 - Aggressive Growth from Existing Stock  based on  IEA 2DS',
                'include':
                True,
                'description':
                ('Sales data for multiple key countries and regions were used to estimate the '
                 "global sales. Using the model's lifetime data, the older HEVs are removed "
                 'from the fleet while aggregating the total sales to get the total stock per '
                 'year. With these, the projected sales from IEA are used to project '
                 'increments to the existing stock to 2050 (latest data vailable). Stock data '
                 "are converted to usage with model's Advanced Controls input. All scenarios "
                 'are limited by integrated TAM after removing adoptions of higher priority '
                 'solutions. '),
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_PDS1_Aggressive_Growth_from_Existing_Stock_based_on_IEA_2DS.csv'
                )
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=self.ac.soln_pds_adoption_custom_high_sd_mult,
            low_sd_mult=self.ac.soln_pds_adoption_custom_low_sd_mult,
            total_adoption_limit=pds_tam_per_region)

        # Custom REF Data
        ca_ref_data_sources = [
            {
                'name':
                'Default REF Projection with Adjustment for Recent Historical Adoptions',
                'include':
                True,
                'description':
                ('We take the Default Project Drawdown REF adoption using Average Baseline '
                 'TAM data and then adjust the years 2012-2018 to be the estimated historical '
                 'adoptions from the HEV Pass-Km tab. '),
                'filename':
                THISDIR.joinpath(
                    'ca_ref_data',
                    'custom_ref_ad_Default_REF_Projection_with_Adjustment_for_Recent_Historical_Adoptions.csv'
                )
            },
        ]
        self.ref_ca = customadoption.CustomAdoption(
            data_sources=ca_ref_data_sources,
            soln_adoption_custom_name=self.ac.soln_ref_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=ref_tam_per_region)

        if self.ac.soln_ref_adoption_basis == 'Custom':
            ref_adoption_data_per_region = self.ref_ca.adoption_data_per_region(
            )
        else:
            ref_adoption_data_per_region = None

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None
        elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
            pds_adoption_data_per_region = self.ad.adoption_data_per_region()
            pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
            pds_adoption_is_single_source = self.ad.adoption_is_single_source()

        ht_ref_adoption_initial = pd.Series(list(
            self.ac.ref_base_adoption.values()),
                                            index=dd.REGIONS)
        ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (
            ht_ref_adoption_initial / ref_tam_per_region.loc[2018])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2018] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_pds_adoption_final_percentage = pd.Series(
            list(self.ac.pds_adoption_final_percentage.values()),
            index=list(self.ac.pds_adoption_final_percentage.keys()))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2018] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=ref_tam_per_region,
            pds_adoption_limits=pds_tam_per_region,
            ref_adoption_data_per_region=ref_adoption_data_per_region,
            use_first_pds_datapoint_main=False,
            copy_pds_to_ref=False,
            copy_ref_datapoint=False,
            copy_pds_datapoint=False,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(
            ac=self.ac, grid_emissions_version=3)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=ref_tam_per_region,
            pds_total_adoption_units=pds_tam_per_region,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            bug_cfunits_double_count=True)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            fc_convert_iunit_factor=1.0)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=1.0)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            soln_pds_direct_co2_emissions_saved(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            soln_pds_direct_ch4_co2_emissions_saved(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            soln_pds_direct_n2o_co2_emissions_saved(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            fuel_in_liters=False)

        self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014,
                                                                      'World'],
                           soln_avg_annual_use=self.ac.soln_avg_annual_use,
                           conv_avg_annual_use=self.ac.conv_avg_annual_use)
Ejemplo n.º 28
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TLA
        self.ae = aez.AEZ(solution_name=self.name,
                          cohort=2020,
                          regimes=dd.THERMAL_MOISTURE_REGIMES8)
        if self.ac.use_custom_tla:
            self.c_tla = tla.CustomTLA(
                filename=THISDIR.joinpath('custom_tla_data.csv'))
            custom_world_vals = self.c_tla.get_world_values()
        else:
            custom_world_vals = None
        self.tla_per_region = tla.tla_per_region(
            self.ae.get_land_distribution(),
            custom_world_values=custom_world_vals)

        adconfig_list = [
            [
                'param', 'World', 'OECD90', 'Eastern Europe',
                'Asia (Sans Japan)', 'Middle East and Africa', 'Latin America',
                'China', 'India', 'EU', 'USA'
            ],
            [
                'trend', self.ac.soln_pds_adoption_prognostication_trend,
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium'
            ],
            [
                'growth', self.ac.soln_pds_adoption_prognostication_growth,
                'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE', 'NOTE',
                'NOTE'
            ],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        ]
        adconfig = pd.DataFrame(adconfig_list[1:],
                                columns=adconfig_list[0],
                                dtype=np.object).set_index('param')
        ad_data_sources = {
            'Raw Data for ALL LAND TYPES': {
                'Nair 2012 & Lal et al. 2018':
                THISDIR.joinpath('ad', 'ad_Nair_2012_Lal_et_al__2018.csv'),
            },
        }
        self.ad = adoptiondata.AdoptionData(ac=self.ac,
                                            data_sources=ad_data_sources,
                                            main_includes_regional=True,
                                            adconfig=adconfig)

        # Custom PDS Data
        ca_pds_columns = ['Year'] + dd.REGIONS
        tla_2050 = self.tla_per_region.loc[2050, 'World']
        adoption_vma = VMAs['Current Adoption']
        adoption_2018 = adoption_vma.avg_high_low(key='mean')

        # SOURCE: den Herder, M., Moreno, G., Mosquera-Losada, R. M., Palma, J. H., Sidiropoulou,
        # A., Freijanes, J. J. S., ... & Papanastasis, V. P. (2017). Current extent and
        # stratification of agroforestry in the European Union. Agriculture, Ecosystems &
        # Environment, 241, 121-132.
        ds4_silvo_of_grassland = 0.35
        ds4_total_grassland = 3621.237045
        ds4_potential_adoption = ds4_silvo_of_grassland * ds4_total_grassland
        ds4_adopt_2050 = 0.6 * ds4_potential_adoption

        # SOURCE: Somarriba, E., Beer, J., Alegre-Orihuela, J., Andrade, H. J., Cerda, R., DeClerck,
        # F., ... & Krishnamurthy, L. (2012). Mainstreaming agroforestry in Latin America. In
        # Agroforestry-The Future of Global Land Use (pp. 429-453). Springer, Dordrecht.
        ds5_adoption_rate = 0.45
        pg_vma = VMAs['Total Pasture/Grazing Area']
        pasture_grassland_area = pg_vma.avg_high_low(key='mean')
        ds5_potential_adoption = ds5_adoption_rate * pasture_grassland_area
        ds5_adopt_2050 = 0.6 * ds5_potential_adoption

        # SOURCE: Holman et al., 2004, http://www.lrrd.org/lrrd16/12/holm16098.htm
        growth_initial = pd.DataFrame(
            [[2018] + list(self.ac.ref_base_adoption.values())],
            columns=ca_pds_columns).set_index('Year')
        ds6_rate = 0.006

        # SOURCE: Holman et al., 2004, http://www.lrrd.org/lrrd16/12/holm16098.htm
        ds7_rate = 0.013

        ca_pds_data_sources = [
            {
                'name':
                'Linear trend based on Zomers  >30% tree cover percent area applied in grassland area',
                'include':
                False,
                # This is a proxy adoption scenario which is created in the absence of any data
                # available either on historical growth rate of silvopasture or any future
                # projections. Thus, the present scenario builds the future adoption using the
                # Zoomer 2014 information available on tree coverage in the agricultural area.
                # Country level data on agricultural area with > 30 percent tree cover was available
                # at Zomer 2014. This data was compiled at the Project Drawdown regions, which is
                # then used to get their percent with respect  to the total agricultural area.
                # Those percentages were then applied on the grassland area to get the regional
                # grassland area under >30 percent tree cover. The future adoption of the silvopasture
                # area under was thus projected based on the regional linear trend applied to the
                # grassland area with >30 percent tree coverage. The projections were based on the
                # regional linear trend. (Refer PD region wise - silvopasture sheet)
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Linear_trend_based_on_Zomers_30_tree_cover_percent_area_applied_in_grassland_area.csv'
                )
            },
            {
                'name':
                'Linear trend based on Zomers >30% tree cover percent area and conversion of >10% are to 30% tree cover area applied in grassland area',
                'include':
                False,
                #  In this scenario, the future area in silvopasture is projected based on scenario
                # one, in addition it was assumed that there will be some extra area available for
                # silvopasture by the conversion of 0-10 percent/11-20 percent tree coverage
                # grassland area to >30 percent tree coverage areas as required for a silvopasture
                # system.  The projections are based on regional linear trends.
                'filename':
                THISDIR.joinpath(
                    'ca_pds_data',
                    'custom_pds_ad_Linear_trend_based_on_Zomers_30_tree_cover_percent_area_and_conversion_of_10_are_to_30_t_d419700f.csv'
                )
            },
            {
                'name':
                'Linear Interpolation for Adoption Data based on Nair 2012 & Lal et al. 2018',
                'include':
                True,
                # In the absence of comprehensive historical data for silvopasture adoption, this
                # scenario uses available global adoption estimates reported in peer-reviewed
                # publications. Data points ffrom 2012 (Nair 2012) and 2018 (Lal et al. 2018) were
                # used for a linear interpolation of future adoption based on historic expansion of
                # silvopasture adoption.
                'datapoints':
                pd.DataFrame([
                    [
                        2018, self.ac.ref_base_adoption['World'], 0., 0., 0.,
                        0., 0., 0., 0., 0., 0.
                    ],
                    [
                        2050, 1083.33333333333, 0., 0., 0., 0., 0., 0., 0., 0.,
                        0.
                    ],
                ],
                             columns=ca_pds_columns).set_index('Year')
            },
            {
                'name':
                'Medium interpolation based on current adoption, linear trend (high regional proportion of grazing land under silvopasture)',
                'include':
                True,
                # Future area in silvopasture is projected based on the proportion of current area
                # of grazing or pasture land under silvopasture practice in the EU, which currently
                # has the highest regional proportion of grazing land under silvopasture worldwide
                # (35%), as reported by den Herder et al 2017 (see VMA, Variable 31). This percentage
                # was applied to the total global grazing area to obtain a medium estimate of
                # potential projected area for future silvopasture adoption. This scenario assumes
                # 60 percent of future silvopasture adoption by 2050.
                'datapoints':
                pd.DataFrame([
                    [
                        2018, self.ac.ref_base_adoption['World'], 0., 0., 0.,
                        0., 0., 0., 0., 0., 0.
                    ],
                    [2050, ds4_adopt_2050, 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                ],
                             columns=ca_pds_columns).set_index('Year')
            },
            {
                'name':
                'High interpolation based on current adoption, linear trend (high national proportion of grazing land under silvopasture)',
                'include':
                True,
                # Future area in silvopasture is projected based on the proportion of current area
                # of grazing or pasture land under silvopasture practice in Nicaragua, which currently
                # has the highest national proportion of grazing land under silvopasture worldwide
                # (45%), as reported by Somarriba et al 2012 (see VMA, Variable 31). This percentage
                # was applied to the total global grazing area to obtain a high estimate of potential
                # projected area for future silvopasture adoption. This scenario assumes 60 percent
                # of future silvopasture adoption by 2050.
                'datapoints':
                pd.DataFrame([
                    [
                        2018, self.ac.ref_base_adoption['World'], 0., 0., 0.,
                        0., 0., 0., 0., 0., 0.
                    ],
                    [2050, ds5_adopt_2050, 0., 0., 0., 0., 0., 0., 0., 0., 0.],
                ],
                             columns=ca_pds_columns).set_index('Year')
            },
            {
                'name':
                'Low growth, linear trend (based on improved pasture area)',
                'include': True,
                # This is a proxy adoption scenario which is created in the absence of any data
                # available either on historical growth rate of silvopasture or any future projections
                # on silvopasture. In this scenario future adoption of silvopasture area was projected
                # using the Thorton 2010 future adoption rates given for improved pasture. The
                # silvopasture adoption is  projected based on the average annual adoption percent
                # (0.60%) increase in the improved pasture area given for the five countries (Mexico,
                # Honduras, Nicaragua, Costa Rica, and Panama) by Holman et al 2004 and reported by
                # Thorton et al 2010. With the limitation of data at the regional level, the
                # projections are made only at the global scale.
                'growth_rate': ds6_rate,
                'growth_initial': growth_initial
            },
            {
                'name':
                'High growth, linear trend (based on improved pasture area)',
                'include': True,
                # This is a proxy adoption scenario which is created in the absence of any data
                # available either on historical growth rate of silvopasture or any future projections
                # on silvopasture. In this scenario future adoption of silvopasture area was projected
                # using the Thorton 2010 future adoption rates given for improved pasture. The
                # silvopasture adoption is  projected based on the maximum annual adoption percent
                # (1.30%) increase in the improved pasture area given for the five countries (Mexico,
                # Honduras, Nicaragua, Costa Rica, and Panama) by Holman et al 2004 and reported by
                # Thorton et al 2010. With the limitation of data at the regional level, the
                # projections are made only at the global scale.
                'growth_rate': ds7_rate,
                'growth_initial': growth_initial
            },
        ]
        self.pds_ca = customadoption.CustomAdoption(
            data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=self.tla_per_region)
        # Manual adjustment made in spreadsheet for Drawdown 2020.
        for source in ca_pds_data_sources:
            if 'filename' in source:
                # only the interpolated sources are adjusted
                continue
            name = source['name']
            s = self.pds_ca.scenarios[name]
            df = s['df']
            df.loc[2012, 'World'] = 450.0
            df.loc[2013, 'World'] = 466.666666666667
            df.loc[2014, 'World'] = 483.333333333333
            df.loc[2015, 'World'] = 500.0
            df.loc[2016, 'World'] = 516.666666666667
            df.loc[2017, 'World'] = 533.333333333333
            df.loc[2018, 'World'] = 550.0

        # Custom REF Data
        ca_ref_data_sources = [
            {
                'name':
                '[Type Scenario 1 Name Here (REF CASE)...]',
                'include':
                True,
                'filename':
                THISDIR.joinpath(
                    'ca_ref_data',
                    'custom_ref_ad_Type_Scenario_1_Name_Here_REF_CASE_.csv')
            },
        ]
        self.ref_ca = customadoption.CustomAdoption(
            data_sources=ca_ref_data_sources,
            soln_adoption_custom_name=self.ac.soln_ref_adoption_custom_name,
            high_sd_mult=1.0,
            low_sd_mult=1.0,
            total_adoption_limit=self.tla_per_region)

        if self.ac.soln_ref_adoption_basis == 'Custom':
            ref_adoption_data_per_region = self.ref_ca.adoption_data_per_region(
            )
        else:
            ref_adoption_data_per_region = None

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region(
            )
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region(
            )
            pds_adoption_is_single_source = None
        elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
            pds_adoption_data_per_region = self.ad.adoption_data_per_region()
            pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
            pds_adoption_is_single_source = self.ad.adoption_is_single_source()

        ht_ref_adoption_initial = pd.Series(list(
            self.ac.ref_base_adoption.values()),
                                            index=dd.REGIONS)
        ht_ref_adoption_final = self.tla_per_region.loc[2050] * (
            ht_ref_adoption_initial / self.tla_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2018] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_pds_adoption_final_percentage = pd.Series(
            list(self.ac.pds_adoption_final_percentage.values()),
            index=list(self.ac.pds_adoption_final_percentage.keys()))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * self.tla_per_region.loc[
            2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2018] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(
            ac=self.ac,
            ref_datapoints=ht_ref_datapoints,
            pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=self.tla_per_region,
            pds_adoption_limits=self.tla_per_region,
            ref_adoption_data_per_region=ref_adoption_data_per_region,
            use_first_pds_datapoint_main=False,
            adoption_base_year=2018,
            copy_pds_to_ref=False,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

        self.ua = unitadoption.UnitAdoption(
            ac=self.ac,
            ref_total_adoption_units=self.tla_per_region,
            pds_total_adoption_units=self.tla_per_region,
            electricity_unit_factor=1000000.0,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            bug_cfunits_double_count=True)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted = self.ua.soln_net_annual_funits_adopted(
        )

        self.fc = firstcost.FirstCost(
            ac=self.ac,
            pds_learning_increase_mult=2,
            ref_learning_increase_mult=2,
            conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_first_cost_uses_tot_units=True,
            fc_convert_iunit_factor=land.MHA_TO_HA)

        self.oc = operatingcost.OperatingCost(
            ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.
            soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.
            soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.
            conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.
            soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.
            conv_ref_install_cost_per_iunit(),
            conversion_factor=land.MHA_TO_HA)

        self.c4 = ch4calcs.CH4Calcs(
            ac=self.ac,
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            direct_ch4_co2_emissions_saved_land(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(
            ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.
            soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.
            soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2eq_emissions_saved=self.ua.
            direct_co2eq_emissions_saved_land(),
            soln_pds_direct_co2_emissions_saved=self.ua.
            direct_co2_emissions_saved_land(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.
            direct_n2o_co2_emissions_saved_land(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.
            direct_ch4_co2_emissions_saved_land(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            annual_land_area_harvested=self.ua.
            soln_pds_annual_land_area_harvested(),
            regime_distribution=self.ae.get_land_distribution(),
            regimes=dd.THERMAL_MOISTURE_REGIMES8)
Ejemplo n.º 29
0
  def __init__(self, scenario=None):
    if scenario is None:
      scenario = list(scenarios.keys())[0]
    self.scenario = scenario
    self.ac = scenarios[scenario]

    # TAM
    tamconfig_list = [
      ['param', 'World', 'PDS World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
       'Middle East and Africa', 'Latin America', 'China', 'India', 'EU', 'USA'],
      ['source_until_2014', self.ac.source_until_2014, self.ac.source_until_2014,
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'],
      ['source_after_2014', self.ac.ref_source_post_2014, self.ac.pds_source_post_2014,
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
       'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'],
      ['trend', '3rd Poly', '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly'],
      ['growth', 'Medium', 'Medium', 'Medium', 'Medium',
       'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'],
      ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
      ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
    tamconfig = pd.DataFrame(tamconfig_list[1:], columns=tamconfig_list[0], dtype=np.object).set_index('param')
    tam_ref_data_sources = {
      'Baseline Cases': {
          'IEA (2016), "Energy Technology Perspectives - 6DS", IEA/OECD': THISDIR.joinpath('tam', 'tam_IEA_2016_Energy_Technology_Perspectives_6DS_IEAOECD.csv'),
          'ICCT (2012) "Global Transport Roadmap Model", http://www.theicct.org/global-transportation-roadmap-model': THISDIR.joinpath('tam', 'tam_ICCT_2012_Global_Transport_Roadmap_Model_httpwww_theicct_orgglobaltransportationroadmapmodel.csv'),
      },
      'Conservative Cases': {
          'IEA (2016), "Energy Technology Perspectives - 4DS", IEA/OECD': THISDIR.joinpath('tam', 'tam_IEA_2016_Energy_Technology_Perspectives_4DS_IEAOECD.csv'),
      },
      'Ambitious Cases': {
          'IEA (2016), "Energy Technology Perspectives - 2DS", IEA/OECD': THISDIR.joinpath('tam', 'tam_IEA_2016_Energy_Technology_Perspectives_2DS_IEAOECD.csv'),
      },
    }
    self.tm = tam.TAM(tamconfig=tamconfig, tam_ref_data_sources=tam_ref_data_sources,
      tam_pds_data_sources=tam_ref_data_sources)
    ref_tam_per_region=self.tm.ref_tam_per_region()
    pds_tam_per_region=self.tm.pds_tam_per_region()

    adconfig_list = [
      ['param', 'World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
       'Middle East and Africa', 'Latin America', 'China', 'India', 'EU', 'USA'],
      ['trend', self.ac.soln_pds_adoption_prognostication_trend, '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
       '3rd Poly', '3rd Poly', '3rd Poly'],
      ['growth', self.ac.soln_pds_adoption_prognostication_growth, 'Medium',
       'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
       'Medium', 'Medium', 'Medium'],
      ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
      ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
    adconfig = pd.DataFrame(adconfig_list[1:], columns=adconfig_list[0], dtype=np.object).set_index('param')
    ad_data_sources = {
      'Baseline Cases': {
          'Based on IEA Reference Tech Scenario- 2017': THISDIR.joinpath('ad', 'ad_based_on_IEA_Reference_Tech_Scenario_2017.csv'),
      },
      'Conservative Cases': {
          'Based on OPEC World Energy Outlook 2016': THISDIR.joinpath('ad', 'ad_based_on_OPEC_World_Energy_Outlook_2016.csv'),
          'Based on The Paris Declaration as Cited in (IEA, 2017- EV Outlook)': THISDIR.joinpath('ad', 'ad_based_on_The_Paris_Declaration_as_Cited_in_IEA_2017_EV_Outlook.csv'),
      },
      'Ambitious Cases': {
          'Based on: IEA ETP 2016 2DS': THISDIR.joinpath('ad', 'ad_based_on_IEA_ETP_2016_2DS.csv'),
          'Based on Bloomberg New Energy Finance - EV Outlook 2017': THISDIR.joinpath('ad', 'ad_based_on_Bloomberg_New_Energy_Finance_EV_Outlook_2017.csv'),
          'Based on IEA Beyond 2DS/B2DS Scenario': THISDIR.joinpath('ad', 'ad_based_on_IEA_Beyond_2DSB2DS_Scenario.csv'),
      },
      'Maximum Cases': {
          'Double EV occupancy on PDS2 = double pass-km': THISDIR.joinpath('ad', 'ad_Double_EV_occupancy_on_PDS2_double_passkm.csv'),
          'Drawdown Projections based on adjusted IEA data (ETP 2012) on projected growth in each year, and recent sales Data (IEA - ETP 2016)': THISDIR.joinpath('ad', 'ad_Drawdown_Projections_based_on_adjusted_IEA_data_ETP_2012_on_projected_growth_in_each_yea_72fb5617.csv'),
      },
    }
    self.ad = adoptiondata.AdoptionData(ac=self.ac, data_sources=ad_data_sources,
        adconfig=adconfig)

    # Custom PDS Data
    ca_pds_data_sources = [
      {'name': 'PDS2-Based on IEA (2017) B2DS+50% Occupancy Increase', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_PDS2based_on_IEA_2017_B2DS50_Occupancy_Increase.csv')},
      {'name': 'PDS3-Based on IEA B2DS with 100% Increase in Car Occupancy', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_PDS3based_on_IEA_B2DS_with_100_Increase_in_Car_Occupancy.csv')},
      {'name': 'Book Ed.1 Scenario 1', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Book_Ed_1_Scenario_1.csv')},
      {'name': 'Book Ed.1 Scenario 2', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Book_Ed_1_Scenario_2.csv')},
      {'name': 'Book Ed.1 Scenario 3', 'include': True,
          'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_Book_Ed_1_Scenario_3.csv')},
    ]
    self.pds_ca = customadoption.CustomAdoption(data_sources=ca_pds_data_sources,
        soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
        high_sd_mult=1.0, low_sd_mult=1.0,
        total_adoption_limit=pds_tam_per_region)

    ref_adoption_data_per_region = None

    if False:
      # One may wonder why this is here. This file was code generated.
      # This 'if False' allows subsequent conditions to all be elif.
      pass
    elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
      pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region()
      pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region()
      pds_adoption_is_single_source = None
    elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
      pds_adoption_data_per_region = self.ad.adoption_data_per_region()
      pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
      pds_adoption_is_single_source = self.ad.adoption_is_single_source()

    ht_ref_adoption_initial = pd.Series(
      [16.701444916159307, 14.405959906291683, 8.68248837596512e-05, 2.7858260096477, 8.68248837596512e-05,
       8.68248837596512e-05, 2.6861138324271523, 0.09962535233678836, 4.508096807458965, 6.7600117997589235],
       index=dd.REGIONS)
    ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (ht_ref_adoption_initial / ref_tam_per_region.loc[2014])
    ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
    ht_ref_datapoints.loc[2014] = ht_ref_adoption_initial
    ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
    ht_pds_adoption_initial = ht_ref_adoption_initial
    ht_regions, ht_percentages = zip(*self.ac.pds_adoption_final_percentage)
    ht_pds_adoption_final_percentage = pd.Series(list(ht_percentages), index=list(ht_regions))
    ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[2050]
    ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
    ht_pds_datapoints.loc[2014] = ht_pds_adoption_initial
    ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
    self.ht = helpertables.HelperTables(ac=self.ac,
        ref_datapoints=ht_ref_datapoints, pds_datapoints=ht_pds_datapoints,
        pds_adoption_data_per_region=pds_adoption_data_per_region,
        ref_adoption_limits=ref_tam_per_region, pds_adoption_limits=pds_tam_per_region,
        pds_adoption_trend_per_region=pds_adoption_trend_per_region,
        pds_adoption_is_single_source=pds_adoption_is_single_source)

    self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac)

    self.ua = unitadoption.UnitAdoption(ac=self.ac,
        ref_total_adoption_units=ref_tam_per_region, pds_total_adoption_units=pds_tam_per_region,
        soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
        soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
        repeated_cost_for_iunits=False,
        bug_cfunits_double_count=False)
    soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
    soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
    conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
    soln_net_annual_funits_adopted=self.ua.soln_net_annual_funits_adopted()

    self.fc = firstcost.FirstCost(ac=self.ac, pds_learning_increase_mult=2,
        ref_learning_increase_mult=2, conv_learning_increase_mult=2,
        soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
        soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
        conv_ref_tot_iunits=conv_ref_tot_iunits,
        soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
        soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
        conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
        fc_convert_iunit_factor=1.0)

    self.oc = operatingcost.OperatingCost(ac=self.ac,
        soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
        soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
        soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
        conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
        soln_pds_annual_world_first_cost=self.fc.soln_pds_annual_world_first_cost(),
        soln_ref_annual_world_first_cost=self.fc.soln_ref_annual_world_first_cost(),
        conv_ref_annual_world_first_cost=self.fc.conv_ref_annual_world_first_cost(),
        single_iunit_purchase_year=2017,
        soln_pds_install_cost_per_iunit=self.fc.soln_pds_install_cost_per_iunit(),
        conv_ref_install_cost_per_iunit=self.fc.conv_ref_install_cost_per_iunit(),
        conversion_factor=1.0)

    self.c4 = ch4calcs.CH4Calcs(ac=self.ac,
        soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

    self.c2 = co2calcs.CO2Calcs(ac=self.ac,
        ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
        soln_pds_net_grid_electricity_units_saved=self.ua.soln_pds_net_grid_electricity_units_saved(),
        soln_pds_net_grid_electricity_units_used=self.ua.soln_pds_net_grid_electricity_units_used(),
        soln_pds_direct_co2_emissions_saved=self.ua.soln_pds_direct_co2_emissions_saved(),
        soln_pds_direct_ch4_co2_emissions_saved=self.ua.soln_pds_direct_ch4_co2_emissions_saved(),
        soln_pds_direct_n2o_co2_emissions_saved=self.ua.soln_pds_direct_n2o_co2_emissions_saved(),
        soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
        soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
        conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
        conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
        conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
        soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
        fuel_in_liters=False)

    self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014, 'World'],
        soln_avg_annual_use=self.ac.soln_avg_annual_use,
        conv_avg_annual_use=self.ac.conv_avg_annual_use)
Ejemplo n.º 30
0
    def __init__(self, scenario=None):
        if scenario is None:
            scenario = list(scenarios.keys())[0]
        self.scenario = scenario
        self.ac = scenarios[scenario]

        # TAM
        tamconfig_list = [
            ['param', 'World', 'PDS World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
                'Middle East and Africa', 'Latin America', 'China', 'India', 'EU', 'USA'],
            ['source_until_2014', self.ac.source_until_2014, self.ac.source_until_2014,
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'],
            ['source_after_2014', self.ac.ref_source_post_2014, self.ac.pds_source_post_2014,
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES',
                'ALL SOURCES', 'ALL SOURCES', 'ALL SOURCES'],
            ['trend', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
                '3rd Poly', '3rd Poly', '3rd Poly'],
            ['growth', 'Medium', 'Medium', 'Medium', 'Medium',
                'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium'],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
        tamconfig = pd.DataFrame(tamconfig_list[1:], columns=tamconfig_list[0],
            dtype=np.object).set_index('param')
        tam_ref_data_sources = {
              'Baseline Cases': {
                  'ETP 2016, URBAN 6 DS + Non-motorized Travel Adjustment': THISDIR.joinpath('tam', 'tam_ETP_2016_URBAN_6_DS_Nonmotorized_Travel_Adjustment.csv'),
                  'ICCT, 2012, "Global Transportation Roadmap Model" + Non-motorized Travel Adjustment': THISDIR.joinpath('tam', 'tam_ICCT_2012_Global_Transportation_Roadmap_Model_Nonmotorized_Travel_Adjustment.csv'),
            },
              'Conservative Cases': {
                  'ETP 2016, URBAN 4 DS + Non-motorized Travel Adjustment': THISDIR.joinpath('tam', 'tam_ETP_2016_URBAN_4_DS_Nonmotorized_Travel_Adjustment.csv'),
                  'ITDP/UC Davis 2014 Global High Shift Baseline': THISDIR.joinpath('tam', 'tam_ITDPUC_Davis_2014_Global_High_Shift_Baseline.csv'),
            },
              'Ambitious Cases': {
                  'ETP 2016, URBAN 2 DS + Non-motorized Travel Adjustment': THISDIR.joinpath('tam', 'tam_ETP_2016_URBAN_2_DS_Nonmotorized_Travel_Adjustment.csv'),
                  'ITDP/UC Davis 2014 Global High Shift HighShift': THISDIR.joinpath('tam', 'tam_ITDPUC_Davis_2014_Global_High_Shift_HighShift.csv'),
            },
        }
        self.tm = tam.TAM(tamconfig=tamconfig, tam_ref_data_sources=tam_ref_data_sources,
            tam_pds_data_sources=tam_ref_data_sources)
        ref_tam_per_region=self.tm.ref_tam_per_region()
        pds_tam_per_region=self.tm.pds_tam_per_region()

        adconfig_list = [
            ['param', 'World', 'OECD90', 'Eastern Europe', 'Asia (Sans Japan)',
             'Middle East and Africa', 'Latin America', 'China', 'India', 'EU', 'USA'],
            ['trend', self.ac.soln_pds_adoption_prognostication_trend, '3rd Poly',
             '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly', '3rd Poly',
             '3rd Poly', '3rd Poly', '3rd Poly'],
            ['growth', self.ac.soln_pds_adoption_prognostication_growth, 'Medium',
             'Medium', 'Medium', 'Medium', 'Medium', 'Medium',
             'Medium', 'Medium', 'Medium'],
            ['low_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
            ['high_sd_mult', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
        adconfig = pd.DataFrame(adconfig_list[1:], columns=adconfig_list[0],
            dtype=np.object).set_index('param')
        ad_data_sources = {
            'Ambitious Cases': {
                'ITDP/UCD (2015) A Global High Shift Cycling Scenario - High Shift Scenario  - Early Years replaced with Recent Historical Data': THISDIR.joinpath('ad', 'ad_ITDPUCD_2015_A_Global_High_Shift_Cycling_Scenario_High_Shift_Scenario_Early_Years_replac_b131f9f6.csv'),
            },
        }
        self.ad = adoptiondata.AdoptionData(ac=self.ac, data_sources=ad_data_sources,
            adconfig=adconfig)

        # Custom PDS Data
        ca_pds_data_sources = [
            {'name': 'PDS2 - Density remains Constant and is the key driver of walking in cities.', 'include': True,
                'description': (
                    'We project the amount of walking that would happen in 1,737 cities '
                    'worldwide representing 57% of the global urban population then we scale the '
                    'total amount of walking to 100% of the world’s urban population. The '
                    'background calculations of this scenario use the population and density of '
                    'each of the 1737 cities from Demographia’s report and projects the fraction '
                    'of each country’s urban population in that city. We assume that that '
                    'fraction is constant and then project the city’s population each year to '
                    '2050 using UN projections of each country’s urban population to 2050. With '
                    'the TAM and total urban population projections, we estimate the mobility '
                    'per urban resident each year and then apply 6.5% to walking in each city in '
                    'each year when the density is over the "dense city threshold" (~3,000 '
                    'p/sqkm) and 2% otherwise. Each year is scaled to the global urban '
                    'population. '
                    ),
                'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_PDS2_Density_remains_Constant_and_is_the_key_driver_of_walking_in_cities_.csv')},
            {'name': 'PDS2 - Increasing Urban Density with Density Driving Urban Walking (Book Ed.1)', 'include': True,
                'description': (
                    'We project the amount of walking that would happen in 1,737 cities '
                    'worldwide representing 57% of the global urban population then we scale the '
                    'total amount of walking to 100% of the world’s urban population. The '
                    'background calculations of this scenario use the population and density of '
                    'each of the 1737 cities from Demographia’s report and projects the fraction '
                    'of each country’s urban population in that city. We assume that that '
                    'fraction is constant and then project the city’s population each year to '
                    '2050 using UN projections of each country’s urban population to 2050. With '
                    'the TAM and total urban population projections, we estimate the mobility '
                    'per urban resident each year and then apply 7% to walking in each city in '
                    'each year when the density is over the "dense city threshold" (~3,000 '
                    'p/sqkm) and 2% otherwise. Each year is scaled to the global urban '
                    'population. City densities are assumed to increased by around 2.4% annually '
                    'which reverses historical declines of around 2%. This scenario was '
                    'calculated for the Drawdown book Edition 1. Some variables may have been '
                    'updated. '
                    ),
                'filename': THISDIR.joinpath('ca_pds_data', 'custom_pds_ad_PDS2_Increasing_Urban_Density_with_Density_Driving_Urban_Walking_Book_Ed_1.csv')},
        ]
        self.pds_ca = customadoption.CustomAdoption(data_sources=ca_pds_data_sources,
            soln_adoption_custom_name=self.ac.soln_pds_adoption_custom_name,
            high_sd_mult=self.ac.soln_pds_adoption_custom_high_sd_mult,
            low_sd_mult=self.ac.soln_pds_adoption_custom_low_sd_mult,
            total_adoption_limit=pds_tam_per_region)

        # Custom REF Data
        ca_ref_data_sources = [
            {'name': 'Custom REF Scenario 1: Fixed Passenger-km Annual after 2014', 'include': True,
                'description': (
                    'Taking the estimated passenger-km adoption value from 2014, we hold that '
                    'constant out to 2050 which assumes that the total amount of walking remains '
                    'constant despite increasing populations. The rapid rise in populations '
                    'generally happens in developing countries, and as these countries urbanise '
                    'and get wealthier, there is a large trend towards increased motorization '
                    'following the historical patterns of Western Nations. This then, although a '
                    'pessimistic case, is not unrealistic. '
                    ),
                'filename': THISDIR.joinpath('ca_ref_data', 'custom_ref_ad_Custom_REF_Scenario_1_Fixed_Passengerkm_Annual_after_2018.csv')},
            {'name': 'Reference Growth in Walking', 'include': True,
                'description': (
                    'Here the Drawdown Model of Urban density for 1,737 cities across the world '
                    'in the Demographia Dataset was used to develop a reasonable Reference '
                    'Scenario for Walking out to the end of the analysis period. While full '
                    'details are described in the [Mobility Output] sheet, here is the summary: '
                    'The urban density of these cities (representing 57% of the world urban '
                    'population), was obtained from the data source and projected out to 2050 '
                    'using an assumed global urban density change as listed below. Research on '
                    'walking in cities indicates that higher density is correlated with more '
                    'walking, so an assumed walking mode share in cities with at least the '
                    'minimum threshold urban density, and another assumed walking mode share for '
                    'cities below this threshold were together used to estimate the average '
                    'walking for each city in each year (considering that density change is '
                    'assumed). The total walking mobility in these cities was summed and then '
                    'scaled linearly to 100% of the global urban population. This projection to '
                    '2050 was then interpolated and extrapolated to develop a smooth curve for '
                    'the entire analysis period. Also taken into account: increasing urban '
                    'population, assumed fixed total mobility per capita, recent historical '
                    'walking estimates have been used (2012-2018) instead of curve fit. '
                    ),
                'filename': THISDIR.joinpath('ca_ref_data', 'custom_ref_ad_Reference_Growth_in_Walking.csv')},
            {'name': 'ITDP/ UCDavis (2015) Global Highshift Cycling Scenario - Baseline Case for Walking', 'include': True,
                'description': (
                    'The Source listed below estimated a Baseline Walking Case which generally '
                    'shows an increae in walking, but not in line with total mobility increase, '
                    'so the walking mode share declines over time. The source published data in '
                    '5-year increments, these have been interpolated for missing years (on Data- '
                    'Interpolator) and pasted here. '
                    ),
                'filename': THISDIR.joinpath('ca_ref_data', 'custom_ref_ad_ITDP_UCDavis_2015_Global_Highshift_Cycling_Scenario_Baseline_Case_for_Walking.csv')},
        ]
        self.ref_ca = customadoption.CustomAdoption(data_sources=ca_ref_data_sources,
            soln_adoption_custom_name=self.ac.soln_ref_adoption_custom_name,
            high_sd_mult=1.0, low_sd_mult=1.0,
            total_adoption_limit=ref_tam_per_region)

        ref_adoption_data_per_region = self.ref_ca.adoption_data_per_region()

        if False:
            # One may wonder why this is here. This file was code generated.
            # This 'if False' allows subsequent conditions to all be elif.
            pass
        elif self.ac.soln_pds_adoption_basis == 'Fully Customized PDS':
            pds_adoption_data_per_region = self.pds_ca.adoption_data_per_region()
            pds_adoption_trend_per_region = self.pds_ca.adoption_trend_per_region()
            pds_adoption_is_single_source = None
        elif self.ac.soln_pds_adoption_basis == 'Existing Adoption Prognostications':
            pds_adoption_data_per_region = self.ad.adoption_data_per_region()
            pds_adoption_trend_per_region = self.ad.adoption_trend_per_region()
            pds_adoption_is_single_source = self.ad.adoption_is_single_source()
        elif self.ac.soln_pds_adoption_basis == 'Linear':
            pds_adoption_data_per_region = None
            pds_adoption_trend_per_region = None
            pds_adoption_is_single_source = None

        ht_ref_adoption_initial = pd.Series(
            list(self.ac.ref_base_adoption.values()), index=dd.REGIONS)
        ht_ref_adoption_final = ref_tam_per_region.loc[2050] * (ht_ref_adoption_initial /
            ref_tam_per_region.loc[2014])
        ht_ref_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_ref_datapoints.loc[2018] = ht_ref_adoption_initial
        ht_ref_datapoints.loc[2050] = ht_ref_adoption_final.fillna(0.0)
        ht_pds_adoption_initial = ht_ref_adoption_initial
        ht_pds_adoption_final_percentage = pd.Series(
            list(self.ac.pds_adoption_final_percentage.values()),
            index=list(self.ac.pds_adoption_final_percentage.keys()))
        ht_pds_adoption_final = ht_pds_adoption_final_percentage * pds_tam_per_region.loc[2050]
        ht_pds_datapoints = pd.DataFrame(columns=dd.REGIONS)
        ht_pds_datapoints.loc[2018] = ht_pds_adoption_initial
        ht_pds_datapoints.loc[2050] = ht_pds_adoption_final.fillna(0.0)
        self.ht = helpertables.HelperTables(ac=self.ac,
            ref_datapoints=ht_ref_datapoints, pds_datapoints=ht_pds_datapoints,
            pds_adoption_data_per_region=pds_adoption_data_per_region,
            ref_adoption_limits=ref_tam_per_region, pds_adoption_limits=pds_tam_per_region,
            ref_adoption_data_per_region=ref_adoption_data_per_region,
            use_first_pds_datapoint_main=False,
            copy_pds_to_ref=False, copy_ref_datapoint=False,
            pds_adoption_trend_per_region=pds_adoption_trend_per_region,
            pds_adoption_is_single_source=pds_adoption_is_single_source)

        self.ef = emissionsfactors.ElectricityGenOnGrid(ac=self.ac, grid_emissions_version=3)

        self.ua = unitadoption.UnitAdoption(ac=self.ac,
            ref_total_adoption_units=ref_tam_per_region,
            pds_total_adoption_units=pds_tam_per_region,
            soln_ref_funits_adopted=self.ht.soln_ref_funits_adopted(),
            soln_pds_funits_adopted=self.ht.soln_pds_funits_adopted(),
            bug_cfunits_double_count=True)
        soln_pds_tot_iunits_reqd = self.ua.soln_pds_tot_iunits_reqd()
        soln_ref_tot_iunits_reqd = self.ua.soln_ref_tot_iunits_reqd()
        conv_ref_tot_iunits = self.ua.conv_ref_tot_iunits()
        soln_net_annual_funits_adopted=self.ua.soln_net_annual_funits_adopted()

        self.fc = firstcost.FirstCost(ac=self.ac, pds_learning_increase_mult=2,
            ref_learning_increase_mult=2, conv_learning_increase_mult=2,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_tot_iunits=conv_ref_tot_iunits,
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            fc_convert_iunit_factor=1.0)

        self.oc = operatingcost.OperatingCost(ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            soln_pds_tot_iunits_reqd=soln_pds_tot_iunits_reqd,
            soln_ref_tot_iunits_reqd=soln_ref_tot_iunits_reqd,
            conv_ref_annual_tot_iunits=self.ua.conv_ref_annual_tot_iunits(),
            soln_pds_annual_world_first_cost=self.fc.soln_pds_annual_world_first_cost(),
            soln_ref_annual_world_first_cost=self.fc.soln_ref_annual_world_first_cost(),
            conv_ref_annual_world_first_cost=self.fc.conv_ref_annual_world_first_cost(),
            single_iunit_purchase_year=2017,
            soln_pds_install_cost_per_iunit=self.fc.soln_pds_install_cost_per_iunit(),
            conv_ref_install_cost_per_iunit=self.fc.conv_ref_install_cost_per_iunit(),
            conversion_factor=1.0)

        self.c4 = ch4calcs.CH4Calcs(ac=self.ac,
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted)

        self.c2 = co2calcs.CO2Calcs(ac=self.ac,
            ch4_ppb_calculator=self.c4.ch4_ppb_calculator(),
            soln_pds_net_grid_electricity_units_saved=self.ua.soln_pds_net_grid_electricity_units_saved(),
            soln_pds_net_grid_electricity_units_used=self.ua.soln_pds_net_grid_electricity_units_used(),
            soln_pds_direct_co2_emissions_saved=self.ua.soln_pds_direct_co2_emissions_saved(),
            soln_pds_direct_ch4_co2_emissions_saved=self.ua.soln_pds_direct_ch4_co2_emissions_saved(),
            soln_pds_direct_n2o_co2_emissions_saved=self.ua.soln_pds_direct_n2o_co2_emissions_saved(),
            soln_pds_new_iunits_reqd=self.ua.soln_pds_new_iunits_reqd(),
            soln_ref_new_iunits_reqd=self.ua.soln_ref_new_iunits_reqd(),
            conv_ref_new_iunits=self.ua.conv_ref_new_iunits(),
            conv_ref_grid_CO2_per_KWh=self.ef.conv_ref_grid_CO2_per_KWh(),
            conv_ref_grid_CO2eq_per_KWh=self.ef.conv_ref_grid_CO2eq_per_KWh(),
            soln_net_annual_funits_adopted=soln_net_annual_funits_adopted,
            fuel_in_liters=False)

        self.r2s = rrs.RRS(total_energy_demand=ref_tam_per_region.loc[2014, 'World'],
            soln_avg_annual_use=self.ac.soln_avg_annual_use,
            conv_avg_annual_use=self.ac.conv_avg_annual_use)