Ejemplo n.º 1
0
 def test_processing_dict_for_json_export_parse_str(self):
     """ """
     file_name = "test_json_str"
     F0.store_as_json(JSON_TEST_DICTIONARY[TYPE_STR], OUTPUT_PATH,
                      file_name)
     assert os.path.exists(os.path.join(OUTPUT_PATH,
                                        file_name + ".json")) is True
    def test_store_scalars_to_excel_two_tabs_no_dict(self):
        """ """
        dict_scalars_two_tabs = {
            SIMULATION_SETTINGS: {PATH_OUTPUT_FOLDER: OUTPUT_PATH},
            KPI: {"economic": pandas_Dataframe, "technical": pandas_Dataframe},
        }

        F0.store_scalars_to_excel(dict_scalars_two_tabs)
        assert os.path.exists(os.path.join(OUTPUT_PATH, "scalars.xlsx")) is True
Ejemplo n.º 3
0
 def setup_class(self):
     """ """
     if os.path.exists(OUTPUT_PATH):
         shutil.rmtree(OUTPUT_PATH, ignore_errors=True)
     os.mkdir(OUTPUT_PATH)
     self.file_name = "test_json_converter"
     F0.store_as_json(JSON_TEST_DICTIONARY, OUTPUT_PATH, self.file_name)
     self.value_dict = B0.load_json(
         os.path.join(OUTPUT_PATH, self.file_name + ".json"))
Ejemplo n.º 4
0
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)
 def test_store_each_bus_timeseries_to_excel_and_png_one_bus(self):
     """ """
     dict_timeseries_test_one_bus = {
         PROJECT_DATA: {PROJECT_NAME: "a_project", SCENARIO_NAME: "a_scenario",},
         SIMULATION_SETTINGS: {PATH_OUTPUT_FOLDER: OUTPUT_PATH},
         OPTIMIZED_FLOWS: {"a_bus": BUS},
     }
     dict_timeseries_test_one_bus.update(copy.deepcopy(DICT_PLOTS))
     F0.store_timeseries_all_busses_to_excel(dict_timeseries_test_one_bus)
     assert (
         os.path.exists(os.path.join(OUTPUT_PATH, "timeseries_all_busses.xlsx"))
         is True
     )
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def run_simulation(json_dict, epa_format=True, **kwargs):
    r"""
     Starts MVS tool simulation from an input json file

     Parameters
    -----------
     json_dict: dict
         json from http request
     epa_format: bool, optional
         Specifies whether the output is formatted for EPA standards
         Default: True

     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.

    """
    display_output = kwargs.get("display_output", None)

    if display_output == "debug":
        screen_level = logging.DEBUG
    elif display_output == "info":
        screen_level = logging.INFO
    elif display_output == "warning":
        screen_level = logging.WARNING
    elif display_output == "error":
        screen_level = logging.ERROR
    else:
        screen_level = logging.INFO

    # Define logging settings and path for saving log
    logger.define_logging(screen_level=screen_level)

    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 Reference: https://zenodo.org/record/4610237 \n \n ")

    logging.info(welcome_text)

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

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

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

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

    logging.debug("Convert results to json")

    if epa_format is True:
        epa_dict_values = data_parser.convert_mvs_params_to_epa(dict_values)

        json_values = F0.store_as_json(epa_dict_values)
        answer = json.loads(json_values)

    else:
        answer = dict_values

    return answer
 def test_store_dict_into_json(self):
     """ """
     file_name = "test_json_converter"
     F0.store_as_json(JSON_TEST_DICTIONARY, OUTPUT_PATH, file_name)
     assert os.path.exists(os.path.join(OUTPUT_PATH, file_name + ".json")) is True