Esempio n. 1
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}'
Esempio n. 2
0
def test_run_cesar_with_neighbourhood(config_sample_case, result_main_folder):
    config = config_sample_case
    res_base_path = result_main_folder / Path("sample_case_with_neighbourhood")
    result_idf_file_path = res_base_path / "fid2_fixed_constr_fixed_sched_neighbourhood100.idf"
    result_eplus_folder = res_base_path / Path("eplusout")
    result_file_path = result_eplus_folder / Path("eplustbl.csv")
    expected_folder_path = os.path.dirname(__file__) / Path(
        "expected_result") / Path("sample_case_with_neighbourhood") / Path(
            "gis_fid2")
    expected_idf_file_path = expected_folder_path / Path(
        "fid2_fixed_constr_fixed_sched_neighbourhood100.idf")
    expected_res_file_path = expected_folder_path / Path(
        "eplustbl_result_fid2_fixed_constr_fixed_sched_neighbourhood100.csv")

    gis_fid = 2
    config["GEOMETRY"] = {"NEIGHBOURHOOD": {"RADIUS": 100}}
    ureg = cesarp.common.init_unit_registry()
    run_single_bldg(gis_fid, _TEST_WEATHER_FILE_PATH, result_idf_file_path,
                    result_eplus_folder, config, ureg)
    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, 751
        ]  # on line 751 there is a small numeric difference when run on windows vs linux...
    ) is True, "E+ results not equal"
def test_window_shading(result_main_folder, default_main_cfg,
                        ep_version_setup):
    all_config = cesarp.common.load_config_full(default_main_cfg)
    if "EPLUS_ADAPTER" not in all_config.keys():
        all_config["EPLUS_ADAPTER"] = {}
    #all_config["OPERATION"]= {"WINDOW_SHADING_CONTROL": {"ACTIVE": True}}
    if "GEOMETRY" not in all_config.keys():
        all_config["GEOMETRY"] = {}
    if "NEIGHBOURHOIOD" not in all_config["GEOMETRY"].keys():
        all_config["GEOMETRY"]["NEIGHBOURHOOD"] = {}
    all_config["GEOMETRY"]["NEIGHBOURHOOD"][
        "RADIUS"] = 0  # to get less complicated IDF
    base_folder = str(result_main_folder / Path("win_shading_ep85"))
    sim_manager = SimulationManager(base_folder,
                                    all_config,
                                    cesarp.common.init_unit_registry(),
                                    fids_to_use=[4])

    sim_manager.create_bldg_models()
    sim_manager.create_IDFs()
    idf_output = base_folder / Path("idfs") / "fid_4.idf"
    expected_output = os.path.dirname(__file__) / Path(
        "expected_result") / Path("win_shading") / Path(
            "fid_4_win_shading_ep85.idf")
    assert test_helpers.are_files_equal(idf_output,
                                        expected_output,
                                        ignore_changing_config=True,
                                        ignore_filesep_mismatch=True,
                                        ignore_line_nrs=[1])
Esempio n. 4
0
def test_shp_sitevertices_parser():
    """ just a simple test if reading works... not really testing if data is read correctly """

    try:
        import geopandas
    except ModuleNotFoundError:
        pytest.skip("geopandas not available")

    sitevertices_fullfile = os.path.dirname(__file__) / Path(
        "./testfixture/shp/test_shp_buildings.shp")
    sitevertices = cesarp.geometry.shp_input_parser.read_sitevertices_from_shp(
        sitevertices_fullfile)
    # required columns available?
    assert set(sitevertices.columns) == set(_REQUIRED_SITEVERTICES_PD_COLUMNS)
    # minimum is 5 vertices per building, as the startpoint must be repeated at the end
    assert sitevertices['gis_fid'].value_counts().min() >= 5
    # check if the height is always the same for the same building fid
    assert all(
        len(set(sitevertices[sitevertices['gis_fid'] == fid]['height'])) == 1
        for fid in set(sitevertices['gis_fid']))
    temp_vertices_from_shp_file = "./temp_vertices_from_shp.csv"
    sitevertices.to_csv(temp_vertices_from_shp_file, index=False)
    expected_sitevertices_file = os.path.dirname(__file__) / Path(
        "./expected_results/shp/SiteVerticesReadFromShp.csv")
    assert are_files_equal(
        temp_vertices_from_shp_file, expected_sitevertices_file
    ), "SiteVertices generated from shp file not as expected."
    os.remove(temp_vertices_from_shp_file)
