Example #1
0
def test_setting_values():
    """Test the methods for setting values on the data collection"""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyDiscontinuousCollection(header, values,
                                       header.analysis_period.datetimes)
    # test the contains and reversed methods
    assert 10 in dc
    assert list(reversed(dc)) == list(reversed(values))

    # test setting individual values
    assert dc[0] == 0
    dc[0] = 10
    assert dc[0] == 10

    # try setting the whole list of values
    val_rev = list(reversed(values))
    dc.values = val_rev
    assert dc[0] == 8759

    # make sure that people can't change the values without changing datetimes
    with pytest.raises(Exception):
        dc.values.append(10)
Example #2
0
def test_init_utci_collection_full_input():
    """Test the initialization of the UTCI collection will all inputs."""
    calc_length = 24
    air_temp_header = Header(Temperature(), 'C',
                             AnalysisPeriod(end_month=1, end_day=1))
    air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length)
    custom_par = UTCIParameter(8, 25, -41, -28, -14, -1, 27, 31, 37, 45)
    utci_obj = UTCI(air_temp, 50, 22, 0.5, custom_par)

    assert utci_obj.air_temperature[0] == 24
    assert utci_obj.rel_humidity[0] == 50
    assert utci_obj.rad_temperature[0] == 22
    assert utci_obj.wind_speed[0] == 0.5
    assert utci_obj.comfort_parameter.cold_thresh == 8
    assert utci_obj.comfort_parameter.heat_thresh == 25
    assert utci_obj.comfort_parameter.extreme_cold_thresh == -41
    assert utci_obj.comfort_parameter.very_strong_cold_thresh == -28
    assert utci_obj.comfort_parameter.strong_cold_thresh == -14
    assert utci_obj.comfort_parameter.moderate_cold_thresh == -1
    assert utci_obj.comfort_parameter.moderate_heat_thresh == 27
    assert utci_obj.comfort_parameter.strong_heat_thresh == 31
    assert utci_obj.comfort_parameter.very_strong_heat_thresh == 37
    assert utci_obj.comfort_parameter.extreme_heat_thresh == 45
