Пример #1
0
    def test_apply_mvs(self, margs):
        """ """

        main.apply_pvcompare(
            storeys=self.storeys,
            country=self.country,
            latitude=self.latitude,
            longitude=self.longitude,
            year=self.year,
            static_inputs_directory=self.static_inputs_directory,
            user_inputs_pvcompare_directory=self.user_inputs_pvcompare_directory,
            user_inputs_mvs_directory=self.user_inputs_mvs_directory,
            collections_mvs_inputs_directory=self.user_inputs_collection_mvs,
            plot=False,
            pv_setup=None,
            overwrite_grid_parameters=True,
            overwrite_pv_parameters=True,
        )

        main.apply_mvs(
            scenario_name=self.scenario_name,
            outputs_directory=self.outputs_directory,
            user_inputs_mvs_directory=self.user_inputs_mvs_directory,
        )

        assert os.path.isdir(os.path.join(self.outputs_directory, self.scenario_name))
    def test_implementations_tes(self, margs):
        """
        This test checks if the results of two different ways of implementing a stratified
        thermal storage match.
        You can include a stratified thermal storage in the model using two ways:

        1. With storage component with `inflow_direction` and `outflow_direction` to the heat bus
        2. With a storage bus, a storage component and `inflow_direction` and `outflow_direction`
            as Transformer feeding in and from that bus
            Please note that the cost parameters of `inflow_direction` and `outflow_direction` of
            the Transformer should be set to zero, since they cannot be assigned to a real plant
            component with cost parameters
        Parameters
        ----------
        margs

        """
        # Simulation of first way of implementation
        main.apply_pvcompare(
            storeys=self.storeys,
            country=self.country,
            latitude=self.lat,
            longitude=self.lon,
            year=self.year,
            static_inputs_directory=self.static_inputs_directory,
            user_inputs_pvcompare_directory=self.user_inputs_pvcompare_directory,
            user_inputs_mvs_directory=self.user_inputs_mvs_directory,
            plot=False,
            pv_setup=self.pv_setup,
            overwrite_grid_parameters=True,
            overwrite_pv_parameters=True,
        )

        # RUN MVS OEMOF SIMULATTION
        main.apply_mvs(
            scenario_name=self.scenario_name,
            outputs_directory=self.outputs_directory,
            user_inputs_mvs_directory=self.user_inputs_mvs_directory,
        )

        # Read results of simulation with first way of implementation
        results_storage_heat_bus = pd.read_excel(
            os.path.join(
                self.outputs_directory,
                self.scenario_name,
                "mvs_outputs",
                "timeseries_all_busses.xlsx",
            ),
            sheet_name="Heat bus",
        )

        # Revert changes made in storage_xx.csv file
        self.storage_xx_original.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "storage_TES.csv"), na_rep="NaN"
        )

        # Calculated files in time_series directory need to be deleted to ensure
        # the next simulation is run completely
        time_series_directory = os.path.join(
            self.user_inputs_mvs_directory, "time_series"
        )
        time_series = os.listdir(time_series_directory)
        for file_name in time_series:
            if file_name != "file_exists.csv":
                os.remove(os.path.join(time_series_directory, file_name))

        # Modify mvs csv input data as a preparation for the simulation of
        # the second way of implementation (see below)

        # Add "TES bus" to busses
        energy_busses = self.energy_busses_original.copy()
        energy_busses["TES bus"] = "Heat"
        energy_busses.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyBusses.csv"), na_rep="NaN"
        )
        # Add TES input and output converter to transformers
        energy_conversion = self.energy_conversion_original.copy()
        energy_conversion["TES converter in"] = [
            "kW",
            "True",
            "None",
            0,
            0,
            30,
            0,
            0,
            0,
            0,
            1,
            "Heat bus",
            "TES bus",
            "Heat",
            "transformer",
        ]
        energy_conversion["TES converter out"] = [
            "kW",
            "True",
            "None",
            0,
            0,
            30,
            0,
            0,
            0,
            0,
            1,
            "TES bus",
            "Heat bus",
            "Heat",
            "transformer",
        ]
        energy_conversion.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyConversion.csv"), na_rep="NaN"
        )
        # Adapt inflow and outflow direction of storage to "TES bus"
        energy_storage = self.energy_storage_original.copy()
        energy_storage.at["inflow_direction", "storage_TES"] = "TES bus"
        energy_storage.at["outflow_direction", "storage_TES"] = "TES bus"
        energy_storage.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyStorage.csv"), na_rep="NaN"
        )

        # Simulation of second way of implementation
        main.apply_pvcompare(
            storeys=self.storeys,
            country=self.country,
            latitude=self.lat,
            longitude=self.lon,
            year=self.year,
            static_inputs_directory=self.static_inputs_directory,
            user_inputs_pvcompare_directory=self.user_inputs_pvcompare_directory,
            user_inputs_mvs_directory=self.user_inputs_mvs_directory,
            plot=False,
            pv_setup=self.pv_setup,
            overwrite_grid_parameters=True,
            overwrite_pv_parameters=True,
        )

        # RUN MVS OEMOF SIMULATTION
        main.apply_mvs(
            scenario_name=self.scenario_name_with_TES_bus,
            outputs_directory=self.outputs_directory,
            user_inputs_mvs_directory=self.user_inputs_mvs_directory,
        )

        # Read results of simulation with second way of implementation
        results_storage_tes_bus = pd.read_excel(
            os.path.join(
                self.outputs_directory,
                self.scenario_name_with_TES_bus,
                "mvs_outputs",
                "timeseries_all_busses.xlsx",
            ),
            sheet_name="Heat bus",
        )

        # Assert that results of both implementations match
        assert (
            results_storage_heat_bus["TES input power"].values.all()
            == results_storage_tes_bus["TES converter in"].values.all()
        )
        assert (
            results_storage_heat_bus["TES output power"].values.all()
            == results_storage_tes_bus["TES converter out"].values.all()
        )

        # Revert changes made in mvs csv input files
        self.storage_xx_original.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "storage_TES.csv"), na_rep="NaN"
        )
        self.energy_busses_original.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyBusses.csv"), na_rep="NaN"
        )
        self.energy_conversion_original.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyConversion.csv"), na_rep="NaN"
        )
        self.energy_storage_original.to_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyStorage.csv"), na_rep="NaN"
        )
        self.energy_production_original = pd.read_csv(
            os.path.join(self.mvs_csv_inputs_path, "energyProduction.csv"),
            header=0,
            index_col=0,
        )

        scenarios = [self.scenario_name, self.scenario_name_with_TES_bus]
        for scenario in scenarios:
            outputs_directory = os.path.join(self.outputs_directory, scenario)
            if os.path.exists(outputs_directory):
                shutil.rmtree(outputs_directory)