def test_building_geometry(ureg, res_folder):
    expected_file_path = os.path.dirname(__file__) / Path("./expected_results/idf_expected_geometry.idf")
    site_vertices_file = os.path.dirname(__file__) / Path("./testfixture/SiteVertices.csv")
    main_bldg_fid = 2
    glazing_ratio = 0.16
    infiltration_rate = 0.71 * ureg.ACH
    flat_vertices = cesarp.geometry.csv_input_parser.read_sitevertices_from_csv(site_vertices_file, __sitevertices_labels)
    site_bldgs = vertices_basics.convert_flat_site_vertices_to_per_bldg_footprint(flat_vertices)
    bldg_geometry = GeometryBuilder(main_bldg_fid, site_bldgs, glazing_ratio)
    bldg_shape = bldg_geometry.get_bldg_shape_detailed()

    idf_file_path = res_folder / Path("idf_geometry.idf")
    aux_files_handler = RelativeAuxiliaryFilesHandler()
    aux_files_handler.set_destination(res_folder, "profiles")
    my_idf_writer = CesarIDFWriter(idf_file_path, ureg, aux_files_handler)

    bldg_constr = __get_constr_for(main_bldg_fid, 1930, ureg)
    bldg_constr.infiltration_rate = infiltration_rate # overwrite because the default has higher precision than what was written with the matlab version
    idf = IDF(str(idf_file_path))
    my_idf_writer.add_building_geometry(idf, bldg_shape, ConstructionIDFWritingHandler(bldg_constr, None, ureg))
    idf.save()
    assert are_files_equal(idf_file_path, expected_file_path, ignore_line_nrs=[1])

    # test wrong infiltration rate unit
    bldg_constr.infiltration_rate = 3 * ureg.m ** 3 / ureg.sec
    with pytest.raises(Exception):
        my_idf_writer.add_building_geometry(idf, bldg_shape, ConstructionIDFWritingHandler(bldg_constr, None, ureg))
Esempio n. 6
0
def test_window_shading(result_main_folder, default_main_cfg, ep_version_setup, caplog):
    caplog.set_level(logging.DEBUG, logger="cesarp.manager.processing_steps")
    caplog.set_level(logging.DEBUG, logger="cesarp.manager.SimulationManager")
    all_config = cesarp.common.load_config_full(default_main_cfg)
    if not "EPLUS_ADAPTER" in all_config.keys():
        all_config["EPLUS_ADAPTER"] = {}
    all_config["EPLUS_ADAPTER"]["EPLUS_VERSION"] = "9.5"
    all_config["OPERATION"] = {"WINDOW_SHADING_CONTROL": {"ACTIVE": True}}
    if "GEOMETRY" not in all_config.keys():
        all_config["GEOMETRY"] = {}
    if "NEIGHBOURHOIOD" not in all_config["GEOMETRY"].keys():
        all_config["GEOMETRY"]["NEIGHBOURHOOD"] = {}
    all_config["GEOMETRY"]["NEIGHBOURHOOD"]["RADIUS"] = 0 # to get less complicated IDF
    base_folder = str(result_main_folder / Path("win_shading_ep95"))

    idf_output = base_folder / Path("idfs") / "fid_4.idf"
    #run_single_bldg(4, "dummy_weather.epw", idf_output, str(base_folder/Path("ep_res_fid4")), all_config, cesarp.common.init_unit_registry())

    sim_manager = SimulationManager(base_folder, all_config, cesarp.common.init_unit_registry(), fids_to_use=[4])

    sim_manager.create_bldg_models()
    sim_manager.create_IDFs()

    expected_output = os.path.dirname(__file__) / Path("expected_result") / Path("win_shading") / Path("fid_4_win_shading_ep95.idf")
    assert test_helpers.are_files_equal(idf_output, expected_output, ignore_changing_config=True, ignore_filesep_mismatch=True, ignore_line_nrs=[1])
Esempio n. 7
0
def test_create_idf_with_SIA_generated_profiles(config_sample_case,
                                                result_main_folder):
    config = config_sample_case
    res_base_path = result_main_folder / Path(
        "sia_test_sample_case_no_neighbourhood")
    config["MANAGER"]["BLDG_TYPE_PER_BLDG_FILE"] = {
        "PATH":
        str(
            os.path.dirname(__file__) /
            Path("./testfixture/sample_case/BuildingInformation.csv"))
    }
    config["MANAGER"][
        "BUILDING_OPERATION_FACTORY_CLASS"] = "cesarp.SIA2024.SIA2024Facade.SIA2024Facade"
    config["MANAGER"]["INFILTRATION_RATE_SOURCE"] = "SIA2024"
    expected_folder_path = os.path.dirname(__file__) / Path(
        "./expected_result/sia_test_sample_case_no_neighbourhood/")
    expected_idf_file_path = expected_folder_path / Path("gis_fid2") / Path(
        "fid_2.idf")
    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.create_bldg_models()
    sim_mgr.create_IDFs()
    assert are_files_equal(sim_mgr.idf_pathes[gis_fid],
                           expected_idf_file_path,
                           ignore_line_nrs=[1],
                           ignore_filesep_mismatch=True)