def test_get_aligned_collection():
    """Test the method for getting an aligned discontinuous collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    values = list(xrange(24))
    dc1 = HourlyDiscontinuousCollection(header, values,
                                        header.analysis_period.datetimes)
    dc2 = dc1.get_aligned_collection(50, RelativeHumidity(), '%')
    assert dc2.header.data_type.name == 'Relative Humidity'
    assert dc2.header.unit == '%'
    assert isinstance(dc2, HourlyDiscontinuousCollection)
    assert dc2.is_mutable is True

    dc3 = dc1.get_aligned_collection(50, RelativeHumidity(), '%', mutable=False)
    assert dc3.header.data_type.name == 'Relative Humidity'
    assert dc3.header.unit == '%'
    assert isinstance(dc3, HourlyDiscontinuousCollectionImmutable)
    assert dc3.is_mutable is False

    dc4 = dc1.get_aligned_collection(50, RelativeHumidity(), '%', mutable=True)
    assert dc4.header.data_type.name == 'Relative Humidity'
    assert dc4.header.unit == '%'
    assert isinstance(dc4, HourlyDiscontinuousCollection)
    assert dc4.is_mutable is True
def test_hourly():
    """Test the dicontinuous collections."""
    a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13)
    dt1, dt2 = DateTime(6, 21, 12), DateTime(6, 21, 13)
    v1, v2 = 20, 25
    dc1 = HourlyDiscontinuousCollectionImmutable(
        Header(Temperature(), 'C', a_per), [v1, v2], [dt1, dt2])
    assert dc1.datetimes == (dt1, dt2)
    assert dc1.values == (v1, v2)
    assert dc1.is_mutable is False
    with pytest.raises(AttributeError):
        dc1[0] = 18
    with pytest.raises(AttributeError):
        dc1.values = [18, 24]
    with pytest.raises(Exception):
        dc1.values.append(10)
    with pytest.raises(AttributeError):
        dc2 = dc1.convert_to_culled_timestep(1)

    dc2 = dc1.to_mutable()
    assert isinstance(dc2, HourlyDiscontinuousCollection)
    assert dc2.is_mutable is True
    dc2[0] = 18
    assert dc2[0] == 18
    dc2.values = [18, 24]
    assert dc2.values == (18, 24)
    with pytest.raises(Exception):
        dc2.values.append(10)  # make sure that we can still not append

    dc3 = dc2.to_immutable()
    assert isinstance(dc3, HourlyDiscontinuousCollectionImmutable)
    assert dc3.is_mutable is False

    dc4 = dc3.to_immutable()
    assert isinstance(dc4, HourlyDiscontinuousCollectionImmutable)
    assert dc4.is_mutable is False
Example #5
0
def test_init_prevailing_temperature_monthly():
    """Test the PrevailingTemperature object with monthly inputs."""
    outdoor_header = Header(Temperature(), 'C', AnalysisPeriod())
    outdoor_temp = MonthlyCollection(outdoor_header, range(12),
                                     AnalysisPeriod().months_int)
    outdoor_temp = outdoor_temp.validate_analysis_period()

    prevail_obj = PrevailingTemperature(outdoor_temp, True)
    assert isinstance(prevail_obj.hourly_prevailing_temperature,
                      HourlyContinuousCollection)
    assert len(prevail_obj.hourly_prevailing_temperature.values) == 8760
    assert isinstance(prevail_obj.daily_prevailing_temperature,
                      DailyCollection)
    assert len(prevail_obj.daily_prevailing_temperature.values) == 365
    assert isinstance(prevail_obj.monthly_prevailing_temperature,
                      MonthlyCollection)
    assert len(prevail_obj.monthly_prevailing_temperature.values) == 12
    assert isinstance(prevail_obj.monthly_per_hour_prevailing_temperature,
                      MonthlyPerHourCollection)
    assert len(
        prevail_obj.monthly_per_hour_prevailing_temperature.values) == 288

    with pytest.raises(Exception):
        prevail_obj = PrevailingTemperature(outdoor_temp, False)
Example #6
0
def test_adaptive_collection_comfort_outputs():
    """Test the is_comfortable and thermal_condition outputs of the collection."""
    calc_length = 24
    prevail_header = Header(PrevailingOutdoorTemperature(), 'C',
                            AnalysisPeriod(end_month=1, end_day=1))
    prevail_temp = HourlyContinuousCollection(prevail_header,
                                              [22] * calc_length)
    op_temp_header = Header(Temperature(), 'C',
                            AnalysisPeriod(end_month=1, end_day=1))
    op_temp = HourlyContinuousCollection(op_temp_header,
                                         range(20, 20 + calc_length))
    adapt_obj = Adaptive(prevail_temp, op_temp)

    assert isinstance(adapt_obj.is_comfortable, HourlyContinuousCollection)
    assert len(adapt_obj.is_comfortable.values) == calc_length
    assert adapt_obj.is_comfortable[0] == 0
    assert adapt_obj.is_comfortable[5] == 1
    assert adapt_obj.is_comfortable[10] == 0

    assert isinstance(adapt_obj.thermal_condition, HourlyContinuousCollection)
    assert len(adapt_obj.thermal_condition.values) == calc_length
    assert adapt_obj.thermal_condition[0] == -1
    assert adapt_obj.thermal_condition[5] == 0
    assert adapt_obj.thermal_condition[10] == 1
Example #7
0
def test_adaptive_collection_defaults():
    """Test the default inputs assigned to the Adaptive collection."""
    calc_length = 24
    prevail_header = Header(PrevailingOutdoorTemperature(), 'C',
                            AnalysisPeriod(end_month=1, end_day=1))
    prevail_temp = HourlyContinuousCollection(prevail_header,
                                              [22] * calc_length)
    op_temp_header = Header(Temperature(), 'C',
                            AnalysisPeriod(end_month=1, end_day=1))
    op_temp = HourlyContinuousCollection(op_temp_header, [26] * calc_length)
    adapt_obj = Adaptive(prevail_temp, op_temp)

    assert isinstance(adapt_obj.air_speed, HourlyContinuousCollection)
    assert len(adapt_obj.air_speed.values) == calc_length
    assert adapt_obj.air_speed[0] == 0.1

    assert isinstance(adapt_obj.comfort_parameter, AdaptiveParameter)
    default_par = AdaptiveParameter()
    assert adapt_obj.comfort_parameter.ashrae55_or_en15251 == default_par.ashrae55_or_en15251
    assert adapt_obj.comfort_parameter.neutral_offset == default_par.neutral_offset
    assert adapt_obj.comfort_parameter.avg_month_or_running_mean == default_par.avg_month_or_running_mean
    assert adapt_obj.comfort_parameter.discrete_or_continuous_air_speed == default_par.discrete_or_continuous_air_speed
    assert adapt_obj.comfort_parameter.cold_prevail_temp_limit == default_par.cold_prevail_temp_limit
    assert adapt_obj.comfort_parameter.conditioning == default_par.conditioning
Example #8
0
def test_pmv_collection_comfort_outputs():
    """Test the is_comfortable and thermal_condition outputs of the PMV collection."""
    calc_length = 24
    air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    air_temp = HourlyContinuousCollection(air_temp_header, range(20, 20 + calc_length))
    pmv_obj = PMV(air_temp, 50)

    assert isinstance(pmv_obj.is_comfortable, HourlyContinuousCollection)
    assert len(pmv_obj.is_comfortable.values) == calc_length
    assert pmv_obj.is_comfortable[0] == 0
    assert pmv_obj.is_comfortable[5] == 1
    assert pmv_obj.is_comfortable[10] == 0

    assert isinstance(pmv_obj.thermal_condition, HourlyContinuousCollection)
    assert len(pmv_obj.thermal_condition.values) == calc_length
    assert pmv_obj.thermal_condition[0] == -1
    assert pmv_obj.thermal_condition[5] == 0
    assert pmv_obj.thermal_condition[10] == 1

    assert isinstance(pmv_obj.discomfort_reason, HourlyContinuousCollection)
    assert len(pmv_obj.discomfort_reason.values) == calc_length
    assert pmv_obj.discomfort_reason[0] == -1
    assert pmv_obj.discomfort_reason[5] == 0
    assert pmv_obj.discomfort_reason[10] == 1
Example #9
0
def test_init_utci_collection():
    """Test the initialization of the UTCI collection and basic outputs."""
    calc_length = 24
    air_temp_header = Header(Temperature(), 'C',
                             AnalysisPeriod(end_month=1, end_day=1))
    air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length)
    utci_obj = UTCI(air_temp, 50)

    assert utci_obj.comfort_model == 'Universal Thermal Climate Index'
    assert utci_obj.calc_length == calc_length
    str(utci_obj)  # test that the string representaiton is ok

    assert isinstance(utci_obj.air_temperature, HourlyContinuousCollection)
    assert len(utci_obj.air_temperature.values) == calc_length
    assert utci_obj.air_temperature[0] == 24
    assert isinstance(utci_obj.rel_humidity, HourlyContinuousCollection)
    assert len(utci_obj.rel_humidity.values) == calc_length
    assert utci_obj.rel_humidity[0] == 50

    assert isinstance(utci_obj.universal_thermal_climate_index,
                      HourlyContinuousCollection)
    assert len(utci_obj.universal_thermal_climate_index.values) == calc_length
    assert utci_obj.universal_thermal_climate_index[0] == pytest.approx(
        23.8110341, rel=1e-3)
Example #10
0
def test_hourlyplot_analysis_period():
    """Test the initialization of MonthlyChart with an analysis period."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(range(8760))
    data_coll = HourlyContinuousCollection(header, values)
    period1 = AnalysisPeriod(3, 1, 0, 3, 31, 23)
    data_coll1 = data_coll.filter_by_analysis_period(period1)
    month_chart = MonthlyChart([data_coll1])

    assert month_chart.analysis_period == period1
    meshes = month_chart.data_meshes
    assert len(meshes) == 1
    assert isinstance(meshes[0], Mesh2D)
    assert len(meshes[0].faces) == 24

    period2 = AnalysisPeriod(3, 1, 0, 6, 30, 23)
    data_coll2 = data_coll.filter_by_analysis_period(period2)
    month_chart = MonthlyChart([data_coll2])

    assert month_chart.analysis_period == period2
    meshes = month_chart.data_meshes
    assert len(meshes) == 1
    assert isinstance(meshes[0], Mesh2D)
    assert len(meshes[0].faces) == 24 * 4
 def surface_temperatures(self):
     """Data Collection of surface temperature values in degrees C."""
     return self._get_coll('_srf_temp_coll', self._srf_temp,
                           Temperature('Surface Temperature'), 'C')
