Ejemplo n.º 1
0
def test_duplicate():
    """Test the duplicate method on the discontinuous collections."""
    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.duplicate()
    assert dc1.header.data_type.name == dc2.header.data_type.name
    assert dc1.header.unit == dc2.header.unit
    assert dc1.header.analysis_period == dc2.header.analysis_period
    assert dc1.header.metadata == dc2.header.metadata
    assert dc1.values == dc2.values
    assert dc1.datetimes == dc2.datetimes
Ejemplo n.º 2
0
def test_validate_a_period_monthly():
    """Test the validate_a_period methods for monthly collections."""
    a_per = AnalysisPeriod(6, 1, 0, 7, 1, 23)
    v1, v2 = 20, 25
    dt1, dt2 = 6, 7

    # Test that the validate method correctly sorts reversed datetimes.
    dc1 = MonthlyCollection(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, 1, 0, 6, 1, 23)
    dc1 = MonthlyCollection(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, 1, 0, 7, 31, 23)

    # Test that the validate method with reversed analysis_periods.
    a_per_3 = AnalysisPeriod(6, 1, 0, 2, 28, 23)
    dt5 = 1
    dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2, v2],
                            [dt5, dt1, dt2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == a_per_3
    assert dc1_new.datetimes == (dt1, dt2, dt5)
    dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2],
                            [dt1, dt2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == a_per_3
    assert dc1_new.datetimes == (dt1, dt2)
    dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2],
                            [dt5, 2])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.datetimes == (dt5, 2)
    assert dc1_new.header.analysis_period == a_per_3
    dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2],
                            [dt5, 4])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == AnalysisPeriod()
    assert dc1_new.datetimes == (dt5, 4)

    # Test that duplicated datetimes are caught
    dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                            [dt1, dt1])
    with pytest.raises(Exception):
        dc1_new = dc1.validate_analysis_period()
Ejemplo n.º 3
0
def test_total_monthly_per_hour():
    """Test the total monthly per hour method."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyContinuousCollection(header, values)
    new_dc = dc.total_monthly_per_hour()
    assert isinstance(new_dc, MonthlyPerHourCollection)
    assert len(new_dc) == 12 * 24
    assert new_dc.datetimes[0] == (1, 0)
    assert new_dc.datetimes[-1] == (12, 23)
    assert new_dc.is_continuous is True
    for i, val in enumerate(dc.group_by_month_per_hour().values()):
        assert new_dc[i] == sum(val)
Ejemplo n.º 4
0
def test_init_incorrect():
    """Test the init methods for base collections with incorrect inputs."""
    a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13)
    dt1, dt2 = DateTime(6, 21, 12), DateTime(6, 21, 13)
    v1, v2 = 20, 25
    avg = (v1 + v2) / 2

    dc1 = BaseCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                         [dt1, dt2])
    dc1 = BaseCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                         (dt1, dt2))
    dc1 = BaseCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                         xrange(2))
    assert dc1.average == avg
    with pytest.raises(Exception):
        dc1 = BaseCollection(Header(Temperature(), 'C', a_per), [v1, v2], 'te')

    with pytest.raises(Exception):
        dc1 = BaseCollection(Header(Temperature(), 'C', a_per), [v1, v2], {
            '1': 1,
            '2': 2
        })
Ejemplo n.º 5
0
def test_total_monthly():
    """Test the total monthly method."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyContinuousCollection(header, values)
    new_dc = dc.total_monthly()
    assert isinstance(new_dc, MonthlyCollection)
    assert len(new_dc) == 12
    assert new_dc.datetimes[0] == 1
    assert new_dc.datetimes[-1] == 12
    assert new_dc.is_continuous is True
    for i, val in dc.group_by_month().items():
        assert new_dc[i - 1] == sum(val)