def test_add_construction(ureg, idf, idf_res_path):
    sample_constr = get_sample_opaque_constr(ureg)
    idf_writer_construction.add_detailed_construction(
        idf=idf, construction=sample_constr, ureg=ureg)
    idf.save(idf_res_path)

    assert are_files_equal(idf_res_path,
                           os.path.dirname(__file__) /
                           Path("./expected_results/constr/constr_opaque.idf"),
                           ignore_line_nrs=[1])
def test_basic_Shade0801(res_folder, idf, local_db_access):
    expected_file_path = _EXPECTED_FOLDER / Path("./Shade0801.idf")
    shade_mat_idf_name = idf_writer_window_shading._add_shading_mat(
        idf,
        local_db_access.get_window_shading_constr(
            "http://uesl_data/sources/archetypes/2014_SFH_Archetype"))
    idf_file_path = res_folder / Path('Shade0801_compare.idf')
    idf.save(idf_file_path)
    assert are_files_equal(idf_file_path,
                           expected_file_path,
                           ignore_line_nrs=[1])
def test_add_window_construction(ureg, idf, idf_res_path):
    sample_constr = get_sample_win_constr(ureg)
    idf_writer_construction.add_win_glass_construction(
        idf=idf, glass_constr=sample_constr.glass, ureg=ureg)
    idf_writer_construction.add_win_frame_construction(
        idf=idf, frame_constr=sample_constr.frame, ureg=ureg)
    idf.save(idf_res_path)

    assert are_files_equal(idf_res_path,
                           os.path.dirname(__file__) /
                           Path("./expected_results/constr/constr_window.idf"),
                           ignore_line_nrs=[1])
Esempio n. 11
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 test_add_opaque_material(ureg, idf, idf_res_path):
    sample_mat = get_sample_opaque_mat(ureg)
    idf_writer_construction.add_opaque_material(
        idf=idf,
        idf_obj_name="Glasswool_TEST.2500",
        thickness=0.25 * ureg.m,
        mat_def=sample_mat,
        ureg=ureg)
    idf.save(idf_res_path)

    assert are_files_equal(idf_res_path,
                           os.path.dirname(__file__) /
                           Path("./expected_results/constr/opaque_mat.idf"),
                           ignore_line_nrs=[1])
def test_simulations_basic_settings(ureg, res_folder):
    expected_file_path = os.path.dirname(__file__) / Path(
        "./expected_results/idf_expected_simulation_basics.idf")

    os.makedirs(res_folder, exist_ok=True)
    aux_files_handler = RelativeAuxiliaryFilesHandler()
    aux_files_handler.set_destination(res_folder, "profiles")

    idf_file_path = res_folder / Path("idf_simulation_basics.idf")
    my_idf_writer = CesarIDFWriter(idf_file_path, ureg, aux_files_handler)
    idf = IDF(str(idf_file_path))
    my_idf_writer.add_basic_simulation_settings(idf, SiteGroundTemperatureFactory(ureg).get_ground_temperatures())
    idf.save()
    assert are_files_equal(idf_file_path, expected_file_path, ignore_line_nrs=[1]) == True
def test_add_win_glazing_material(ureg, idf, idf_res_path):
    sample_win_glazing_mat = get_sample_win_glazing_mat(ureg)
    idf_writer_construction.add_window_glazing_material(
        idf=idf,
        idf_obj_name="my_test_win_mat",
        thickness=0.006 * ureg.m,
        mat_def=sample_win_glazing_mat,
        ureg=ureg)
    idf.save(idf_res_path)
    assert are_files_equal(
        idf_res_path,
        os.path.dirname(__file__) /
        Path("./expected_results/constr/window_glazing_mat.idf"),
        ignore_line_nrs=[1])
