Exemple #1
0
def test_construct_shortfall_data_for_western_with_independent_scenario():
    mock_targets = {"Arizona": 12, "Colorado": 8, "Oregon": 10, "Western": 30}
    ax_data, shortfall_pct_list = _construct_shortfall_data_for_western(
        create_mock_graph_data(more_gen=True),
        is_match_CA=False,
        has_collaborative_scenarios=None,
        baseline=13,
        targets=mock_targets,
        demand=50,
    )
    expected_data = {
        "2016 Simulated Base Case": {
            "2016 Renewables": 13,
            # western target - shortfall - baseline
            "Simulated increase in renewables": 9.0,
            "Missed target": 8.0,
        },
        "2016 NREL Data": {
            "2016 Renewables": 13,
            # western target - shortfall - baseline
            "Simulated increase in renewables": 14.0,
            "Missed target": 3.0,
        },
    }
    assert ax_data == expected_data
    assert shortfall_pct_list == [16.0, 6.0]
def test_handle_plot_inputs():
    mock_graph_data = create_mock_graph_data()
    time = ("2016-01-01-00", "2016-12-31-23", "utc", "H")
    zone_list, graph_data = handle_plot_inputs("Western", time, None, None,
                                               mock_graph_data)
    assert zone_list == ZONES["Western"]
    assert graph_data == mock_graph_data
Exemple #3
0
def test_construct_pie_ax_data():
    ax_data_list = _construct_pie_ax_data("Washington",
                                          create_mock_graph_data(),
                                          min_percentage=0)
    expected_output = [
        {
            "title":
            "2016 Simulated Base Case\nGeneration",
            "labels": ["Coal", "Solar", "Hydro"],
            "values": [4, 1, 5],
            "colors": [
                RESOURCE_COLORS["coal"],
                RESOURCE_COLORS["solar"],
                RESOURCE_COLORS["hydro"],
            ],
            "unit":
            "TWh",
        },
        {
            "title":
            "2016 Simulated Base Case\nCapacity",
            "labels": ["Coal", "Solar", "Hydro"],
            "values": [5, 1, 4],
            "colors": [
                RESOURCE_COLORS["coal"],
                RESOURCE_COLORS["solar"],
                RESOURCE_COLORS["hydro"],
            ],
            "unit":
            "GW",
        },
        {
            "title":
            "2016 NREL Data\nGeneration",
            "labels": ["Coal", "Solar", "Hydro"],
            "values": [4, 1, 5],
            "colors": [
                RESOURCE_COLORS["coal"],
                RESOURCE_COLORS["solar"],
                RESOURCE_COLORS["hydro"],
            ],
            "unit":
            "TWh",
        },
        {
            "title":
            "2016 NREL Data\nCapacity",
            "labels": ["Coal", "Solar", "Hydro", "Wind"],
            "values": [3, 1, 4, 2],
            "colors": [
                RESOURCE_COLORS["coal"],
                RESOURCE_COLORS["solar"],
                RESOURCE_COLORS["hydro"],
                RESOURCE_COLORS["wind"],
            ],
            "unit":
            "GW",
        },
    ]
    assert ax_data_list == expected_output
def test_construct_bar_ax_data_with_user_set_resource_types():
    ax_data_list = _construct_bar_ax_data("Washington",
                                          create_mock_graph_data(),
                                          ["wind", "solar"])
    expected_output = [
        {
            "title": "Generation (TWh)",
            "labels": ["Wind", "Solar"],
            "values": {
                "2016 Simulated Base Case": [0, 1],
                "2016 NREL Data": [0, 1]
            },
            "unit": "TWh",
        },
        {
            "title": "Capacity (GW)",
            "labels": ["Wind", "Solar"],
            "values": {
                "2016 Simulated Base Case": [0, 1],
                "2016 NREL Data": [2, 1]
            },
            "unit": "GW",
        },
    ]
    assert ax_data_list == expected_output
def test_construct_bar_ax_data_fills_in_missing_resources_with_0():
    ax_data_list = _construct_bar_ax_data("Washington",
                                          create_mock_graph_data(), None)
    assert ax_data_list[1]["labels"] == ["Wind", "Solar", "Coal", "Hydro"]
    assert ax_data_list[1]["values"] == {
        "2016 Simulated Base Case": [0, 1, 5, 4],
        "2016 NREL Data": [2, 1, 3, 4],
    }
def test_get_bar_resource_types_handles_resource_types_not_found_in_known_resource_types(
):
    mock_graph_data = create_mock_graph_data()
    mock_graph_data["87"]["gen"]["data"]["Washington"] = {
        "cereal": 1,
        "coal": 2,
        "milk": 1,
        "bananas": 3,
    }
    resource_types = _get_bar_resource_types("Washington", mock_graph_data)
    assert resource_types == [
        "wind",
        "solar",
        "coal",
        "hydro",
        "bananas",
        "cereal",
        "milk",
    ]
Exemple #7
0
def test_construct_shortfall_ax_data_when_target_is_zero():
    ax_data, shortfall_pct_list = _construct_shortfall_ax_data(
        "Washington",
        create_mock_graph_data(),
        is_match_CA=False,
        baseline=4,
        target=0,
        demand=20,
    )
    expected_data = {
        "2016 Simulated Base Case": {
            "2016 Renewables": 4,
            "Simulated increase in renewables": 2.0,
            "Missed target": 0,
        },
        "2016 NREL Data": {
            "2016 Renewables": 4,
            "Simulated increase in renewables": 2.0,
            "Missed target": 0,
        },
    }
    assert ax_data == expected_data
    assert shortfall_pct_list == [0.0, 0.0]
def test_construct_bar_ax_data():
    ax_data_list = _construct_bar_ax_data("Washington",
                                          create_mock_graph_data(), None)
    expected_output = [
        {
            "title": "Generation (TWh)",
            "labels": ["Wind", "Solar", "Coal", "Hydro"],
            "values": {
                "2016 Simulated Base Case": [0, 1, 4, 5],
                "2016 NREL Data": [0, 1, 4, 5],
            },
            "unit": "TWh",
        },
        {
            "title": "Capacity (GW)",
            "labels": ["Wind", "Solar", "Coal", "Hydro"],
            "values": {
                "2016 Simulated Base Case": [0, 1, 5, 4],
                "2016 NREL Data": [2, 1, 3, 4],
            },
            "unit": "GW",
        },
    ]
    assert ax_data_list == expected_output
def test_format_scenario_data():
    formatted_scenario_data = _format_scenario_data(
        create_mock_data_chart(), "2016 Simulated Base Case")
    expected_result = create_mock_graph_data()["87"]
    assert formatted_scenario_data == expected_result
def test_handle_plot_inputs_throws_valueError_for_incorrect_interconnect():
    time = ("2016-01-01-00", "2016-12-31-23", "utc", "H")
    with pytest.raises(ValueError):
        handle_plot_inputs("The Moon", time, None, None,
                           create_mock_graph_data())
Exemple #11
0
def test_get_bar_resource_types_includes_resource_types_only_present_in_some_scenarios(
):
    resource_types = _get_bar_resource_types("Washington",
                                             create_mock_graph_data())
    assert "wind" in resource_types
Exemple #12
0
def test_get_bar_resource_types_does_not_have_duplicates():
    resource_types = _get_bar_resource_types("Washington",
                                             create_mock_graph_data())
    assert resource_types.sort() == list(set(resource_types)).sort()
Exemple #13
0
def test_get_bar_resource_types():
    resource_types = _get_bar_resource_types("Washington",
                                             create_mock_graph_data())
    assert resource_types == ["wind", "solar", "coal", "hydro"]