def setup_module(m_args):
    """Run the simulation up to module E0 and save dict_values before and after evaluation"""
    if os.path.exists(TEST_OUTPUT_PATH):
        shutil.rmtree(TEST_OUTPUT_PATH, ignore_errors=True)
    user_input = A0.process_user_arguments()

    logging.debug("Accessing script: B0_data_input_json")
    dict_values = B0.load_json(
        user_input[PATH_INPUT_FILE],
        path_input_folder=user_input[PATH_INPUT_FOLDER],
        path_output_folder=user_input[PATH_OUTPUT_FOLDER],
        move_copy=False,
    )
    logging.debug("Accessing script: C0_data_processing")
    C0.all(dict_values)

    logging.debug("Accessing script: D0_modelling_and_optimization")
    results_meta, results_main = D0.run_oemof(dict_values)

    with open(DICT_BEFORE, "wb") as handle:
        pickle.dump(dict_values, handle, protocol=pickle.HIGHEST_PROTOCOL)

    logging.debug("Accessing script: E0_evaluation")
    E0.evaluate_dict(dict_values, results_main, results_meta)

    with open(DICT_AFTER, "wb") as handle:
        pickle.dump(dict_values, handle, protocol=pickle.HIGHEST_PROTOCOL)
Exemple #2
0
def test_get_name_or_names_of_in_or_output_bus_single():
    bus = "bus"
    bus_with_suffix = C0.bus_suffix(bus)
    bus_name = C0.get_name_or_names_of_in_or_output_bus(bus)
    assert (
        bus_name == bus_with_suffix
    ), f"A bus label with a string value is not appeded by the bus suffix."
