예제 #1
0
def test_validate_a_period_daily():
    """Test the validate_a_period methods for daily collections."""
    a_per = AnalysisPeriod(6, 21, 0, 6, 22, 23)
    v1, v2 = 20, 25
    dt1, dt2 = 172, 173

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

    # Test that the validate method with reversed analysis_periods.
    a_per_3 = AnalysisPeriod(6, 20, 0, 2, 20, 23)
    dt5 = 21
    dc1 = DailyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2, v2],
                          [dt1, dt2, dt5])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == a_per_3
    dc1 = DailyCollection(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
    dc1 = DailyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2],
                          [dt5, 22])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == a_per_3
    dc1 = DailyCollection(Header(Temperature(), 'C', a_per_3), [v1, v2],
                          [dt5, 60])
    dc1_new = dc1.validate_analysis_period()
    assert dc1_new.header.analysis_period == AnalysisPeriod()

    # Test that the validate method correctly identifies leap years.
    dc1 = DailyCollection(Header(Temperature(), 'C', a_per), [v1, v2, v2],
                          [dt1, dt2, 366])
    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 = DailyCollection(Header(Temperature(), 'C', a_per), [v1, v2],
                          [dt1, dt1])
    with pytest.raises(Exception):
        dc1_new = dc1.validate_analysis_period()
예제 #2
0
def test_filter_by_analysis_period_daily():
    """Test filtering by analysis period on daily collection."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(xrange(365))
    dc = DailyCollection(header, values, AnalysisPeriod().doys_int)
    dc = dc.validate_analysis_period()
    a_per = AnalysisPeriod(st_month=3, end_month=4, end_day=30)
    filt_dc = dc.filter_by_analysis_period(a_per)
    assert len(filt_dc) == 31 + 30
    assert filt_dc.header.analysis_period == a_per
    assert filt_dc.datetimes[0] == 31 + 28 + 1
    assert filt_dc.datetimes[-1] == 31 + 28 + 31 + 30
예제 #3
0
def test_init_prevailing_temperature_daily():
    """Test the PrevailingTemperature object with daily inputs."""
    outdoor_header = Header(Temperature(), 'C', AnalysisPeriod())
    outdoor_temp = DailyCollection(outdoor_header, range(365),
                                   AnalysisPeriod().doys_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

    prevail_obj = PrevailingTemperature(outdoor_temp, False)
    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