Example #12
0
def test_total():
    """Test the total method."""
    header1 = Header(Temperature(), 'C', AnalysisPeriod())
    values = [1] * 8760
    dc = HourlyContinuousCollection(header1, values)
    assert dc.total == 8760
Example #13
0
def test_validate_a_period_hourly():
    """Test the validate_analysis_period method for dicontinuous collections."""
    a_per = AnalysisPeriod(6, 21, 0, 6, 21, 23)
    dt1, dt2 = DateTime(6, 21, 12), DateTime(6, 21, 13)
    v1, v2 = 20, 25

    # Test that the validate method correctly sorts reversed datetimes.
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2], [dt2, dt1])
    dc1_new = dc1.validate_analysis_period()
    assert dc1.validated_a_period is False
    assert dc1_new.validated_a_period is True
    assert dc1.datetimes == (dt2, dt1)
    assert dc1_new.datetimes == (dt1, dt2)

    # Test that the validate method correctly updates analysis_period range.
    a_per_2 = AnalysisPeriod(6, 20, 15, 6, 20, 23)
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per_2),
                                        [v1, v2], [dt1, dt2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1.validated_a_period is False
    assert dc1_new.validated_a_period is True
    assert dc1.header.analysis_period == a_per_2
    assert dc1_new.header.analysis_period == AnalysisPeriod(
        6, 20, 12, 6, 21, 23)

    # Test that the validate method with reversed analysis_periods.
    a_per_3 = AnalysisPeriod(6, 20, 15, 2, 20, 23)
    dt5 = DateTime(1, 21, 12)
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per_3),
                                        [v1, v2, v2], [dt1, dt2, dt5])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == AnalysisPeriod(
        6, 20, 12, 2, 20, 23)
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per_3),
                                        [v1, v2], [dt1, dt2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == AnalysisPeriod(
        6, 20, 12, 2, 20, 23)
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C',
                                               a_per_3), [v1, v2],
                                        [dt5, DateTime(1, 21, 15)])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == AnalysisPeriod(
        6, 20, 12, 2, 20, 23)

    # Test that the validate method correctly updates timestep.
    dt3 = DateTime(6, 21, 12, 30)
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2, v2], [dt1, dt3, dt2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1.validated_a_period is False
    assert dc1_new.validated_a_period is True
    assert dc1.header.analysis_period.timestep == 1
    assert dc1_new.header.analysis_period.timestep == 2

    # Test that the validate method correctly identifies leap years.
    dt4 = DateTime(2, 29, 12, leap_year=True)
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2, v2], [dt1, dt4, dt2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1.validated_a_period is False
    assert dc1_new.validated_a_period is True
    assert dc1.header.analysis_period.is_leap_year is False
    assert dc1_new.header.analysis_period.is_leap_year is True

    # Test that duplicated datetimes are caught
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2], [dt1, dt1])
    with pytest.raises(Exception):
        dc1_new = dc1.validate_analysis_period()