Ejemplo n.º 6
0
def test_percentile_monthly():
    """Test the percentile monthly method."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = [50] * 8760
    dc = HourlyContinuousCollection(header, values)
    new_dc = dc.percentile_monthly(25)
    assert isinstance(new_dc, MonthlyCollection)
    assert len(new_dc) == 12
    assert new_dc.datetimes[0] == 1
    assert new_dc.datetimes[-1] == 12
    assert new_dc.is_continuous is True
    for i, val in dc.group_by_month().items():
        assert new_dc[i - 1] == 50
Ejemplo n.º 7
0
def test_average_daily():
    """Test the average daily method."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyContinuousCollection(header, values)
    new_dc = dc.average_daily()
    assert isinstance(new_dc, DailyCollection)
    assert len(new_dc) == 365
    assert new_dc.datetimes[0] == 1
    assert new_dc.datetimes[-1] == 365
    assert new_dc.is_continuous
    for i, val in dc.group_by_day().items():
        assert new_dc[i - 1] == sum(val) / len(val)
Ejemplo n.º 8
0
def test_percentile_daily():
    """Test the percentile daily method."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(24)) * 365
    dc = HourlyContinuousCollection(header, values)
    new_dc = dc.percentile_daily(25)
    assert isinstance(new_dc, DailyCollection)
    assert len(new_dc) == 365
    assert new_dc.datetimes[0] == 1
    assert new_dc.datetimes[-1] == 365
    assert new_dc.is_continuous is True
    for i, val in dc.group_by_day().items():
        assert new_dc[i - 1] == 5.75
Ejemplo n.º 9
0
def test_filter_by_analysis_period_hourly():
    """Test filtering by analysis period on hourly discontinuous collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyDiscontinuousCollection(header, values,
                                       header.analysis_period.datetimes)
    dc = dc.validate_analysis_period()
    a_per = AnalysisPeriod(st_month=3, end_month=3)
    filt_dc = dc.filter_by_analysis_period(a_per)
    assert len(filt_dc) == 31 * 24
    assert filt_dc.header.analysis_period == a_per
    assert filt_dc.datetimes[0] == DateTime(3, 1, 0)
    assert filt_dc.datetimes[-1] == DateTime(3, 31, 23)
Ejemplo n.º 10
0
def test_filter_by_analysis_period_continuous_large():
    """Test filtering large analysis period on hourly continuous collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod(st_month=3,
                                                       end_month=3))
    values = list(xrange(24 * 31))
    dc = HourlyContinuousCollection(header, values)
    a_per = AnalysisPeriod(st_hour=9, end_hour=17)
    filt_dc = dc.filter_by_analysis_period(a_per)
    assert len(filt_dc) == 31 * 9
    assert filt_dc.header.analysis_period == AnalysisPeriod(3, 1, 9, 3, 31, 17)
    assert filt_dc.datetimes[0] == DateTime(3, 1, 9)
    assert filt_dc.datetimes[-1] == DateTime(3, 31, 17)
    assert not isinstance(filt_dc, HourlyContinuousCollection)
Ejemplo n.º 11
0
def test_init_continuous():
    """Test the init methods for continuous collections"""
    # Setup temperature data collection
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc1 = HourlyContinuousCollection(header, values)

    assert len(dc1.datetimes) == 8760
    assert list(dc1.values) == list(xrange(8760))
    assert dc1.average == 4379.5
    assert dc1.is_continuous is True
    str(dc1)  # Test the string representation of the collection
    str(dc1.header)  # Test the string representation of the header
Ejemplo n.º 12
0
def test_hourlyplot_sub_hourly():
    """Test the initialization of HourlyPlot and basic properties."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(range(8760))
    dc1 = HourlyContinuousCollection(header, values)
    data_coll = dc1.interpolate_to_timestep(4)
    hour_plot = HourlyPlot(data_coll, y_dim=1)

    mesh = hour_plot.colored_mesh2d
    assert isinstance(mesh, Mesh2D)
    assert len(mesh.faces) == 8760 * 4
    assert mesh.min == Point2D(0, 0)
    assert mesh.max == Point2D(365, 4 * 24)
