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
def plot_pie( interconnect, time, scenario_ids=None, scenario_names=None, custom_data=None, min_percentage=0, ): """Plot any number of scenarios as pie charts with two columns per scenario - defaults to generation and capacity. :param str interconnect: either 'Western' or 'Texas'. :param tuple time: time related parameters. 1st element is the starting date. 2nd element is the ending date (left out). 3rd element is the timezone, only *'utc'*, *'US/Pacific'* and *'local'* are possible. 4th element is the frequency, which can be *'H'* (hour), *'D'* (day), *'W'* (week) or *'auto'*. :param list scenario_ids: list of scenario ids, defaults to None. :param list scenario_names: list of scenario names of same length as scenario ids, defaults to None. :param dict custom_data: hand-generated data, defaults to None. :param float min_percentage: roll up small pie pieces into an Other category, defaults to 0. .. note:: if you want to plot scenario data and custom data together, custom data MUST be in TWh for generation and GW for capacity. We may add a feature to check for and convert to equal units but it's not currently a priority. """ zone_list, graph_data = handle_plot_inputs(interconnect, time, scenario_ids, scenario_names, custom_data) for zone in zone_list: ax_data_list = _construct_pie_ax_data(zone, graph_data, min_percentage) _construct_pie_visuals(zone, ax_data_list) print("\nDone\n")
def plot_hbar( interconnect, time, scenario_ids=None, scenario_names=None, custom_data=None, resource_types=None, ): """Plot any number of scenarios as horizontal bar charts with two columns per scenario - defaults to generation and capacity. :param str interconnect: either 'Western' or 'Texas'. :param tuple time: time related parameters. 1st element is the starting date. 2nd element is the ending date (left out). 3rd element is the timezone, only *'utc'*, *'US/Pacific'* and *'local'* are possible. 4th element is the frequency, which can be *'H'* (hour), *'D'* (day), *'W'* (week) or *'auto'*. :param list scenario_ids: list of scenario ids, defaults to None. :param list scenario_names: list of scenario names of same len as scenario ids, defaults to None :param custom_data: hand-generated data as returned by :func:`postreise.plot.multi.plot_helpers.handle_plot_inputs`, defaults to None. :param list resource_types: list of resource types to show, defaults to None. .. note:: If you want to plot scenario data and custom data together, custom data MUST be in TWh for generation and GW for capacity. We may add a feature to check for and convert to equal units but it's not currently a priority. """ zone_list, graph_data = handle_plot_inputs( interconnect, time, scenario_ids, scenario_names, custom_data ) for zone in zone_list: ax_data_list = _construct_bar_ax_data(zone, graph_data, resource_types) _construct_hbar_visuals(zone, ax_data_list) print("\nDone\n")
def test_handle_plot_inputs_throws_valueError_if_not_enough_scenario_ids_or_custom_data( ): time = ("2016-01-01-00", "2016-12-31-23", "utc", "H") with pytest.raises(ValueError): handle_plot_inputs("Western", time, ["123"], None, custom_data=None)
def test_handle_plot_inputs_throws_valueError_when_wrong_number_of_scenario_names( ): time = ("2016-01-01-00", "2016-12-31-23", "utc", "H") with pytest.raises(ValueError): handle_plot_inputs("Western", time, ["123", "456"], ["Hist. Moon Cheese"], None)
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())
def plot_shortfall( interconnect, time, scenario_ids=None, scenario_names=None, custom_data=None, is_match_CA=False, has_collaborative_scenarios=None, baselines=None, targets=None, demand=None, ): """Plot a stacked bar chart of generation shortfall for any number of scenarios. :param str interconnect: currently only 'Western' works. We include this param to keep a consistent API with all plotting functions. :param tuple time: time related parameters. 1st element is the starting date. 2nd element is the ending date (left out). 3rd element is the timezone, only *'utc'*, *'US/Pacific'* and *'local'* are possible. 4th element is the frequency, which can be *'H'* (hour), *'D'* (day), *'W'* (week) or *'auto'*. :param list scenario_ids: list of scenario ids. :param list scenario_names: list of scenario names of same len as scenario ids. :param dict custom_data: hand-generated data, defaults to None. :param bool is_match_CA: calculate shortfall using special rules that apply when all zones match California goals, defaults to False :param list has_collaborative_scenarios: list of scenario ids where all zones collaborate to meet goals. Affects results for interconnect, defaults to None. :param dict baselines: baseline renewables generation for each zone, defaults to None. :param dict targets: target renewables renewable generation for each zone, defaults to None. :param dict demand: total demand for each zone, defaults to None .. note:: If you want to plot scenario data and custom data together, custom data MUST be in TWh for generation and GW for capacity. We may add a feature to check for and convert to equal units but it's not currently a priority. """ zone_list, graph_data = handle_plot_inputs(interconnect, time, scenario_ids, scenario_names, custom_data) baselines, targets, demand = handle_shortfall_inputs( is_match_CA, baselines, targets, demand) for zone in zone_list: if zone == "Western": ax_data, shortfall_pct_list = _construct_shortfall_data_for_western( graph_data, is_match_CA, has_collaborative_scenarios, baselines[zone], targets, demand[zone], ) else: ax_data, shortfall_pct_list = _construct_shortfall_ax_data( zone, graph_data, is_match_CA, baselines[zone], targets[zone], demand[zone], ) _construct_shortfall_visuals(zone, ax_data, shortfall_pct_list, is_match_CA, targets[zone], demand[zone]) print("\nDone\n")