Example #14
0
def test_init_continuous_incorrect():
    """Test the init methods for continuous collections with incorrect values"""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(10))
    with pytest.raises(Exception):
        HourlyContinuousCollection(header, values)
Example #15
0
    def calculate_surface_temperature(self, epw_file: str, idd_file: str, case_name: str = None, output_directory: str = None, is_shaded: bool = False):
        """
        Calculate the surface temperature of the ground typology using EnergyPlus
        :param epw_file: Weather-file with location and climatic conditions for simulation
        :param idd_file: Location of EnergyPlus IDD file (to enable reference of IDF objects and simulation)
        :param case_name: Name of case being simulated
        :param output_directory: Location of generated outputs
        :param is_shaded:
        :return ground_surface_temperature:
        """

        # Assign to object and locate outputs
        self.epw = epw_file
        self.is_shaded = is_shaded
        case_name = "openfield" if case_name is None else case_name
        output_directory = pathlib.Path(tempfile.gettempdir()) if output_directory is None else output_directory

        # Load monthly ground temperature from weather-file
        monthly_ground_temperatures = EPW(epw_file).monthly_ground_temperature[0.5].values

        # Reference Eplus program
        idd_file = pathlib.Path(idd_file)
        eplus = idd_file.parent / "energyplus.exe"
        IDF.setiddname(str(idd_file))

        # Construct folder structure for eplus case
        eplus_output_path = pathlib.Path(output_directory) / case_name / "ground_surface_temperature"
        eplus_output_path.mkdir(parents=True, exist_ok=True)
        idf_file = eplus_output_path / "in.idf"
        eso_file = eplus_output_path / "eplusout.eso"

        # Construct case for simulation
        idf = IDF(StringIO(""))

        # Define base building object
        building = idf.newidfobject("BUILDING")
        building.Name = "ground"
        building.North_Axis = 0
        building.Terrain = "City"
        building.Solar_Distribution = "FullExterior"
        building.Maximum_Number_of_Warmup_Days = 25
        building.Minimum_Number_of_Warmup_Days = 6

        # Set shadow calculation to once per hour
        shadowcalculation = idf.newidfobject("SHADOWCALCULATION")
        shadowcalculation.Calculation_Method = "TimestepFrequency"
        shadowcalculation.Calculation_Frequency = 1
        shadowcalculation.Maximum_Figures_in_Shadow_Overlap_Calculations = 3000

        # Define ground material

        material = idf.newidfobject("MATERIAL")
        material.Name = "ground_material"
        material.Roughness = "MediumRough"
        material.Thickness = self.thickness
        material.Conductivity = self.conductivity
        material.Density = self.density
        material.Specific_Heat = self.specific_heat
        material.Thermal_Absorptance = self.emissivity
        material.Solar_Absorptance = 1 - self.reflectivity
        material.Visible_Absorptance = 1 - self.reflectivity

        # Define ground construction
        construction = idf.newidfobject("CONSTRUCTION")
        construction.Name = "ground_construction"
        construction.Outside_Layer = "ground_material"

        # Set global geometry rules
        globalgeometryrules = idf.newidfobject("GLOBALGEOMETRYRULES")
        globalgeometryrules.Starting_Vertex_Position = "UpperLeftCorner"
        globalgeometryrules.Vertex_Entry_Direction = "Counterclockwise"
        globalgeometryrules.Coordinate_System = "Relative"

        # Define ground zone
        zone = idf.newidfobject("ZONE")
        zone.Name = "ground_zone"

        # Add ground surfaces (as a closed zone)
        ground_x, ground_y, ground_z = 200, 200, 1
        vertex_groups = [
            [[-ground_x / 2, ground_y / 2, 0], [-ground_x / 2, -ground_y / 2, 0], [ground_x / 2, -ground_y / 2, 0],
             [ground_x / 2, ground_y / 2, 0]],
            [[ground_x / 2, -ground_y / 2, -ground_z], [-ground_x / 2, -ground_y / 2, -ground_z],
             [-ground_x / 2, ground_y / 2, -ground_z], [ground_x / 2, ground_y / 2, -ground_z]],
            [[-ground_x / 2, ground_y / 2, 0], [-ground_x / 2, ground_y / 2, -ground_z],
             [-ground_x / 2, -ground_y / 2, -ground_z], [-ground_x / 2, -ground_y / 2, 0]],
            [[ground_x / 2, -ground_y / 2, 0], [ground_x / 2, -ground_y / 2, -ground_z],
             [ground_x / 2, ground_y / 2, -ground_z], [ground_x / 2, ground_y / 2, 0]],
            [[ground_x / 2, ground_y / 2, 0], [ground_x / 2, ground_y / 2, -ground_z],
             [-ground_x / 2, ground_y / 2, -ground_z], [-ground_x / 2, ground_y / 2, 0]],
            [[-ground_x / 2, -ground_y / 2, 0], [-ground_x / 2, -ground_y / 2, -ground_z],
             [ground_x / 2, -ground_y / 2, -ground_z], [ground_x / 2, -ground_y / 2, 0]]
        ]

        for n, vg in enumerate(vertex_groups):
            gnd = idf.newidfobject("BUILDINGSURFACE:DETAILED")
            gnd.Name = "ground_surface_{}".format(n)
            gnd.Surface_Type = "Roof" if n == 0 else "Floor" if n == 1 else "Wall"
            gnd.Construction_Name = "ground_construction"
            gnd.Zone_Name = "ground_zone"
            gnd.Outside_Boundary_Condition = "Outdoors" if n == 0 else "Ground"
            gnd.Sun_Exposure = "SunExposed" if n == 0 else "Nosun"
            gnd.Wind_Exposure = "WindExposed" if n == 0 else "Nowind"
            for nnn, vgx in enumerate(vg):
                setattr(gnd, "Vertex_{}_Xcoordinate".format(nnn + 1), vgx[0])
                setattr(gnd, "Vertex_{}_Ycoordinate".format(nnn + 1), vgx[1])
                setattr(gnd, "Vertex_{}_Zcoordinate".format(nnn + 1), vgx[2])

        # Set ground temperatures using EPW monthly values
        groundtemperature = idf.newidfobject("SITE:GROUNDTEMPERATURE:BUILDINGSURFACE")
        for i, j in list(zip(*[pd.date_range("2018", "2019", freq="1M").strftime("%B"), monthly_ground_temperatures])):
            setattr(groundtemperature, "{}_Ground_Temperature".format(i), j)

        # Add shading if the case is shaded
        if is_shaded:
            shd_schedule_limits = idf.newidfobject("SCHEDULETYPELIMITS")
            shd_schedule_limits.Name = "shade_schedule_type_limit"
            shd_schedule_limits.Lower_Limit_Value = 0
            shd_schedule_limits.Upper_Limit_Value = 1
            shd_schedule_limits.Numeric_Type = "Continuous"

            shd_schedule_constant = idf.newidfobject("SCHEDULE:CONSTANT")
            shd_schedule_constant.Name = "shade_schedule_constant"
            shd_schedule_constant.Schedule_Type_Limits_Name = "shade_schedule_type_limit"
            shd_schedule_constant.Hourly_Value = 0

            shade_x = 200
            shade_y = 200
            shade_z = 4
            shade_vertex_groups = [
                [[-shade_x / 2, -shade_y / 2, shade_z], [-shade_x / 2, -shade_y / 2, 0], [shade_x / 2, -shade_y / 2, 0],
                 [shade_x / 2, -shade_y / 2, shade_z]],
                [[shade_x / 2, -shade_y / 2, shade_z], [shade_x / 2, -shade_y / 2, 0], [shade_x / 2, shade_y / 2, 0],
                 [shade_x / 2, shade_y / 2, shade_z]],
                [[shade_x / 2, shade_y / 2, shade_z], [shade_x / 2, shade_y / 2, 0], [-shade_x / 2, shade_y / 2, 0],
                 [-shade_x / 2, shade_y / 2, shade_z]],
                [[-shade_x / 2, shade_y / 2, shade_z], [-shade_x / 2, shade_y / 2, 0], [-shade_x / 2, -shade_y / 2, 0],
                 [-shade_x / 2, -shade_y / 2, shade_z]],
                [[shade_x / 2, shade_y / 2, shade_z], [-shade_x / 2, -shade_y / 2, shade_z],
                 [shade_x / 2, -shade_y / 2, shade_z], [shade_x / 2, shade_y / 2, shade_z]]
            ]
            for n, vg in enumerate(shade_vertex_groups):
                shd = idf.newidfobject("SHADING:BUILDING:DETAILED")
                shd.Name = "shade_surface_{}".format(n)
                shd.Transmittance_Schedule_Name = "shade_schedule_constant"
                for nnn, vgx in enumerate(vg):
                    setattr(shd, "Vertex_{}_Xcoordinate".format(nnn + 1), vgx[0])
                    setattr(shd, "Vertex_{}_Ycoordinate".format(nnn + 1), vgx[1])
                    setattr(shd, "Vertex_{}_Zcoordinate".format(nnn + 1), vgx[2])

        # Set output variables for Eplus run - only top surface of ground considered here
        outputvariable = idf.newidfobject("OUTPUT:VARIABLE")
        outputvariable.Key_Value = "ground_surface_0"
        outputvariable.Variable_Name = "Surface Outside Face Temperature"
        outputvariable.Reporting_Frequency = "hourly"

        # Write Eplus file
        idf.saveas(idf_file)

        # Run Eplus simulation
        cmd = '"{0:}" -a -w "{1:}" -d "{2:}" "{3:}"'.format(eplus.absolute(), epw_file, eplus_output_path, idf_file)
        subprocess.call(cmd, shell=True)

        # Read surface temperature results
        with open(eso_file, "r") as f:
            data = f.read().split("\n")

            # Find key
            for n, i in enumerate(data):
                if i == "End of Data Dictionary":
                    split_part = n

            _vars = [j.split(",")[-1].replace(" !Hourly", "") for j in data[7:split_part]]

            surface_temperature = [float(item) for sublist in
                     [[k.split(",")[1:][0] for k in j[1:]] for j in chunk(data[split_part + 2:-3], n=len(_vars) + 1)]
                     for
                     item in sublist]

        self.surface_temperature = HourlyContinuousCollection(header=Header(Temperature(), unit="C", analysis_period=AnalysisPeriod()), values=surface_temperature)

        print("Ground surface temperature simulation completed")

        return self.surface_temperature
                                                       adapt_par.conditioning,
                                                       adapt_par.standard)
        elif adapt_par.ashrae55_or_en15251 is True:
            comf_result = adaptive_comfort_ashrae55(prevail_temp, to)
        else:
            comf_result = adaptive_comfort_en15251(prevail_temp, to)

        # Determine the cooling effect
        if adapt_par.discrete_or_continuous_air_speed is True:
            ce = cooling_effect_ashrae55(input[3], to)
        else:
            ce = cooling_effect_en15251(input[3], to)

        # Output results
        neutral_temp = comf_result['t_comf']
        deg_neutral = comf_result['deg_comf']
        comfort = adapt_par.is_comfortable(comf_result, ce)
        condition = adapt_par.thermal_condition(comf_result, ce)
    else:
        # The inputs include Data Collections.
        if not isinstance(_air_temp, BaseCollection):
            _air_temp = data_colls[0].get_aligned_collection(
                float(_air_temp), Temperature(), 'C')

        comf_obj = Adaptive.from_air_and_rad_temp(_out_temp, _air_temp, _mrt_,
                                                  _air_speed_, adapt_par)
        prevail_temp = comf_obj.prevailing_outdoor_temperature
        neutral_temp = comf_obj.neutral_temperature
        deg_neutral = comf_obj.degrees_from_neutral
        comfort = comf_obj.is_comfortable
        condition = comf_obj.thermal_condition