Ejemplo n.º 13
0
def test_utci_collection_comfort_outputs():
    """Test the is_comfortable and thermal_condition outputs of the UTCI collection."""
    calc_length = 24
    air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    air_temp = HourlyContinuousCollection(air_temp_header, range(5, 5 + calc_length))
    utci_obj = UTCI(air_temp, 50)

    assert isinstance(utci_obj.is_comfortable, HourlyContinuousCollection)
    assert len(utci_obj.is_comfortable.values) == calc_length
    assert utci_obj.is_comfortable[0] == 0
    assert utci_obj.is_comfortable[12] == 1
    assert utci_obj.is_comfortable[23] == 0

    assert isinstance(utci_obj.thermal_condition, HourlyContinuousCollection)
    assert len(utci_obj.thermal_condition.values) == calc_length
    assert utci_obj.thermal_condition[0] == -1
    assert utci_obj.thermal_condition[12] == 0
    assert utci_obj.thermal_condition[23] == 1

    assert isinstance(utci_obj.thermal_condition_five_point, HourlyContinuousCollection)
    assert len(utci_obj.thermal_condition_five_point.values) == calc_length
    assert utci_obj.thermal_condition_five_point[0] == -1
    assert utci_obj.thermal_condition_five_point[12] == 0
    assert utci_obj.thermal_condition_five_point[23] == 1

    assert isinstance(utci_obj.thermal_condition_seven_point, HourlyContinuousCollection)
    assert len(utci_obj.thermal_condition_seven_point.values) == calc_length
    assert utci_obj.thermal_condition_seven_point[0] == -1
    assert utci_obj.thermal_condition_seven_point[12] == 0
    assert utci_obj.thermal_condition_seven_point[23] == 1

    assert isinstance(utci_obj.thermal_condition_nine_point, HourlyContinuousCollection)
    assert len(utci_obj.thermal_condition_nine_point.values) == calc_length
    assert utci_obj.thermal_condition_nine_point[0] == -1
    assert utci_obj.thermal_condition_nine_point[12] == 0
    assert utci_obj.thermal_condition_nine_point[22] == 1
    assert utci_obj.thermal_condition_nine_point[23] == 2

    assert isinstance(utci_obj.thermal_condition_eleven_point, HourlyContinuousCollection)
    assert len(utci_obj.thermal_condition_eleven_point.values) == calc_length
    assert utci_obj.thermal_condition_eleven_point[0] == -1
    assert utci_obj.thermal_condition_eleven_point[12] == 0
    assert utci_obj.thermal_condition_eleven_point[22] == 1
    assert utci_obj.thermal_condition_eleven_point[23] == 2

    assert isinstance(utci_obj.original_utci_category, HourlyContinuousCollection)
    assert len(utci_obj.original_utci_category.values) == calc_length
    assert utci_obj.original_utci_category[0] == 4
    assert utci_obj.original_utci_category[12] == 5
    assert utci_obj.original_utci_category[23] == 6
Ejemplo n.º 14
0
def test_hourlyplot_reversed_analysis_period():
    """Test the initialization of MonthlyChart with a reversed analysis period."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(range(8760))
    data_coll = HourlyContinuousCollection(header, values)
    period = AnalysisPeriod(12, 1, 0, 1, 31, 23)
    data_coll = data_coll.filter_by_analysis_period(period)
    month_chart = MonthlyChart([data_coll])

    assert month_chart.analysis_period == period
    meshes = month_chart.data_meshes
    assert len(meshes) == 1
    assert isinstance(meshes[0], Mesh2D)
    assert len(meshes[0].faces) == 2 * 24
Ejemplo n.º 15
0
def test_percentile_monthly_per_hour():
    """Test the percentile monthly per hour method."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(24)) * 365
    dc = HourlyContinuousCollection(header, values)
    new_dc = dc.percentile_monthly_per_hour(25)
    assert isinstance(new_dc, MonthlyPerHourCollection)
    assert len(new_dc) == 12 * 24
    assert new_dc.datetimes[0] == (1, 0)
    assert new_dc.datetimes[-1] == (12, 23)
    assert new_dc.is_continuous is True
    pct_vals = list(xrange(24)) * 12
    for i, val in enumerate(pct_vals):
        assert new_dc[i] == val
