def func_graphics_storage_results_1scenario(input_data):

    # -------------------------------------------------------------------------

    optimization_results_file_path = input_data[
        "optimization_results_file_path"]
    directory_output = input_data["directory_output"]
    graphics_file_name = input_data["graphics_file_name"]
    SAVE_FIGURES_TO_PDF = input_data["SAVE_FIGURES_TO_PDF"]

    # -------------------------------------------------------------------------

    # load the optimization assumptions and results

    temp_dict = func_load_optimization_results(optimization_results_file_path)
    model_inputs = temp_dict['model_inputs']
    model_results = temp_dict['model_results']

    # -------------------------------------------------------------------------

    # Get the needed data and call the ploting function

    demand = model_inputs['demand']

    dispatched_storage_charge = model_results["dispatched_storage_charge"]
    dispatched_storage_discharge = model_results[
        "dispatched_storage_discharge"]
    storage_energy_soc = model_results["storage_energy_soc"]
    capacity_storage = model_results["capacity_storage"]

    inputs = {
        "storage_energy_soc": storage_energy_soc,
        "capacity_storage": capacity_storage,
        "dispatched_storage_discharge": dispatched_storage_discharge,
        "dispatched_storage_charge": dispatched_storage_charge,
        "demand": demand,
        "directory_output": directory_output,
        "graphics_file_name": graphics_file_name,
        "SAVE_FIGURES_TO_PDF": SAVE_FIGURES_TO_PDF,
    }

    # Call function

    #func_plotting_storage_static_1scenario(inputs)

    # Here is an outpudated information, which would generate figures to show
    #   the same information as in func_plotting_storage_static_1scenario().
    #   But instead of using subplots to combine figures, this _1() function
    #   generated each figure seperately.

    inputs["graphics_file_name"] = graphics_file_name + "_1"
    func_plotting_storage_static_1scenario_1(inputs)
Exemplo n.º 2
0
#    # Deal with dictionary variables
#
#    # First note that when you saved dict variables into .npz files and then retrieve
#    # them back, they have data_type = object (more accurately, it is a numpy.ndarray
#    # type), rather than dictionary, so you have to use them slightly differently.
#    # However, model_results.item() is a dictionary type variable.
#    # So, you access the files like these, model_results.item()['unmet_demand']
#
#elif DATA_TYPE == "pkl":
#
#    import pickle
#
#    file_path = "D:/M/\WorkCarnegie/Post_Processing/Results_Base/20180514/Without_NG/20180514_1e1/optimization_related.pkl"
#
#    f = open(file_path, 'rb')
#    model_inputs, model_results = pickle.load(f)

#%% Script

# optimization_results_data_type = 'pkl'
optimization_results_file_path = "D:/M/WorkCarnegie/Post_Processing/Results_Base/20180514/Without_NG/20180514_1e1/optimization_related.pkl"

#input_data = {
#        'optimization_results_data_type':   optimization_results_data_type,
#        'optimization_results_file_path':   optimization_results_file_path,
#        }

load_optimization = func_load_optimization_results(
    optimization_results_file_path)