Пример #3
0
user_inputs_mvs_directory = constants.EXAMPLE_USER_INPUTS_MVS_ELECTRICITY
pv_setup = None
outputs_directory = constants.EXAMPLE_OUTPUTS_DIRECTORY

# RUN PVCOMPARE PRE-CALCULATIONS:
# - calculate PV timeseries
# - if sectorcoupling: calculate heat pump generation
# - calculate electricity and heat demand

main.apply_pvcompare(
    storeys=storeys,
    country=country,
    latitude=latitude,
    longitude=longitude,
    year=year,
    static_inputs_directory=static_inputs_directory,
    user_inputs_pvcompare_directory=user_inputs_pvcompare_directory,
    user_inputs_mvs_directory=user_inputs_mvs_directory,
    plot=False,
    pv_setup=pv_setup,
    overwrite_grid_parameters=True,
    overwrite_pv_parameters=True,
)

# RUN MVS OEMOF SIMULATTION
main.apply_mvs(
    scenario_name=scenario_name,
    outputs_directory=outputs_directory,
    user_inputs_mvs_directory=user_inputs_mvs_directory,
)
Пример #4
0
def loop_mvs(
    latitude,
    longitude,
    years,
    storeys,
    country,
    variable_name,
    variable_column,
    csv_file_variable,
    start,
    stop,
    step,
    scenario_name,
    user_inputs_mvs_directory=None,
    outputs_directory=None,
):
    """
    Starts multiple MVS simulations with a range of values for a specific parameter.

    This function applies :py:func:`~.main.apply_pvcompare`, one time. After that
     :py:func:`~.main.apply_mvs` is executed in a loop.
     Before each loop a specific variable value is changed. The
    results, stored in two excel sheets, are copied into `loop_output_directory`.

    Parameters
    ----------
    latitude: float
        latitude of the location
    longitude: foat
        longitude of the location
    years: list
        year(s) for simulation
    storeys:int
        number of storeys
    country: str
        country of location
    variable_name: str
        name of the variable that is atapted in each loop
    variable_column: str
        name of the  variable column in the csv file
    csv_file_variable: str
        name of the csv file the variable is saved in
    start: int
        first value of the variable
    stop: int
        last value of the variable. notice that stop > start
    step: int
        step of increase
    scenario_name: str
        Name of the Scenario. The name should follow the scheme:
        "Scenario_A1", "Scenario_A2", "Scenario_B1" etc.
    user_inputs_mvs_directory: str or None
        Default: `user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY`
    outputs_directory: str or None
        Path to output directory.
        Default: `outputs_directory = constants.DEFAULT_OUTPUTS_DIRECTORY`

    Returns
    -------

    """

    if outputs_directory is None:
        outputs_directory = constants.DEFAULT_OUTPUTS_DIRECTORY
    loop_output_directory = create_loop_output_structure(
        outputs_directory, scenario_name, variable_name
    )
    # define filename of variable that should be looped over
    if user_inputs_mvs_directory is None:
        user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY
    csv_filename = os.path.join(
        user_inputs_mvs_directory, "csv_elements", csv_file_variable
    )

    # loop over years
    for year in years:
        # apply pvcompare
        main.apply_pvcompare(
            latitude=latitude,
            longitude=longitude,
            year=year,
            storeys=storeys,
            country=country,
            user_inputs_mvs_directory=user_inputs_mvs_directory,
        )

        # loop over the variable
        i = start
        while i <= stop:
            # change variable value and save this value to csv
            csv_file = pd.read_csv(csv_filename, index_col=0)
            csv_file.loc[[variable_name], [variable_column]] = i
            csv_file.to_csv(csv_filename)

            # define mvs_output_directory for every looping step
            mvs_output_directory = os.path.join(
                outputs_directory,
                scenario_name,
                "mvs_outputs_loop_"
                + str(variable_name)
                + "_"
                + str(year)
                + "_"
                + str(i),
            )

            # apply mvs for every looping step
            main.apply_mvs(
                scenario_name=scenario_name,
                mvs_output_directory=mvs_output_directory,
                user_inputs_mvs_directory=user_inputs_mvs_directory,
                outputs_directory=outputs_directory,
            )

            # copy excel sheets to loop_output_directory
            number_digits = len(str(stop)) - len(str(i))

            if number_digits == 0:
                j = str(i)
            elif number_digits == 1:
                j = "0" + str(i)
            elif number_digits == 2:
                j = "00" + str(i)
            elif number_digits == 3:
                j = "000" + str(i)
            elif number_digits == 4:
                j = "0000" + str(i)

            excel_file1 = "scalars.xlsx"
            new_excel_file1 = "scalars_" + str(year) + "_" + str(j) + ".xlsx"
            src_dir = os.path.join(mvs_output_directory, excel_file1)
            dst_dir = os.path.join(loop_output_directory, "scalars", new_excel_file1)
            shutil.copy(src_dir, dst_dir)

            excel_file2 = "timeseries_all_busses.xlsx"
            new_excel_file2 = (
                "timeseries_all_busses_" + str(year) + "_" + str(j) + ".xlsx"
            )
            src_dir = os.path.join(mvs_output_directory, excel_file2)
            dst_dir = os.path.join(loop_output_directory, "timeseries", new_excel_file2)
            shutil.copy(src_dir, dst_dir)

            # add another step
            i = i + step
    logging.info("starting postprocessing KPI")
    postprocessing_kpi(
        scenario_name=scenario_name,
        variable_name=variable_name,
        outputs_directory=outputs_directory,
    )