Ejemplo n.º 16
0
def test_init_graphic_con_data_type():
    """Test the initialization of GraphicContainer objects with a DataType."""
    mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
    mesh3d = Mesh3D.from_mesh2d(mesh2d)
    data = [-1, 0, 1, 2]
    graphic_con = GraphicContainer(data,
                                   mesh3d.min,
                                   mesh3d.max,
                                   data_type=Temperature())

    assert graphic_con.legend_parameters.is_title_default is False
    assert graphic_con.legend_parameters.title == 'C'

    legend_par = LegendParameters()
    legend_par.vertical = False
    graphic_con = GraphicContainer(data,
                                   mesh3d.min,
                                   mesh3d.max,
                                   legend_par,
                                   data_type=Temperature())

    assert graphic_con.legend_parameters.is_title_default is False
    assert graphic_con.legend_parameters.title == 'Temperature (C)'
Ejemplo n.º 17
0
def test_init_pmv_collection_full_collection_input():
    """Test initialization of the PMV collection will all inputs as collections."""
    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)
    rel_humid_header = Header(RelativeHumidity(), '%',
                              AnalysisPeriod(end_month=1, end_day=1))
    rel_humid = HourlyContinuousCollection(rel_humid_header,
                                           [50] * calc_length)
    rad_temp_header = Header(Temperature(), 'C',
                             AnalysisPeriod(end_month=1, end_day=1))
    rad_temp = HourlyContinuousCollection(rad_temp_header, [22] * calc_length)
    air_speed_header = Header(AirSpeed(), 'm/s',
                              AnalysisPeriod(end_month=1, end_day=1))
    air_speed = HourlyContinuousCollection(air_speed_header,
                                           [0.5] * calc_length)
    met_header = Header(MetabolicRate(), 'met',
                        AnalysisPeriod(end_month=1, end_day=1))
    met_rate = HourlyContinuousCollection(met_header, [1.2] * calc_length)
    clo_header = Header(ClothingInsulation(), 'clo',
                        AnalysisPeriod(end_month=1, end_day=1))
    clo_level = HourlyContinuousCollection(clo_header, [0.85] * calc_length)
    work_header = Header(MetabolicRate(), 'met',
                         AnalysisPeriod(end_month=1, end_day=1))
    ext_work = HourlyContinuousCollection(work_header, [0.1] * calc_length)

    pmv_obj = PMV(air_temp, rel_humid, rad_temp, air_speed, met_rate,
                  clo_level, ext_work)

    assert pmv_obj.air_temperature[0] == 24
    assert pmv_obj.rel_humidity[0] == 50
    assert pmv_obj.rad_temperature[0] == 22
    assert pmv_obj.air_speed[0] == 0.5
    assert pmv_obj.met_rate[0] == 1.2
    assert pmv_obj.clo_value[0] == 0.85
    assert pmv_obj.external_work[0] == 0.1
