コード例 #1
0
    def test_get_aligned_collection_continuous(self):
        """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, RelativeHumidity(), '%')
        assert dc2.header.data_type.name == 'Relative Humidity'
        assert dc2.header.unit == '%'
        assert isinstance(dc2, HourlyContinuousCollection)
        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, HourlyContinuousCollectionImmutable)
        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, HourlyContinuousCollection)
        assert dc4.is_mutable is True
コード例 #2
0
def test_monthlychart_two_axes():
    """Test the MonthlyChart with two Y-axes."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = [i for i in range(12)]
    date_t = list(range(1, 13))
    data_coll = MonthlyCollection(header, values, date_t)

    header2 = Header(RelativeHumidity(), '%', AnalysisPeriod())
    values2 = [i for i in range(10, 70, 5)]
    data_coll2 = MonthlyCollection(header2, values2, date_t)
    month_chart = MonthlyChart([data_coll, data_coll2])

    y_txt = month_chart.y_axis_labels2
    assert all(isinstance(txt, str) for txt in y_txt)
    y_lines = month_chart.y_axis_lines
    y_pts = month_chart.y_axis_label_points2
    assert len(y_lines) == len(y_txt) == len(y_pts) == 11
    assert all(isinstance(line, LineSegment2D) for line in y_lines)
    assert all(isinstance(pt, Point2D) for pt in y_pts)
    assert isinstance(month_chart.y_axis_title_text2, str)
    assert 'Fraction' in month_chart.y_axis_title_text2
    assert isinstance(month_chart.y_axis_title_location2, Plane)

    # ensure the first axis was not affected
    y_txt = month_chart.y_axis_labels1
    assert all(isinstance(txt, str) for txt in y_txt)
    y_pts = month_chart.y_axis_label_points1
    assert len(y_lines) == len(y_txt) == len(y_pts) == 11
    assert all(isinstance(pt, Point2D) for pt in y_pts)
    assert isinstance(month_chart.y_axis_title_text1, str)
    assert 'Temperature' in month_chart.y_axis_title_text1
    assert isinstance(month_chart.y_axis_title_location1, Plane)
コード例 #3
0
def test_monthlychart_daily():
    """Test the initialization of MonthlyChart with daily data collections."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = [i / 31 for i in range(365)]
    date_t = list(range(1, 366))
    data_coll = DailyCollection(header, values, date_t)
    month_chart = MonthlyChart([data_coll])

    meshes = month_chart.data_meshes
    assert len(meshes) == 1
    assert isinstance(meshes[0], Mesh2D)
    assert len(meshes[0].faces) == 365
    assert month_chart.data_polylines is None

    header2 = Header(RelativeHumidity(), '%', AnalysisPeriod())
    values2 = [i / 31 for i in range(365)]
    data_coll2 = DailyCollection(header2, values2, date_t)
    month_chart = MonthlyChart([data_coll, data_coll2])

    meshes = month_chart.data_meshes
    assert len(meshes) == 2
    assert isinstance(meshes[1], Mesh2D)
    assert len(meshes[1].faces) == 365

    month_chart = MonthlyChart([data_coll, data_coll2], stack=True)
    meshes = month_chart.data_meshes
    assert len(meshes) == 2
    assert isinstance(meshes[1], Mesh2D)
    assert len(meshes[1].faces) == 365
コード例 #4
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
コード例 #5
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 == '%'
コード例 #6
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
コード例 #7
0
def test_monthlychart_monthly_per_hour():
    """Test the initialization of MonthlyChart with monthly-per-hour data collections."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = list(range(12 * 24))
    date_t = AnalysisPeriod().months_per_hour
    data_coll = MonthlyPerHourCollection(header, values, date_t)
    month_chart = MonthlyChart([data_coll])

    assert month_chart.data_meshes is None
    plines = month_chart.data_polylines
    assert isinstance(plines[0], Polyline2D)
    assert len(plines) == 12

    header2 = Header(RelativeHumidity(), '%', AnalysisPeriod())
    values2 = [x / 10 for x in range(12 * 24)]
    data_coll2 = MonthlyPerHourCollection(header2, values2, date_t)
    month_chart = MonthlyChart([data_coll, data_coll2])

    plines = month_chart.data_polylines
    assert isinstance(plines[0], Polyline2D)
    assert len(plines) == 12 * 2