Пример #5
0
def single_loop_pvcompare(
    scenario_name,
    storeys,
    country,
    latitude,
    longitude,
    year,
    user_inputs_pvcompare_directory,
    user_inputs_mvs_directory,
    outputs_directory,
    plot,
    pv_setup,
    loop_output_directory,
    loop_type,
    step,
):
    """

    Parameters
    ----------
    scenario_name: str
        name of the scenario.
    storeys: int
        number of storeys
    country: str
        country name
    latitude: float
        latitude of the location
    longitude: foat
        longitude of the location
    year: int
        year
    user_inputs_pvcompare_directory: str or None
        If None, `constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY` is used
        as user_input_directory. Default: None.
    user_inputs_mvs_directory: str or None
        Default: `user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY`
    outputs_directory: str or None
        Path to output directory.
        Default: `outputs_directory = constants.DEFAULT_OUTPUTS_DIRECTORY`
    plot: bool
        default: False
    loop_output_directory: str
        output directory defined in 'pvcompare.outputs.create_loop_output_structure()'.
    loop_type: str
        possible values: 'location', 'year', 'storeys', 'technology', 'hp_temp'.
        Defines the variable or variables that are changed with each loop.
    step: str or int
        Gradation of the loop variable.

    Returns
    -------
        None
    """

    main.apply_pvcompare(
        storeys=storeys,
        country=country,
        latitude=latitude,
        longitude=longitude,
        year=year,
        user_inputs_pvcompare_directory=user_inputs_pvcompare_directory,
        user_inputs_mvs_directory=user_inputs_mvs_directory,
        plot=plot,
        pv_setup=pv_setup,
    )

    # define mvs_output_directory for every looping step
    mvs_output_directory = os.path.join(
        outputs_directory,
        scenario_name,
        "mvs_outputs_loop_" + str(loop_type) + "_" + str(year) + "_" + str(step),
    )

    main.apply_mvs(
        scenario_name,
        user_inputs_mvs_directory=user_inputs_mvs_directory,
        mvs_output_directory=mvs_output_directory,
        outputs_directory=outputs_directory,
    )

    excel_file1 = "scalars.xlsx"
    new_excel_file1 = "scalars_" + str(year) + "_" + str(step) + ".xlsx"
    src_dir = os.path.join(mvs_output_directory, excel_file1)
    dst_dir = os.path.join(loop_output_directory, "scalars", new_excel_file1)
    shutil.copy(src_dir, dst_dir)

    excel_file2 = "timeseries_all_busses.xlsx"
    new_excel_file2 = (
        "timeseries_all_busses_" + "_" + str(year) + "_" + str(step) + ".xlsx"
    )
    src_dir = os.path.join(mvs_output_directory, excel_file2)
    dst_dir = os.path.join(loop_output_directory, "timeseries", new_excel_file2)
    shutil.copy(src_dir, dst_dir)