model_inputs = load_optimization['model_inputs']
model_results = load_optimization['model_results']
Exemplo n.º 3
0
def func_storage_analysis_alternative_size(input_data):

    alternative_size_list = input_data['alternative_size_list']
    optimization_results_file_path = input_data[
        'optimization_results_file_path']
    SAVE_FIGURES_TO_PDF = input_data['SAVE_FIGURES_TO_PDF']
    directory_output = input_data['directory_output']
    graphics_file_name = input_data['graphics_file_name']
    scenario_name = input_data['scenario_name']

    # -------------------------------------------------------------------------

    #    # DATA_TYPE = 'pkl'
    #
    #    f = open(optimization_results_file_path, 'rb')
    #    model_inputs, model_results = pickle.load(f)

    temp_dict = func_load_optimization_results(optimization_results_file_path)
    model_inputs = temp_dict['model_inputs']
    model_results = temp_dict['model_results']

    # -------------------------------------------------------------------------

    # Previously imported, but never used

    # demand = model_inputs['demand']

    # -------------------------------------------------------------------------

    # Note that storage_optimization_charge and storage_optimization_discharge, are
    # both defined on the grid side.
    # so, from the storage perspective,
    # discharge* = storage_optimization_discharge / one-way efficiency
    # charge* = storage_optimization_charge * one-way efficiency

    storage_optimization_charge = model_results["dispatched_storage_charge"]
    storage_optimization_discharge = model_results[
        "dispatched_storage_discharge"]
    storage_optimization_capacity = model_results["capacity_storage"]
    storage_optimization_soc = model_results["storage_energy_soc"]
    storage_charging_efficiency = model_inputs["storage_charging_efficiency"]

    # -------------------------------------------------------------------------

    # Test:
    #   for any time step, discharging energy and charging energy cannot be both nonzero.
    #   In other word, the piece-by-piece product of the two variables should always be zero.

    test_variables = storage_optimization_charge * storage_optimization_discharge
    #    print 'Test: for any time step, can both discharging power flow and charging power folw be nonzero?'
    #    print 'Results (sum {discharging * charging)): ', np.sum(test_variables)

    if np.sum(test_variables) > 0:
        raise ValueError("Test failed")

    # -------------------------------------------------------------------------

    input_data = {
        # Core assumptions
        "storage_optimization_charge": storage_optimization_charge,
        "storage_optimization_discharge": storage_optimization_discharge,
        "storage_optimization_soc": storage_optimization_soc,
        "storage_optimization_capacity": storage_optimization_capacity,
        "storage_charging_efficiency": storage_charging_efficiency,
        "alternative_size": 1,
    }

    discharge_unmet_energy = np.zeros(alternative_size_list.shape)
    discharge_unmet_hours = np.zeros(alternative_size_list.shape)
    discharge_unmet_energy_percentage = np.zeros(alternative_size_list.shape)
    discharge_unmet_hours_percentage = np.zeros(alternative_size_list.shape)

    for i in xrange(alternative_size_list.size):

        input_data['alternative_size'] = alternative_size_list[i]

        # Call the function to do the analysis
        outputs = func_alternative_storage_analysis(input_data)

        discharge_unmet_energy[i] = outputs["discharge_unmet_energy"]
        discharge_unmet_energy_percentage[i] = outputs[
            "discharge_unmet_energy_percentage"]
        discharge_unmet_hours[i] = outputs["discharge_unmet_hours"]
        discharge_unmet_hours_percentage[i] = outputs[
            "discharge_unmet_hours_percentage"]

    # -----------------------

    # some additional calculations

    discharge_met_energy_percentage = (1 - discharge_unmet_energy_percentage)

    # Calculate the derivative

    discharge_met_energy_percentage_derivative = np.zeros(
        discharge_met_energy_percentage.size - 1)

    for i in xrange(discharge_met_energy_percentage_derivative.size):

        discharge_met_energy_percentage_derivative[i] = (
            (discharge_met_energy_percentage[i + 1] -
             discharge_met_energy_percentage[i]) /
            (alternative_size_list[i + 1] - alternative_size_list[i]))

    # -------------------------------------------------------------------------

    title_text = (scenario_name + "\n" + "capacity: {:0.0f}e6 kWh, ".format(
        storage_optimization_capacity / 1e6) +
                  "discharged in {:0.1f} eq. cycles, ".format(
                      np.sum(storage_optimization_discharge) /
                      storage_optimization_capacity) + "over {} hours".format(
                          np.count_nonzero(storage_optimization_discharge)))

    # Plotting

    input_data = {
        'storage_optimization_discharge': storage_optimization_discharge,
        'storage_optimization_capacity': storage_optimization_capacity,
        'alternative_size_list': alternative_size_list,
        'discharge_unmet_energy_percentage': discharge_unmet_energy_percentage,
        'discharge_unmet_hours': discharge_unmet_hours,
        'discharge_met_energy_percentage': discharge_met_energy_percentage,
        'discharge_met_energy_percentage_derivative':
        discharge_met_energy_percentage_derivative,
        'SAVE_FIGURES_TO_PDF': SAVE_FIGURES_TO_PDF,
        'directory_output': directory_output,
        'graphics_file_name': graphics_file_name,
        'title_text': title_text,
    }

    # call the function to plot figures
    func_alternative_storage_plotting(input_data)
Exemplo n.º 4
0
storage_scenario_list = ['1e-2']
ng_scenario_list = ['without_NG']

# ------------------------------

# actually load the data

for ng_scenario, storage_scenario in product(ng_scenario_list,
                                             storage_scenario_list):

    optimization_results_file_path = directory_project + \
        "Results_Base/20180514/{}/20180514_{}/optimization_related.pkl".format(ng_scenario, storage_scenario)

    graphics_file_name = "Storage_analysis_alternative_size_" + storage_scenario + "_" + ng_scenario

    scenario_name = "storage cost: " + storage_scenario + "$/kWh, " + ng_scenario

    input_data = {
        "alternative_size_list": alternative_size_list,
        "optimization_results_file_path": optimization_results_file_path,
        "SAVE_FIGURES_TO_PDF": SAVE_FIGURES_TO_PDF,
        "directory_output": directory_output,
        "graphics_file_name": graphics_file_name,
        "scenario_name": scenario_name,
    }

    func_storage_analysis_alternative_size(input_data)

    temp_dict = func_load_optimization_results(optimization_results_file_path)
    model_inputs = temp_dict['model_inputs']
    model_results = temp_dict['model_results']