Ejemplo n.º 18
0
def test_colorfaces_init():
    """Test the initialization of ColorFace and basic properties."""
    data = []
    identifiers = ['Bottom', 'Front', 'Right', 'Back', 'Left', 'Top']
    for identifier in identifiers:
        metadata = {
            'type': 'Surface Inside Face Temperature',
            'Surface': 'RESIDENCE_{}'.format(identifier.upper())
        }
        head = Header(Temperature(), 'C', AnalysisPeriod(1, 1, 0, 1, 1, 23),
                      metadata)
        data.append(HourlyContinuousCollection(head, [22] * 24))

    room = Room.from_box('Residence', 3, 6, 3.2)
    color_obj = ColorFace(data, room.faces)

    str(color_obj)
    assert len(color_obj.data_collections) == 6
    for coll in color_obj.data_collections:
        assert isinstance(coll, HourlyContinuousCollection)
        assert coll.header.unit == 'C'
    assert isinstance(color_obj.legend_parameters, LegendParameters)
    assert color_obj.simulation_step is None
    assert color_obj.normalize
    assert color_obj.geo_unit == 'm'
    assert len(color_obj.matched_flat_faces) == 6
    assert len(color_obj.matched_values) == 6
    for val in color_obj.matched_values:
        assert isinstance(val, (float, int))
    assert len(color_obj.matched_flat_geometry) == 6
    for face3d in color_obj.matched_flat_geometry:
        assert isinstance(face3d, Face3D)
    assert len(color_obj.matched_flat_areas) == 6
    for val in color_obj.matched_flat_areas:
        assert isinstance(val, (float, int))
    assert isinstance(color_obj.graphic_container, GraphicContainer)
    assert len(color_obj.graphic_container.value_colors) == 6
    assert color_obj.unit == 'C'
    assert isinstance(color_obj.data_type, Temperature)
    assert color_obj.data_type_text == 'Surface Inside Face Temperature'
    assert color_obj.title_text == 'Average Surface Inside Face Temperature ' \
        '(C)\n1/1 to 1/1 between 0 and 23 '

    color_obj.simulation_step = 0
    assert color_obj.title_text == 'Surface Inside Face Temperature ' \
        '(C)\n01 Jan 00:00'

    with pytest.raises(AssertionError):
        color_obj.simulation_step = 8760
Ejemplo n.º 19
0
def test_init():
    """Test the init methods for base collections."""
    a_per = AnalysisPeriod(6, 21, 12, 6, 21, 13)
    dt1, dt2 = DateTime(6, 21, 12), DateTime(6, 21, 13)
    v1, v2 = 20, 25
    avg = (v1 + v2) / 2
    # Setup data collection
    dc1 = BaseCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                         [dt1, dt2])

    assert dc1.datetimes == (dt1, dt2)
    assert dc1.values == (v1, v2)
    assert dc1.average == avg
    str(dc1)  # Test the string representation of the collection
    str(dc1.header)  # Test the string representation of the header
Ejemplo n.º 20
0
def test_init_utci_collection_full_collection_input():
    """Test initialization of the UTCI collection will all inputs as collections."""
    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)
    rel_humid_header = Header(RelativeHumidity(), '%',
                              AnalysisPeriod(end_month=1, end_day=1))
    rel_humid = HourlyContinuousCollection(rel_humid_header,
                                           [50] * calc_length)
    rad_temp_header = Header(Temperature(), 'C',
                             AnalysisPeriod(end_month=1, end_day=1))
    rad_temp = HourlyContinuousCollection(rad_temp_header, [22] * calc_length)
    wind_speed_header = Header(AirSpeed(), 'm/s',
                               AnalysisPeriod(end_month=1, end_day=1))
    wind_speed = HourlyContinuousCollection(wind_speed_header,
                                            [0.5] * calc_length)

    utci_obj = UTCI(air_temp, rel_humid, rad_temp, wind_speed)

    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
