示例#1
0
def test_night_ventilation(result_main_folder):
    cfg_file = _TESTFIXTURE_FOLDER / Path("cooling") / Path("main_config.yml")
    cfg = cesarp.common.load_config_full(cfg_file)
    cfg["OPERATION"] = {
        "WINDOW_SHADING_CONTROL": {
            "ACTIVE": False
        },
        "NIGHT_VENTILATION": {
            "ACTIVE": True
        }
    }
    # Note: trick to debug results: remove deleting result folder in res_folder(), then run it once, then uncomment
    #       sim_mgr.run_all_steps(), change load_from_disk=True and then debug and check the results...
    sim_mgr = SimulationManager(result_main_folder / Path("sim_test"),
                                cfg,
                                cesarp.common.init_unit_registry(),
                                load_from_disk=False,
                                fids_to_use=[7])
    sim_mgr.run_all_steps()
    results = sim_mgr.get_all_results_summary()
    dhw_annual_expected = pytest.approx(10364.1775, rel=0.005)
    electricity_annual_expected = pytest.approx(71952.9883)
    assert results.loc[7,
                       "h * kiloW / year"]["Cooling Annual"] == pytest.approx(
                           13633.8, rel=0.005)
    assert results.loc[7,
                       "h * kiloW / year"]["Heating Annual"] == pytest.approx(
                           14744.2, rel=0.005)
    assert results.loc[7,
                       "h * kiloW / year"]["DHW Annual"] == dhw_annual_expected
    assert results.loc[7, "h * kiloW / year"][
        "Electricity Annual"] == electricity_annual_expected
示例#2
0
def test_no_adjacencies(config_no_adjacencies_case, result_main_folder):
    """ Testcase data provided by Manolis """
    """ Tests usage of parallel workers, as the run_all_steps() function is called and not the run_single_bldg() as in the other testcases """
    config = config_no_adjacencies_case
    expected_folder_path = os.path.dirname(__file__) / Path(
        "expected_result") / Path("no_adjacencies_case")
    expected_idf_file_path = str(expected_folder_path / Path("fid_{}.idf"))
    expected_result_file_path = str(expected_folder_path /
                                    Path("fid_job{}Table.csv"))
    res_base_path = result_main_folder / Path("no_adjacencies_case/")

    bldg_fids = [307143, 1150082]

    sim_mgr = SimulationManager(res_base_path, config,
                                cesarp.common.init_unit_registry())
    sim_mgr.run_all_steps()

    for bldg_fid in bldg_fids:
        assert are_files_equal(sim_mgr.idf_pathes[bldg_fid],
                               expected_idf_file_path.format(bldg_fid),
                               ignore_line_nrs=[1],
                               ignore_filesep_mismatch=True
                               ) is True, f'IDF files not equal for {bldg_fid}'
        # Line 0 and 177 contain energyplus veriosn and date/time of execution, thus ignore those;
        # on line 709 and 1463 there is a small numeric difference when run on windows vs linux...
        assert are_files_equal(
            sim_mgr.output_folders[bldg_fid] / Path("eplustbl.csv"),
            expected_result_file_path.format(bldg_fid),
            ignore_line_nrs=[
                1, 178, 709, 1463
            ]) is True, f'result files not equal for {bldg_fid}'
示例#3
0
def test_run_cesar_no_neighbourhood(config_sample_case, result_main_folder):
    config = config_sample_case
    res_base_path = result_main_folder / Path("sample_case_no_neighbourhood")
    result_idf_file_path = res_base_path / Path("idfs") / "fid_2.idf"
    result_eplus_folder = res_base_path / Path("eplus_output") / Path("fid_2")
    result_file_path = result_eplus_folder / Path("eplustbl.csv")
    result_summary_path = res_base_path / Path("site_result_summary.csvy")

    expected_folder_path = os.path.dirname(__file__) / Path(
        "./expected_result/sample_case_no_neighbourhood/gis_fid2/")
    expected_res_sum_path = os.path.dirname(__file__) / Path(
        "./expected_result/sample_case_no_neighbourhood/site_result_summary.csvy"
    )
    expected_idf_file_path = expected_folder_path / Path(
        "fid_2_fixed_constr_fixed_sched_no_neighbourhood.idf")
    expected_res_file_path = expected_folder_path / Path(
        "eplustbl_result_fid2_fixed_constr_fixed_sched_no_neighbourhood.csv")

    config["GEOMETRY"] = {"NEIGHBOURHOOD": {"RADIUS": 0}}
    gis_fid = 2
    sim_mgr = SimulationManager(res_base_path,
                                config,
                                cesarp.common.init_unit_registry(),
                                fids_to_use=[gis_fid])
    sim_mgr.run_all_steps()

    assert are_files_equal(
        result_idf_file_path,
        expected_idf_file_path,
        ignore_line_nrs=[1],
        ignore_filesep_mismatch=True) is True, "IDF files not equal"

    # Line 0 and 177 contain energyplus veriosn and date/time of execution, thus ignore those
    assert are_files_equal(
        result_file_path, expected_res_file_path,
        ignore_line_nrs=[1, 178]) is True, "E+ results not equal"
    assert are_files_equal(result_summary_path,
                           expected_res_sum_path,
                           ignore_line_nrs=[189],
                           ignore_changing_config=True)