Exemple #3
0
    def setup_class(m_args):
        """Run the simulation up to module E0 and prepare bus_data for E1"""
        if os.path.exists(TEST_OUTPUT_PATH):
            shutil.rmtree(TEST_OUTPUT_PATH, ignore_errors=True)

        logging.debug("Accessing script: A0_initialization")
        user_input = A0.process_user_arguments()

        A1.create_input_json(input_directory=os.path.join(
            user_input[PATH_INPUT_FOLDER], CSV_ELEMENTS))

        logging.debug("Accessing script: B0_data_input_json")
        dict_values = B0.load_json(
            user_input[PATH_INPUT_FILE],
            path_input_folder=user_input[PATH_INPUT_FOLDER],
            path_output_folder=user_input[PATH_OUTPUT_FOLDER],
            move_copy=True,
            set_default_values=True,
        )
        logging.debug("Accessing script: C0_data_processing")
        C0.all(dict_values)

        logging.debug("Accessing script: D0_modelling_and_optimization")
        results_meta, results_main = D0.run_oemof(dict_values)

        bus_data = {}
        # Store all information related to busses in bus_data
        for bus in dict_values[ENERGY_BUSSES]:
            # Read all energy flows from busses
            bus_data.update({bus: solph.views.node(results_main, bus)})

        # Pickle dump bus data
        with open(BUS_DATA_DUMP, "wb") as handle:
            pickle.dump(bus_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
Exemple #4
0
def test_process_maximum_cap_constraint_subasset():
    """For storages, the subassets have to be processes. This tests the procedure examplary."""
    dict_values = {
        group: {
            asset: {
                subasset: {
                    LABEL: asset,
                    UNIT: unit,
                    MAXIMUM_CAP: {
                        VALUE: None
                    },
                }
            }
        }
    }

    C0.process_maximum_cap_constraint(dict_values,
                                      group,
                                      asset,
                                      subasset=subasset)
    assert (
        dict_values[group][asset][subasset][MAXIMUM_CAP][VALUE] is None
    ), f"The function does not change the previously defined MAXIMUM_CAP."
    assert (
        dict_values[group][asset][subasset][MAXIMUM_CAP][UNIT] == unit
    ), f"The maximumCap is in {dict_values[group][asset][subasset][MAXIMUM_CAP][UNIT]}, while the asset itself has unit {dict_values[group][asset][subasset][UNIT]}."
Exemple #5
0
def test_add_busses_of_asset_depending_on_in_out_direction_single():
    bus_names = ["bus_name_" + str(i) for i in range(1, 3)]
    asset_name = "asset"
    asset_label = "asset_label"
    energy_vector = "Electricity"
    dict_test = {
        ENERGY_BUSSES: {},
        ENERGY_CONVERSION: {
            asset_name: {
                LABEL: asset_label,
                OUTFLOW_DIRECTION: bus_names[0],
                INFLOW_DIRECTION: bus_names[1],
                ENERGY_VECTOR: energy_vector,
            }
        },
    }
    C0.add_busses_of_asset_depending_on_in_out_direction(
        dict_test, dict_test[ENERGY_CONVERSION][asset_name], asset_name)
    for k in bus_names:
        assert (k + BUS_SUFFIX in dict_test[ENERGY_BUSSES].keys()
                ), f"Bus {k+BUS_SUFFIX} is not added to the {ENERGY_BUSSES}."

    for bus in dict_test[ENERGY_BUSSES].keys():
        assert (asset_name in dict_test[ENERGY_BUSSES][bus][ASSET_DICT].keys(
        )), f"Asset {asset_name} is not included in the asset list of {bus}."
        assert (
            dict_test[ENERGY_BUSSES][bus][ASSET_DICT][asset_name] ==
            asset_label
        ), f"The asset label of asset {asset_name} in the asset list of {bus} is of unexpected value."
Exemple #6
0
def test_process_maximum_cap_constraint_maximumCap_is_0():
    """The asset has no maximumCapacity, and the entry is translated into a unit-value pair."""
    maxCap = 0

    dict_values = {
        group: {
            asset: {
                UNIT: unit,
                INSTALLED_CAP: {
                    VALUE: installed_cap
                },
                MAXIMUM_CAP: {
                    VALUE: maxCap
                },
            }
        }
    }
    with pytest.warns(UserWarning):
        C0.process_maximum_cap_constraint(dict_values,
                                          group,
                                          asset,
                                          subasset=None)
        assert (
            dict_values[group][asset][MAXIMUM_CAP][VALUE] is None
        ), f"The initial maximumCap defined by the end-user ({maxCap}) is overwritten by a different value ({dict_values[group][asset][MAXIMUM_CAP][VALUE]})."
Exemple #7
0
def test_process_maximum_cap_constraint_maximumCap_is_int_smaller_than_installed_cap(
):
    """"The asset has a maximumCap < installedCap which is invalid and being ignored."""
    maxCap = 10
    dict_values = {
        group: {
            asset: {
                UNIT: unit,
                INSTALLED_CAP: {
                    VALUE: installed_cap
                },
                MAXIMUM_CAP: {
                    VALUE: maxCap
                },
            }
        }
    }
    with pytest.warns(UserWarning):
        C0.process_maximum_cap_constraint(dict_values,
                                          group,
                                          asset,
                                          subasset=None)
        assert (
            dict_values[group][asset][MAXIMUM_CAP][VALUE] is None
        ), f"The invalid input is not ignored by defining maximumCap as None."
Exemple #8
0
def test_update_bus():
    bus_name = "bus_name"
    asset_name = "asset"
    asset_label = "asset_label"
    energy_vector = "Electricity"
    dict_test = {
        ENERGY_BUSSES: {},
        ENERGY_CONVERSION: {
            asset_name: {
                LABEL: asset_label,
                OUTFLOW_DIRECTION: bus_name,
                ENERGY_VECTOR: energy_vector,
            }
        },
    }
    bus_label = C0.bus_suffix(bus_name)
    C0.update_bus(
        dict_values=dict_test,
        bus=bus_name,
        asset_key=asset_name,
        asset_label=asset_label,
        energy_vector=energy_vector,
    )
    assert (bus_label in dict_test[ENERGY_BUSSES]
            ), f"The {bus_label} is not added to the {ENERGY_BUSSES}."
    assert (
        asset_name in dict_test[ENERGY_BUSSES][bus_label][ASSET_DICT]
    ), f"The asset {asset_name} is not added to the list of assets attached to the bus."
    assert (
        dict_test[ENERGY_BUSSES][bus_label][ASSET_DICT][asset_name] ==
        asset_label
    ), f"The asset {asset_name} is not added with its {LABEL} to the list of assets attached to the bus."
    assert (
        dict_test[ENERGY_BUSSES][bus_label][ENERGY_VECTOR] == energy_vector
    ), f"The {ENERGY_VECTOR} of the added bus is not of the expected value."
Exemple #9
0
def test_process_maximum_cap_constraint_group_is_ENERGY_PRODUCTION_non_dispatchable_asset(
):
    """The asset belongs to the energy production group, and is a non-dispatchable asset.
    As the maximumCap is used to define the maximum capacity of an asset, but used in oemof-solph to limit a flow, the value has to be translated."""
    timeseries_peak = 0.8
    group = ENERGY_PRODUCTION
    maxCap = 100
    dict_values = {
        group: {
            asset: {
                LABEL: asset,
                UNIT: unit,
                INSTALLED_CAP: {
                    VALUE: installed_cap
                },
                MAXIMUM_CAP: {
                    VALUE: maxCap
                },
                FILENAME: "a_name",
                TIMESERIES_PEAK: {
                    VALUE: timeseries_peak
                },
            }
        }
    }
    C0.process_maximum_cap_constraint(dict_values, group, asset, subasset=None)
    assert (
        dict_values[group][asset][MAXIMUM_CAP][VALUE] == maxCap *
        timeseries_peak
    ), f"The initial maximumCap defined by the end-user ({maxCap}) is overwritten by a different value ({dict_values[group][asset][MAXIMUM_CAP][VALUE]})."
Exemple #10
0
def test_check_if_energy_carrier_is_defined_in_DEFAULT_WEIGHTS_ENERGY_CARRIERS_pass(
):
    # Function only needs to pass
    C0.check_if_energy_carrier_is_defined_in_DEFAULT_WEIGHTS_ENERGY_CARRIERS(
        "Electricity", "asset_group", "asset")
    assert (
        1 == 1
    ), f"The energy carrier `Electricity` is not recognized to be defined in `DEFAULT_WEIGHTS_ENERGY_CARRIERS`."
def run_simulation(json_dict, **kwargs):
    r"""
     Starts MVS tool simulation from an input json file

     Parameters
    -----------
     json_dict: dict
         json from http request

     Other Parameters
     ----------------
     pdf_report: bool, optional
         Can generate an automatic pdf report of the simulation's results (True) or not (False)
         Default: False.
     display_output : str, optional
         Sets the level of displayed logging messages.
         Options: "debug", "info", "warning", "error". Default: "info".
     lp_file_output : bool, optional
         Specifies whether linear equation system generated is saved as lp file.
         Default: False.
    """

    welcome_text = (
        "\n \n Multi-Vector Simulation Tool (MVS) V" + version_num + " " +
        "\n Version: " + version_date + " " +
        '\n Part of the toolbox of H2020 project "E-LAND", ' +
        "Integrated multi-vector management system for Energy isLANDs" +
        "\n Coded at: Reiner Lemoine Institute (Berlin) " +
        "\n Contributors: Martha M. Hoffmann \n \n ")

    logging.info(welcome_text)

    logging.debug("Accessing script: B0_data_input_json")
    dict_values = data_input.convert_from_json_to_special_types(json_dict)

    print("")
    logging.debug("Accessing script: C0_data_processing")
    data_processing.all(dict_values)

    print("")
    logging.debug("Accessing script: D0_modelling_and_optimization")
    results_meta, results_main = modelling.run_oemof(dict_values)

    print("")
    logging.debug("Accessing script: E0_evaluation")
    evaluation.evaluate_dict(dict_values, results_main, results_meta)

    logging.debug("Convert results to json")

    epa_dict_values = data_parser.convert_mvs_params_to_epa(dict_values)

    output_processing.select_essential_results(epa_dict_values)

    json_values = output_processing.store_as_json(epa_dict_values)

    return json.loads(json_values)
Exemple #12
0
def test_process_maximum_cap_constraint_maximumCap_is_None():
    """The asset has a maximumCap==None, and a unit is added."""
    dict_values = {group: {asset: {UNIT: unit, MAXIMUM_CAP: {VALUE: None}}}}
    C0.process_maximum_cap_constraint(dict_values, group, asset, subasset=None)
    assert (
        dict_values[group][asset][MAXIMUM_CAP][VALUE] is None
    ), f"Eventhough there is no limit imposed to the asset capacity, its maximumCap is defined to be {dict_values[group][asset][MAXIMUM_CAP][VALUE]}."
    assert (
        dict_values[group][asset][MAXIMUM_CAP][UNIT] == unit
    ), f"The maximumCap is in {dict_values[group][asset][MAXIMUM_CAP][UNIT]}, while the asset itself has unit {dict_values[group][asset][UNIT]}."
Exemple #13
0
def test_evaluate_lifetime_costs():
    settings = {EVALUATED_PERIOD: {VALUE: 10}}
    economic_data = {
        PROJECT_DURATION: {
            VALUE: 20
        },
        DISCOUNTFACTOR: {
            VALUE: 0.1
        },
        TAX: {
            VALUE: 0
        },
        CRF: {
            VALUE: 0.1
        },
        ANNUITY_FACTOR: {
            VALUE: 7
        },
    }

    dict_asset = {
        SPECIFIC_COSTS_OM: {
            VALUE: 5,
            UNIT: "unit"
        },
        SPECIFIC_COSTS: {
            VALUE: 100,
            UNIT: "unit"
        },
        DISPATCH_PRICE: {
            VALUE: 1,
            UNIT: "unit"
        },
        LIFETIME: {
            VALUE: 10
        },
        UNIT: UNIT,
        AGE_INSTALLED: {
            VALUE: 0
        },
    }

    C0.evaluate_lifetime_costs(settings, economic_data, dict_asset)

    # Note: Only the relevant keys are tested here. The valid calculation of the costs is tested with test_benchmark_KPI.py, Test_Economic_KPI.test_benchmark_Economic_KPI_C2_E2()
    for k in [
            LIFETIME_SPECIFIC_COST,
            LIFETIME_SPECIFIC_COST_OM,
            ANNUITY_SPECIFIC_INVESTMENT_AND_OM,
            SIMULATION_ANNUITY,
            LIFETIME_PRICE_DISPATCH,
            SPECIFIC_REPLACEMENT_COSTS_INSTALLED,
            SPECIFIC_REPLACEMENT_COSTS_OPTIMIZED,
    ]:
        assert k in dict_asset, f"Function does not add {k} to the asset dictionary."
Exemple #14
0
def test_evaluate_lifetime_costs_adds_all_parameters():
    C0.evaluate_lifetime_costs(settings, economic_data, dict_asset)
    for k in (
            LIFETIME_SPECIFIC_COST,
            ANNUITY_SPECIFIC_INVESTMENT_AND_OM,
            LIFETIME_SPECIFIC_COST_OM,
            LIFETIME_PRICE_DISPATCH,
            SIMULATION_ANNUITY,
            SPECIFIC_REPLACEMENT_COSTS_OPTIMIZED,
            SPECIFIC_REPLACEMENT_COSTS_INSTALLED,
    ):
        assert (k in dict_asset.keys()
                ), f"Function does not add {k} to the asset dictionary."
Exemple #15
0
def test_process_maximum_cap_constraint_maximumCap_undefined():
    """If no maximum cap is defined previously, it is defined as none."""
    dict_values = {group: {asset: {UNIT: unit}}}
    C0.process_maximum_cap_constraint(dict_values, group, asset, subasset=None)
    assert (
        MAXIMUM_CAP in dict_values[group][asset]
    ), f"The function does not add a MAXIMUM_CAP to the asset dictionary."
    assert (
        dict_values[group][asset][MAXIMUM_CAP][VALUE] is None
    ), f"Eventhough there is no limit imposed to the asset capacity, its maximumCap is defined to be {dict_values[group][asset][MAXIMUM_CAP][VALUE]}."
    assert (
        dict_values[group][asset][MAXIMUM_CAP][UNIT] == unit
    ), f"The maximumCap is in {dict_values[group][asset][MAXIMUM_CAP][UNIT]}, while the asset itself has unit {dict_values[group][asset][UNIT]}."
Exemple #16
0
def test_add_economic_parameters():
    economic_parameters = {
        PROJECT_DURATION: {
            VALUE: 20
        },
        DISCOUNTFACTOR: {
            VALUE: 0.15
        },
    }
    C0.add_economic_parameters(economic_parameters)
    # the actual value of the annuity factor should have been checked in C2
    for k in (ANNUITY_FACTOR, CRF):
        assert (k in economic_parameters.keys()
                ), f"Function does not add {k} to the economic parameters."
Exemple #17
0
def test_define_transformer_for_peak_demand_pricing():
    dict_test = {
        ENERGY_CONVERSION: {},
        ENERGY_PROVIDERS: {
            "dso": {
                LABEL: "a_label",
                INFLOW_DIRECTION: "a_direction",
                OUTFLOW_DIRECTION: "b_direction",
                PEAK_DEMAND_PRICING: {
                    VALUE: 60
                },
                UNIT: "unit",
                ENERGY_VECTOR: "a_vector",
            }
        },
    }
    dict_test_dso = dict_test[ENERGY_PROVIDERS]["dso"].copy()
    transformer_name = "a_name"
    timeseries_availability = pd.Series()
    C0.define_transformer_for_peak_demand_pricing(dict_test, dict_test_dso,
                                                  transformer_name,
                                                  timeseries_availability)
    assert transformer_name in dict_test[ENERGY_CONVERSION]
    for k in [
            LABEL,
            OPTIMIZE_CAP,
            INSTALLED_CAP,
            INFLOW_DIRECTION,
            OUTFLOW_DIRECTION,
            AVAILABILITY_DISPATCH,
            DISPATCH_PRICE,
            SPECIFIC_COSTS,
            DEVELOPMENT_COSTS,
            SPECIFIC_COSTS_OM,
            OEMOF_ASSET_TYPE,
            INPUT_BUS_NAME,
            OUTPUT_BUS_NAME,
            EFFICIENCY,
            ENERGY_VECTOR,
    ]:
        assert (
            k in dict_test[ENERGY_CONVERSION][transformer_name]
        ), f"Function does not add {k} to the asset dictionary of the {transformer_name}."
    assert (
        dict_test[ENERGY_CONVERSION][transformer_name][SPECIFIC_COSTS_OM]
        [VALUE] == dict_test[ENERGY_PROVIDERS]["dso"][PEAK_DEMAND_PRICING]
        [VALUE]
    ), f"The {SPECIFIC_COSTS_OM} of the newly defined {transformer_name} is not equal to the {PEAK_DEMAND_PRICING} of the energy provider it is defined from."
Exemple #18
0
def test_define_availability_of_peak_demand_pricing_assets_yearly():
    dict_availability_timeseries = C0.define_availability_of_peak_demand_pricing_assets(
        dict_test_avilability, 1, 12)
    assert (
        len(dict_availability_timeseries) == 1
    ), f"Function does not create a single availability_timeseries for the whole year."
    assert (
        dict_availability_timeseries[1].values.sum() == 8760
    ), f"Availablity of a single dict_availability_timeseries is not ensured for every hour of the year."
Exemple #19
0
def test_apply_function_to_single_or_list_apply_to_single():
    def multiply(parameter):
        parameter_processed = 2 * parameter
        return parameter_processed

    parameter = 1
    parameter_processed = C0.apply_function_to_single_or_list(
        multiply, parameter)
    assert parameter_processed == 2, f"The multiplication with a single value fails."
Exemple #20
0
def test_apply_function_to_single_or_list_apply_to_list():
    def multiply(parameter):
        parameter_processed = 2 * parameter
        return parameter_processed

    parameter = [1, 1]
    parameter_processed = C0.apply_function_to_single_or_list(
        multiply, parameter)
    assert parameter_processed == [2,
                                   2], f"The multiplication with a list fails."
        def run_parts(margs):
            if os.path.exists(TEST_OUTPUT_PATH):
                shutil.rmtree(TEST_OUTPUT_PATH, ignore_errors=True)
            user_input = A0.process_user_arguments()

            logging.debug("Accessing script: B0_data_input_json")
            dict_values = B0.load_json(
                user_input[PATH_INPUT_FILE],
                path_input_folder=user_input[PATH_INPUT_FOLDER],
                path_output_folder=user_input[PATH_OUTPUT_FOLDER],
                move_copy=False,
            )
            logging.debug("Accessing script: C0_data_processing")
            C0.all(dict_values)

            logging.debug("Run parts of D0_modelling_and_optimization")
            model, dict_model = D0.model_building.initialize(dict_values)
            model = D0.model_building.adding_assets_to_energysystem_model(
                dict_values, dict_model, model)
            return dict_values, model, dict_model
Exemple #22
0
def test_define_availability_of_peak_demand_pricing_assets_quarterly():
    dict_availability_timeseries = C0.define_availability_of_peak_demand_pricing_assets(
        dict_test_avilability, 4, 3)
    assert (
        len(dict_availability_timeseries) == 4
    ), f"Function does not create 4 individual availability_timeseries for the whole year."
    total = 0
    for key in dict_availability_timeseries:
        total += dict_availability_timeseries[key].values.sum()
    assert (
        total == 8760
    ), f"Availablity of all 12 availability_timeseries does not insure availability every hour of the year."
Exemple #23
0
def test_process_maximum_cap_constraint_maximumCap_is_float():
    """The asset has a maximumCap of float, and a unit is added"""
    maxCap = 100.1
    dict_values = {
        group: {
            asset: {
                UNIT: unit,
                INSTALLED_CAP: {
                    VALUE: installed_cap
                },
                MAXIMUM_CAP: {
                    VALUE: maxCap
                },
            }
        }
    }
    C0.process_maximum_cap_constraint(dict_values, group, asset, subasset=None)
    assert (
        dict_values[group][asset][MAXIMUM_CAP][VALUE] == maxCap
    ), f"The initial maximumCap defined by the end-user ({maxCap}) is overwritten by a different value ({dict_values[group][asset][MAXIMUM_CAP][VALUE]})."
    assert (
        dict_values[group][asset][MAXIMUM_CAP][UNIT] == unit
    ), f"The maximumCap is in {dict_values[group][asset][MAXIMUM_CAP][UNIT]}, while the asset itself has unit {dict_values[group][asset][UNIT]}."
Exemple #24
0
def test_process_maximum_cap_constraint_group_is_ENERGY_PRODUCTION_fuel_source(
):
    """The asset belongs to the energy production group, but is a dispatchable fuel source. The maximumCap is processed as usual."""
    group = ENERGY_PRODUCTION
    maxCap = 100
    dict_values = {
        group: {
            asset: {
                LABEL: asset,
                UNIT: unit,
                INSTALLED_CAP: {
                    VALUE: installed_cap
                },
                MAXIMUM_CAP: {
                    VALUE: maxCap
                },
                FILENAME: None,
            }
        }
    }
    C0.process_maximum_cap_constraint(dict_values, group, asset, subasset=None)
    assert (
        dict_values[group][asset][MAXIMUM_CAP][VALUE] == maxCap
    ), f"The initial maximumCap defined by the end-user ({maxCap}) is overwritten by a different value ({dict_values[group][asset][MAXIMUM_CAP][VALUE]})."
Exemple #25
0
def test_define_availability_of_peak_demand_pricing_assets_monthly():
    dict_availability_timeseries = C0.define_availability_of_peak_demand_pricing_assets(
        dict_test_avilability, 12, 1)
    assert (
        len(dict_availability_timeseries) == 12
    ), f"Function does not create 12 individual availability_timeseries for the whole year."
    assert (
        dict_availability_timeseries[1].values.sum() == 31 * 24
    ), f"Availability timeseries that is supposed to be 1 for January alone has an unexpected number of available hours."
    total = 0
    for key in dict_availability_timeseries:
        total += dict_availability_timeseries[key].values.sum()
    assert (
        total == 8760
    ), f"Availablity of all 12 availability_timeseries does not insure availability every hour of the year."
Exemple #26
0
def test_check_if_energy_carrier_is_defined_in_DEFAULT_WEIGHTS_ENERGY_CARRIERS_fail(
):
    with pytest.raises(C0.UnknownEnergyCarrier):
        C0.check_if_energy_carrier_is_defined_in_DEFAULT_WEIGHTS_ENERGY_CARRIERS(
            "Bio-Diesel", "asset_group", "asset"
        ), f"The energy carrier `Bio-Diesel` is recognized in the `DEFAULT_WEIGHTS_ENERGY_CARRIERS`, eventhough it should not be defined."
Exemple #27
0
def test_determine_months_in_a_peak_demand_pricing_period_not_valid():
    with pytest.raises(C0.InvalidPeakDemandPricingPeriods):
        C0.determine_months_in_a_peak_demand_pricing_period(
            5, 365
        ), f"No C0.InvalidPeakDemandPricingPeriods is raised eventhough an invalid number of pricing periods is requested."
Exemple #28
0
def test_determine_months_in_a_peak_demand_pricing_period_valid():
    months_in_a_period = C0.determine_months_in_a_peak_demand_pricing_period(
        4, 365)
    assert (
        months_in_a_period == 3
    ), f"The duration, ie. months of the peak demand pricing periods, are calculated incorrectly."
Exemple #29
0
def main(**kwargs):
    r"""
    Starts MVS tool simulations.

    Other Parameters
    ----------------
    overwrite : bool, optional
        Determines whether to replace existing results in `path_output_folder`
        with the results of the current simulation (True) or not (False).
        Default: False.
    pdf_report: bool, optional
        Can generate an automatic pdf report of the simulation's results (True) or not (False)
        Default: False.
    input_type : str, optional
        Defines whether the input is taken from the `mvs_config.json` file
        ("json") or from csv files ('csv') located within
        <path_input_folder>/csv_elements/. Default: 'json'.
    path_input_folder : str, optional
        The path to the directory where the input CSVs/JSON files are located.
        Default: 'inputs/'.
    path_output_folder : str, optional
        The path to the directory where the results of the simulation such as
        the plots, time series, results JSON files are saved by MVS E-Lands.
        Default: 'MVS_outputs/'
    display_output : str, optional
        Sets the level of displayed logging messages.
        Options: "debug", "info", "warning", "error". Default: "info".
    lp_file_output : bool, optional
        Specifies whether linear equation system generated is saved as lp file.
        Default: False.

    """

    welcome_text = (
        "\n \n Multi-Vector Simulation Tool (MVS) V" + version_num + " " +
        "\n Version: " + version_date + " " +
        '\n Part of the toolbox of H2020 project "E-LAND", ' +
        "Integrated multi-vector management system for Energy isLANDs" +
        "\n Coded at: Reiner Lemoine Institute (Berlin) " +
        "\n Contributors: Martha M. Hoffmann \n \n ")

    logging.debug("Accessing script: A0_initialization")

    user_input = A0.process_user_arguments(welcome_text=welcome_text, **kwargs)

    # Read all inputs
    #    print("")
    #    # todo: is user input completely used?
    #    dict_values = data_input.load_json(user_input[PATH_INPUT_FILE ])

    move_copy_config_file = False

    if user_input[INPUT_TYPE] == CSV_EXT:
        logging.debug("Accessing script: A1_csv_to_json")
        move_copy_config_file = True
        A1.create_input_json(input_directory=os.path.join(
            user_input[PATH_INPUT_FOLDER], CSV_ELEMENTS))

    logging.debug("Accessing script: B0_data_input_json")
    dict_values = B0.load_json(
        user_input[PATH_INPUT_FILE],
        path_input_folder=user_input[PATH_INPUT_FOLDER],
        path_output_folder=user_input[PATH_OUTPUT_FOLDER],
        move_copy=move_copy_config_file,
        set_default_values=True,
    )
    F0.store_as_json(
        dict_values,
        dict_values[SIMULATION_SETTINGS][PATH_OUTPUT_FOLDER_INPUTS],
        MVS_CONFIG,
    )

    print("")
    logging.debug("Accessing script: C0_data_processing")
    C0.all(dict_values)

    F0.store_as_json(
        dict_values,
        dict_values[SIMULATION_SETTINGS][PATH_OUTPUT_FOLDER],
        JSON_PROCESSED,
    )

    if "path_pdf_report" in user_input or "path_png_figs" in user_input:
        save_energy_system_graph = True
    else:
        save_energy_system_graph = False

    print("")
    logging.debug("Accessing script: D0_modelling_and_optimization")
    results_meta, results_main = D0.run_oemof(
        dict_values,
        save_energy_system_graph=save_energy_system_graph,
    )

    print("")
    logging.debug("Accessing script: E0_evaluation")
    E0.evaluate_dict(dict_values, results_main, results_meta)

    logging.debug("Accessing script: F0_outputs")
    F0.evaluate_dict(
        dict_values,
        path_pdf_report=user_input.get("path_pdf_report", None),
        path_png_figs=user_input.get("path_png_figs", None),
    )
    return 1
Exemple #30
0
def test_get_name_or_names_of_in_or_output_bus_list():
    bus = ["bus1", "bus2"]
    bus_with_suffix = [C0.bus_suffix(bus[0]), C0.bus_suffix(bus[1])]
    bus_name = C0.get_name_or_names_of_in_or_output_bus(bus)
    assert (bus_name == bus_with_suffix
            ), f"A list of bus names is not appended by the bus suffix."