Ejemplo n.º 21
0
def test_adaptive_collection_cooling_effect_output():
    """Test the cooling effect output of 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, air_speed=0.7)

    assert isinstance(adapt_obj.cooling_effect, HourlyContinuousCollection)
    assert len(adapt_obj.cooling_effect.values) == calc_length
    assert adapt_obj.cooling_effect[0] == 1.2
Ejemplo n.º 22
0
def test_init_monthly():
    """Test the init methods for monthly collections."""
    a_per = AnalysisPeriod(6, 1, 0, 7, 31, 23)
    v1, v2 = 20, 25
    avg = (v1 + v2) / 2
    # Setup data collection
    dc1 = MonthlyCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                            a_per.months_int)

    assert dc1.datetimes == tuple(a_per.months_int)
    assert dc1.values == (v1, v2)
    assert dc1.average == avg
    assert dc1.is_continuous is False
    str(dc1)  # Test the string representation of the collection
    str(dc1.header)  # Test the string representation of the header
Ejemplo n.º 23
0
def test_init_monthly_per_hour():
    """Test the init methods for monthly per hour collections."""
    a_per = AnalysisPeriod(6, 1, 0, 7, 31, 23)
    vals = [20] * 24 + [25] * 24
    avg = sum(vals) / 48
    # Setup data collection
    dc1 = MonthlyPerHourCollection(Header(Temperature(), 'C', a_per), vals,
                                   a_per.months_per_hour)

    assert dc1.datetimes == tuple(a_per.months_per_hour)
    assert dc1.values == tuple(vals)
    assert dc1.average == avg
    assert dc1.is_continuous is False
    str(dc1)  # Test the string representation of the collection
    str(dc1.header)  # Test the string representation of the header
Ejemplo n.º 24
0
def test_hourlyplot_reversed_analysis_period():
    """Test the initialization of HourlyPlot with a reversed analysis period."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(range(8760))
    data_coll = HourlyContinuousCollection(header, values)
    period = AnalysisPeriod(12, 1, 0, 1, 31, 23)
    data_coll = data_coll.filter_by_analysis_period(period)
    hour_plot = HourlyPlot(data_coll, y_dim=1)

    assert hour_plot.analysis_period == period
    mesh = hour_plot.colored_mesh2d
    assert isinstance(mesh, Mesh2D)
    assert len(mesh.faces) == 31 * 2 * 24
    assert mesh.min == Point2D(0, 0)
    assert mesh.max == Point2D(31 * 2, 24)
Ejemplo n.º 25
0
def test_setting_values_continuous():
    """Test the methods for setting values on the continuous data collection"""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyContinuousCollection(header, values)

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

    # make sure that people can't change the number of values
    with pytest.raises(Exception):
        dc.values.append(10)
Ejemplo n.º 26
0
def test_get_percentile():
    """Test the get_percentile method."""
    header1 = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(8760))
    dc = HourlyContinuousCollection(header1, values)

    assert dc.get_percentile(0) == 0
    assert dc.get_percentile(25) == 2189.75
    assert dc.get_percentile(50) == 4379.5
    assert dc.get_percentile(75) == 6569.25
    assert dc.get_percentile(100) == 8759

    with pytest.raises(Exception):
        dc.get_percentile(-10)
    with pytest.raises(Exception):
        dc.get_percentile(110)