def test_neighbour_shading_objects(ureg, res_folder):
    expected_file_path = os.path.dirname(__file__) / Path("./expected_results/idf_expected_neighbours.idf")
    site_vertices_file = os.path.dirname(__file__) / Path("./testfixture/SiteVertices_minimized.csv")
    main_bldg_fid = 2
    glazing_ratio = 0.16

    flat_vertices = cesarp.geometry.csv_input_parser.read_sitevertices_from_csv(site_vertices_file, __sitevertices_labels)
    site_bldgs = vertices_basics.convert_flat_site_vertices_to_per_bldg_footprint(flat_vertices)
    bldg_geometry = GeometryBuilder(main_bldg_fid, site_bldgs, glazing_ratio)
    neighbours = bldg_geometry.get_bldg_shape_of_neighbours()

    idf_file_path = res_folder / Path("idf_neighbours.idf")

    aux_files_handler = RelativeAuxiliaryFilesHandler()
    aux_files_handler.set_destination(res_folder, "profiles")
    my_idf_writer = CesarIDFWriter(idf_file_path, ureg, aux_files_handler)

    win_glass_constr = __get_constr_for(main_bldg_fid, 1930, ureg).window_constr.glass
    neigh_constr = __get_shading_constr(win_glass_constr, ureg)
    idf = IDF(str(idf_file_path))
    my_idf_writer.add_neighbours(idf, neighbours, ConstructionIDFWritingHandler(None, neigh_constr, ureg))
    idf.save()
    assert are_files_equal(idf_file_path, expected_file_path, ignore_line_nrs=[1])
Esempio n. 16
0
def test_add_night_vent_zone_flowrate(res_folder, idf):
    ureg = cesarp.common.init_unit_registry()
    expected_file_path = _EXPECTED_FOLDER / Path(
        "./night_vent_zone_expected.idf")
    myModel = NightVent(
        is_active=True,
        flow_rate=ureg("2.5 ACH"),
        min_indoor_temperature=ureg("24 degreeC"),
        maximum_in_out_deltaT=ureg("2 degreeC"),
        max_wind_speed=ureg(
            "40 m/s"
        ),  # maximum wind speed threshold (m/s) - above this value the occupant closes the window - 40m/s is default in EnergyPlus Version 8.5
        start_hour="20:00",  # night ventilation starting hour (00:00 format)
        end_hour="6:00",  # night ventilation ending hour (00:00 format)
        maximum_indoor_temp_profile=ScheduleFixedValue(
            value=ureg("25 degreeC"),
            type_limit=ScheduleTypeLimits.TEMPERATURE()))
    idf_writer_night_vent.add_night_ventilation_for_zone(
        idf, "myzone", myModel)
    idf_file_path = res_folder / Path('night_vent_zone_result.idf')
    idf.save(idf_file_path)
    assert are_files_equal(idf_file_path,
                           expected_file_path,
                           ignore_line_nrs=[1])
def test_full_idf(res_folder):
    gis_fid = 2
    expected_file_path = os.path.dirname(__file__) / Path("./expected_results/idf_expected_full.idf")
    result_idf_file_path = res_folder / Path(f"fid_{gis_fid}_full.idf")
    config = dict()
    config["MANAGER"] = dict()
    config["MANAGER"]["SITE_VERTICES_FILE"] = {"PATH": os.path.dirname(__file__) / Path("./testfixture/SiteVertices.csv")}
    config["MANAGER"]["BLDG_FID_FILE"] = {"PATH": os.path.dirname(__file__) / Path("./testfixture/BuildingInformation.csv")}
    config["MANAGER"]["BLDG_AGE_FILE"] = {"PATH": os.path.dirname(__file__) / Path("./testfixture/BuildingInformation.csv")}
    config["MANAGER"]["BLDG_TYPE_PER_BLDG_FILE"] = {"PATH": os.path.dirname(__file__) / Path("./testfixture/BuildingInformation.csv")}
    config["MANAGER"]["BLDG_INSTALLATION_FILE"] = {"PATH": os.path.dirname(__file__) / Path("./testfixture/BuildingInformation.csv")}
    config["MANAGER"]["BUILDING_OPERATION_FACTORY_CLASS"] = "cesarp.operation.fixed.FixedBuildingOperationFactory.FixedBuildingOperationFactory"
    config["MANAGER"]["SINGLE_SITE"] = {"ACTIVE": True, "WEATHER_FILE": os.path.dirname(__file__) / Path("./testfixture/DummyWeather.epw")}
    config["MANAGER"]["SITE_PER_CH_COMMUNITY"] = {"ACTIVE": False}
    config["GEOMETRY"] = {"NEIGHBOURHOOD": {"RADIUS": 1}}

    unit_reg = cesarp.common.init_unit_registry()
    bldg_models_factory = BldgModelFactory(unit_reg, config)
    bldg_model = bldg_models_factory.create_bldg_model(gis_fid)
    profile_file_handler = RelativeAuxiliaryFilesHandler()
    profile_file_handler.set_destination(res_folder, "profiles")
    my_idf_writer = cesarp.eplus_adapter.CesarIDFWriter.CesarIDFWriter(result_idf_file_path, unit_reg, profile_file_handler, custom_config=config)
    my_idf_writer.write_bldg_model(bldg_model)
    assert are_files_equal(result_idf_file_path, expected_file_path, ignore_line_nrs=[1], ignore_case=True, ignore_filesep_mismatch=True)