Example #17
0
def test_hourlyplot_init():
    """Test the initialization of HourlyPlot and basic properties."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(range(8760))
    data_coll = HourlyContinuousCollection(header, values)
    hour_plot = HourlyPlot(data_coll)

    str(hour_plot)  # test the string representation
    assert isinstance(hour_plot.data_collection,
                      HourlyContinuousCollectionImmutable)
    assert isinstance(hour_plot.legend_parameters, LegendParameters)
    assert hour_plot.base_point == Point3D(0, 0, 0)
    assert hour_plot.x_dim == 1
    assert hour_plot.y_dim == 4
    assert hour_plot.z_dim == 0
    assert hour_plot.values == data_coll.values

    mesh = hour_plot.colored_mesh2d
    assert isinstance(mesh, Mesh2D)
    assert len(mesh.faces) == 8760
    mesh = hour_plot.colored_mesh3d
    assert isinstance(mesh, Mesh3D)
    assert len(mesh.faces) == 8760

    border = hour_plot.chart_border2d
    assert isinstance(border, Polyline2D)
    assert len(border.segments) == 4
    border = hour_plot.chart_border3d
    assert isinstance(border, Polyline3D)
    assert len(border.segments) == 4

    hour_txt = hour_plot.hour_labels
    assert all(isinstance(txt, str) for txt in hour_txt)
    hour_lines = hour_plot.hour_lines2d
    hour_pts = hour_plot.hour_label_points2d
    assert len(hour_lines) == len(hour_txt) == len(hour_pts) == 5
    assert all(isinstance(line, LineSegment2D) for line in hour_lines)
    assert all(isinstance(pt, Point2D) for pt in hour_pts)
    hour_lines = hour_plot.hour_lines3d
    hour_pts = hour_plot.hour_label_points3d
    assert len(hour_lines) == len(hour_txt) == len(hour_pts) == 5
    assert all(isinstance(line, LineSegment3D) for line in hour_lines)
    assert all(isinstance(pt, Point3D) for pt in hour_pts)

    month_txt = hour_plot.month_labels
    assert all(isinstance(txt, str) for txt in month_txt)
    month_lines = hour_plot.month_lines2d
    month_pts = hour_plot.month_label_points2d
    assert len(month_txt) == len(month_pts) == 12
    assert len(month_lines) == 11
    assert all(isinstance(line, LineSegment2D) for line in month_lines)
    assert all(isinstance(pt, Point2D) for pt in month_pts)
    month_lines = hour_plot.month_lines3d
    month_pts = hour_plot.month_label_points3d
    assert len(month_txt) == len(month_pts) == 12
    assert len(month_lines) == 11
    assert all(isinstance(line, LineSegment3D) for line in month_lines)
    assert all(isinstance(pt, Point3D) for pt in month_pts)

    assert isinstance(hour_plot.legend, Legend)

    assert isinstance(hour_plot.title_text, str)
    assert 'Temperature' in hour_plot.title_text
    assert isinstance(hour_plot.lower_title_location, Plane)
    assert isinstance(hour_plot.upper_title_location, Plane)