Ejemplo n.º 27
0
def test_get_aligned_collection_continuous():
    """Test the method for getting an aligned continuous collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1))
    values = list(xrange(24))
    dc1 = HourlyContinuousCollection(header, values)
    dc2 = dc1.get_aligned_collection(50)
    assert dc1.header.data_type.name == dc2.header.data_type.name
    assert dc1.header.unit == dc2.header.unit
    assert dc1.header.analysis_period == dc2.header.analysis_period
    assert dc1.header.metadata == dc2.header.metadata
    assert len(dc1.values) == len(dc2.values)
    assert dc2.values == tuple([50] * 24)

    dc3 = dc1.get_aligned_collection(50, RelativeHumidity(), '%')
    assert dc3.header.data_type.name == 'Relative Humidity'
    assert dc3.header.unit == '%'
Ejemplo n.º 28
0
def test_pmv_collection_heat_loss_outputs():
    """Test the heat loss 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, [24] * calc_length)
    pmv_obj = PMV(air_temp, 50, air_speed=0.5)

    assert isinstance(pmv_obj.adjusted_air_temperature,
                      HourlyContinuousCollection)
    assert len(pmv_obj.adjusted_air_temperature.values) == calc_length
    assert pmv_obj.adjusted_air_temperature[0] == pytest.approx(21.79,
                                                                rel=1e-2)

    assert isinstance(pmv_obj.cooling_effect, HourlyContinuousCollection)
    assert len(pmv_obj.cooling_effect.values) == calc_length
    assert pmv_obj.cooling_effect[0] == pytest.approx(2.215, rel=1e-2)

    assert isinstance(pmv_obj.heat_loss_conduction, HourlyContinuousCollection)
    assert len(pmv_obj.heat_loss_conduction.values) == calc_length
    assert pmv_obj.heat_loss_conduction[0] == pytest.approx(12.14, rel=1e-2)

    assert isinstance(pmv_obj.heat_loss_sweating, HourlyContinuousCollection)
    assert len(pmv_obj.heat_loss_sweating.values) == calc_length
    assert pmv_obj.heat_loss_sweating[0] == pytest.approx(2.44, rel=1e-2)

    assert isinstance(pmv_obj.heat_loss_latent_respiration,
                      HourlyContinuousCollection)
    assert len(pmv_obj.heat_loss_latent_respiration.values) == calc_length
    assert pmv_obj.heat_loss_latent_respiration[0] == pytest.approx(4.95,
                                                                    rel=1e-2)

    assert isinstance(pmv_obj.heat_loss_dry_respiration,
                      HourlyContinuousCollection)
    assert len(pmv_obj.heat_loss_dry_respiration.values) == calc_length
    assert pmv_obj.heat_loss_dry_respiration[0] == pytest.approx(1.093,
                                                                 rel=1e-2)

    assert isinstance(pmv_obj.heat_loss_radiation, HourlyContinuousCollection)
    assert len(pmv_obj.heat_loss_radiation.values) == calc_length
    assert pmv_obj.heat_loss_radiation[0] == pytest.approx(28.78, rel=1e-2)

    assert isinstance(pmv_obj.heat_loss_convection, HourlyContinuousCollection)
    assert len(pmv_obj.heat_loss_convection.values) == calc_length
    assert pmv_obj.heat_loss_convection[0] == pytest.approx(26.296, rel=1e-2)
Ejemplo n.º 29
0
def test_init_adaptive_collection_full_collection_input():
    """Test initialization of the Adaptive collection with inputs as collections."""
    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)
    air_speed_header = Header(AirSpeed(), 'm/s',
                              AnalysisPeriod(end_month=1, end_day=1))
    air_speed = HourlyContinuousCollection(air_speed_header,
                                           [0.7] * calc_length)
    adapt_obj = Adaptive(prevail_temp, op_temp, air_speed)

    assert adapt_obj.operative_temperature[0] == 26
    assert adapt_obj.air_speed[0] == 0.7
Ejemplo n.º 30
0
def test_cull_to_timestep():
    """Test the test_cull_to_timestep method on the discontinuous collection."""
    a_per = AnalysisPeriod(6, 21, 0, 6, 21, 23)
    dt1, dt2, dt3 = DateTime(6, 21, 12), DateTime(6, 21,
                                                  13), DateTime(6, 21, 12, 30)
    v1, v2 = 20, 25
    dc1 = HourlyDiscontinuousCollection(Header(Temperature(), 'C', a_per),
                                        [v1, v2, v2], [dt1, dt3, dt2])
    dc1_new = dc1.validate_analysis_period()
    dc2_new = dc1.cull_to_timestep()
    assert dc1_new.header.analysis_period.timestep == 2
    assert dc2_new.header.analysis_period.timestep == 1
    assert len(dc1_new.values) == 3
    assert len(dc2_new.values) == 2

    dc1_new.convert_to_culled_timestep()
    assert dc1_new.header.analysis_period.timestep == 1
    assert len(dc1_new.values) == 2