def run_sim_site(base_output_folder, main_config_path, fids=None):
    base_output_folder = __abs_path(base_output_folder)
    assert not os.path.exists(
        base_output_folder
    ), f"output folder {base_output_folder} already exists - please specify a non-existing folder for cesar-p outputs."
    sim_manager = SimulationManager(base_output_folder,
                                    main_config_path,
                                    cesarp.common.init_unit_registry(),
                                    fids_to_use=fids,
                                    load_from_disk=False)

    sim_manager.run_all_steps()
    zip_path = sim_manager.save_to_zip(
        main_script_path=__file__,
        save_folder_path=os.path.dirname(__file__),
        include_idfs=False,
        include_eplus_output=False,
        include_src_pck=True)
    print(
        f"Project has been saved to {zip_path}, including all input files so it can be transfered to another computer."
    )

    # if you need different result parameters, you have to make sure that energy plus reports them. Do so by using the configuration parameters from eplus_adapter package, namely
    # "OUTPUR_METER" and "OUTPUT_VARS", see cesarp.eplus_adapter.default_config.yml. You can overwrite those parameters in your project config, in this example that would be main_config.yml.
    # Also make sure that the reporting frequency in the configuration and in the callect_results_in_parallel() call match.
    result_series_frame = sim_manager.collect_custom_results(
        result_keys=["DistrictHeating:HVAC", "DistrictHeating:Building"],
        results_frequency=ResultsFrequency.HOURLY)
    # you can postprocess the results as you like, e.g. save to a file
    result_series_frame.to_csv(
        __abs_path(base_output_folder) / Path("hourly_results.csv"))

    if sim_manager.failed_fids:
        logging.warning(
            f"Something went wrong for following FID's {sim_manager.failed_fids}"
        )
示例#5
0
from cesarp.manager.SimulationManager import SimulationManager


def __abs_path(path):
    return cesarp.common.abs_path(path, os.path.abspath(__file__))


if __name__ == "__main__":
    # this logging config is only for the main process, workers log to separate log files which go into a folder, configured in SimulationManager.
    logging.config.fileConfig(__abs_path("../logging.conf"))

    # make sure the BuildingSpecificArechtypConstrctionFactory can be found
    sys.path.append(os.path.dirname(__file__))

    main_config_path = __abs_path("custom_constr_archetype_config.yml")
    output_dir = __abs_path("../results/custom_constr_archetype")
    shutil.rmtree(output_dir, ignore_errors=True)

    fids_to_use = [1, 2, 8]  # set to None to simulate all buildings
    sim_manager = SimulationManager(output_dir,
                                    main_config_path,
                                    cesarp.common.init_unit_registry(),
                                    fids_to_use=fids_to_use)
    sim_manager.run_all_steps()

    print("====================")
    print(f"check out results in {output_dir}")
    print(
        "check archetype assignment in worker log files in folder TIMESTAMP-cesarp-logs. depending on logging settings it is also printed to the console."
    )
示例#6
0
def test_window_shading(result_main_folder):
    """ validated agains matlab implementation of ricardo """
    cfg_file = _TESTFIXTURE_FOLDER / Path("cooling") / Path("main_config.yml")
    cfg = cesarp.common.load_config_full(cfg_file)
    cfg["OPERATION"] = {
        "WINDOW_SHADING_CONTROL": {
            "ACTIVE": True
        },
        "NIGHT_VENTILATION": {
            "ACTIVE": False
        }
    }
    # Note: trick to debug results: remove deleting result folder in res_folder(), then run it once, then uncomment
    #       sim_mgr.run_all_steps(), change load_from_disk=True and then debug and check the results...
    sim_mgr = SimulationManager(result_main_folder / Path("sim_test"),
                                cfg,
                                cesarp.common.init_unit_registry(),
                                load_from_disk=False)
    sim_mgr.run_all_steps()
    results = sim_mgr.get_all_results_summary()
    dhw_annual_expected = pytest.approx(10351.6, rel=0.005)
    electricity_annual_expected = pytest.approx(71953)
    assert results.loc[2,
                       "h * kiloW / year"]["Cooling Annual"] == pytest.approx(
                           297.6, rel=0.005)
    assert results.loc[2,
                       "h * kiloW / year"]["Heating Annual"] == pytest.approx(
                           172524, rel=0.005)
    assert results.loc[2,
                       "h * kiloW / year"]["DHW Annual"] == dhw_annual_expected
    assert results.loc[2, "h * kiloW / year"][
        "Electricity Annual"] == electricity_annual_expected

    assert results.loc[7,
                       "h * kiloW / year"]["Cooling Annual"] == pytest.approx(
                           13718.5, rel=0.005)
    assert results.loc[7,
                       "h * kiloW / year"]["Heating Annual"] == pytest.approx(
                           21194.7, rel=0.005)
    assert results.loc[7,
                       "h * kiloW / year"]["DHW Annual"] == dhw_annual_expected
    assert results.loc[7, "h * kiloW / year"][
        "Electricity Annual"] == electricity_annual_expected

    assert results.loc[8,
                       "h * kiloW / year"]["Cooling Annual"] == pytest.approx(
                           16000.9, rel=0.005)
    assert results.loc[8,
                       "h * kiloW / year"]["Heating Annual"] == pytest.approx(
                           15840.86, rel=0.005)
    assert results.loc[8,
                       "h * kiloW / year"]["DHW Annual"] == dhw_annual_expected
    assert results.loc[8, "h * kiloW / year"][
        "Electricity Annual"] == electricity_annual_expected

    assert results.loc[9,
                       "h * kiloW / year"]["Cooling Annual"] == pytest.approx(
                           14822.8, rel=0.005)
    assert results.loc[9,
                       "h * kiloW / year"]["Heating Annual"] == pytest.approx(
                           14548.6, rel=0.005)
    assert results.loc[9,
                       "h * kiloW / year"]["DHW Annual"] == dhw_annual_expected
    assert results.loc[9, "h * kiloW / year"][
        "Electricity Annual"] == electricity_annual_expected