コード例 #8
0
def test_monthlychart_set_min_max_by_index():
    """Test the set_minimum_by_index amd set_maximum_by_index methods."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = [i for i in range(12)]
    date_t = list(range(1, 13))
    data_coll = MonthlyCollection(header, values, date_t)
    header2 = Header(RelativeHumidity(), '%', AnalysisPeriod())
    values2 = [i for i in range(10, 70, 5)]
    data_coll2 = MonthlyCollection(header2, values2, date_t)
    l_par = LegendParameters(min=-20, max=40)
    l_par.decimal_count = 0

    month_chart = MonthlyChart([data_coll, data_coll2], legend_parameters=l_par)

    assert month_chart.y_axis_labels1[0] == '-20'
    assert month_chart.y_axis_labels1[-1] == '40'

    month_chart.set_minimum_by_index(0, 1)
    assert month_chart.y_axis_labels2[0] == '0'
    month_chart.set_maximum_by_index(100, 1)
    assert month_chart.y_axis_labels2[-1] == '100'
コード例 #9
0
        _dry_bulb: A value or data collection representing dry bulb temperature [C]
        _dew_point: A value or data collection representing dew point temperature [C]
    
    Returns:
        rel_humid: A data collection or value indicating the relative humidity [%]
"""

ghenv.Component.Name = "LB Relative Humidity from Dew Point"
ghenv.Component.NickName = 'RelHumid'
ghenv.Component.Message = '1.0.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:
    from ladybug.psychrometrics import rel_humid_from_db_dpt
    from ladybug.datacollection import HourlyContinuousCollection
    from ladybug.datatype.fraction import RelativeHumidity
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    rel_humid = HourlyContinuousCollection.compute_function_aligned(
        rel_humid_from_db_dpt, [_dry_bulb, _dew_point], RelativeHumidity(),
        '%')
コード例 #10
0
    if _atmos_pressure_:
        epw_obj.atmospheric_station_pressure.values = check_data(
            '_atmos_pressure_', _atmos_pressure_, Pressure, 'Pa', leap_yr)
    if _visibility_:
        epw_obj.visibility.values = check_data(
            '_visibility_', _visibility_, Distance, 'km', leap_yr)
    if _ceiling_height_:
        epw_obj.ceiling_height.values = check_data(
            '_ceiling_height_', _ceiling_height_, Distance, 'm', leap_yr)
    if _model_year_:
        epw_obj.years.values = _model_year_.values
    
    # calculate properties that are derived from other inputs
    if _dry_bulb_temp_ and _dew_point_temp_:
        rel_humid = HourlyContinuousCollection.compute_function_aligned(
            rel_humid_from_db_dpt, [_dry_bulb_temp_, _dew_point_temp_],
            RelativeHumidity(), '%')
        epw_obj.relative_humidity.values = rel_humid.values
    if _direct_normal_rad_ and _diffuse_horiz_rad_:
        wea = Wea(_location, _direct_normal_rad_, _diffuse_horiz_rad_)
        epw_obj.global_horizontal_radiation.values = wea.global_horizontal_irradiance.values
    if _direct_normal_ill_ and _diffuse_horiz_ill_:
        glob_horiz = []
        sp = Sunpath.from_location(_location)
        sp.is_leap_year = leap_yr
        for dt, dni, dhi in zip(_direct_normal_ill_.datetimes,
                _direct_normal_ill_, _diffuse_horiz_ill_):
            sun = sp.calculate_sun_from_date_time(dt)
            glob_horiz.append(dhi + dni * math.sin(math.radians(sun.altitude)))
        epw_obj.global_horizontal_radiation.values = glob_horiz