def test_heating_degree_time_collection(): """Test the heat_index function with Data Collections.""" calc_length = 8760 relative_path = './tests/epw/chicago.epw' epw = EPW(relative_path) hourly_hi = HourlyContinuousCollection.compute_function_aligned( heat_index, [epw.dry_bulb_temperature, epw.relative_humidity], Temperature(), 'C') assert isinstance(hourly_hi, HourlyContinuousCollection) assert len(hourly_hi.values) == calc_length assert hourly_hi[4000] == pytest.approx(30.89833, rel=1e-3) hourly_category = HourlyContinuousCollection.compute_function_aligned( heat_index_warning_category, [hourly_hi], ThermalCondition(), 'condition') assert isinstance(hourly_category, HourlyContinuousCollection) assert len(hourly_category.values) == calc_length assert hourly_category[4000] == 1
def test_compute_function_aligned(): """Test the method for computing funtions with aligned collections.""" epw_file_path = './tests/fixtures/epw/chicago.epw' chicago_epw = EPW(epw_file_path) pressure_at_chicago = 95000 hr_inputs = [ chicago_epw.dry_bulb_temperature, chicago_epw.relative_humidity, pressure_at_chicago ] humid_ratio = HourlyContinuousCollection.compute_function_aligned( humid_ratio_from_db_rh, hr_inputs, HumidityRatio(), 'fraction') assert isinstance(humid_ratio, HourlyContinuousCollection) assert len(humid_ratio.values) == 8760 for i, val in enumerate(humid_ratio.values): assert val == humid_ratio_from_db_rh( chicago_epw.dry_bulb_temperature[i], chicago_epw.relative_humidity[i], pressure_at_chicago) hr_inputs = [20, 70, pressure_at_chicago] humid_ratio = HourlyContinuousCollection.compute_function_aligned( humid_ratio_from_db_rh, hr_inputs, HumidityRatio(), 'fraction') assert isinstance(humid_ratio, float) assert humid_ratio == humid_ratio_from_db_rh(20, 70, pressure_at_chicago)
def test_cooling_degree_time_collection(): """Test the cooling_degree_time function with Data Collections.""" calc_length = 8760 relative_path = './tests/epw/chicago.epw' epw = EPW(relative_path) hourly_cool = HourlyContinuousCollection.compute_function_aligned( cooling_degree_time, [epw.dry_bulb_temperature, 23], CoolingDegreeTime(), 'degC-hours') hourly_cool.convert_to_unit('degC-days') assert isinstance(hourly_cool, HourlyContinuousCollection) assert len(hourly_cool.values) == calc_length assert hourly_cool[4000] == pytest.approx(0.3375, rel=1e-3)
def test_heating_degree_time_collection(): """Test the heating_degree_time function with Data Collections.""" calc_length = 8760 relative_path = './tests/epw/chicago.epw' epw = EPW(relative_path) hourly_heat = HourlyContinuousCollection.compute_function_aligned( heating_degree_time, [epw.dry_bulb_temperature, 18], HeatingDegreeTime(), 'degC-hours') hourly_heat.convert_to_unit('degC-days') assert isinstance(hourly_heat, HourlyContinuousCollection) assert len(hourly_heat.values) == calc_length assert hourly_heat[0] == pytest.approx(1.004166, rel=1e-3)
try: from ladybug_comfort.degreetime import heating_degree_time, cooling_degree_time from ladybug.datacollection import HourlyContinuousCollection from ladybug.datatype.temperaturetime import HeatingDegreeTime, CoolingDegreeTime 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): if _heat_base_ is None: _heat_base_ = 18 if _cool_base_ is None: _cool_base_ = 23 hourly_heat = HourlyContinuousCollection.compute_function_aligned( heating_degree_time, [_dry_bulb, _heat_base_], HeatingDegreeTime(), 'degC-hours') hourly_heat.convert_to_unit('degC-days') hourly_cool = HourlyContinuousCollection.compute_function_aligned( cooling_degree_time, [_dry_bulb, _cool_base_], CoolingDegreeTime(), 'degC-hours') hourly_cool.convert_to_unit('degC-days') heat_deg_days = hourly_heat.total cool_deg_days = hourly_cool.total
wet_bulb_from_db_rh, dew_point_from_db_rh from ladybug.datacollection import HourlyContinuousCollection from ladybug.datatype.fraction import HumidityRatio from ladybug.datatype.specificenergy import Enthalpy from ladybug.datatype.temperature import WetBulbTemperature, DewPointTemperature 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): if _pressure_ is None: _pressure_ = 101325 humid_ratio = HourlyContinuousCollection.compute_function_aligned( humid_ratio_from_db_rh, [_dry_bulb, _rel_humid, _pressure_], HumidityRatio(), 'fraction') enthalpy = HourlyContinuousCollection.compute_function_aligned( enthalpy_from_db_hr, [_dry_bulb, humid_ratio], Enthalpy(), 'kJ/kg') wet_bulb = HourlyContinuousCollection.compute_function_aligned( wet_bulb_from_db_rh, [_dry_bulb, _rel_humid, _pressure_], WetBulbTemperature(), 'C') dew_point = HourlyContinuousCollection.compute_function_aligned( dew_point_from_db_rh, [_dry_bulb, _rel_humid], DewPointTemperature(), 'C')
_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(), '%')
_dew_point: A value or data collection representing dew point temperature [C] Returns: horiz_infrared: A data collection or value indicating the downwelling horizontal infrared radiation [W/m2] """ ghenv.Component.Name = 'DF Horizontal Infrared' ghenv.Component.NickName = 'HorizInfr' ghenv.Component.Message = '1.2.0' ghenv.Component.Category = 'Dragonfly' ghenv.Component.SubCategory = '4 :: AlternativeWeather' ghenv.Component.AdditionalHelpFromDocStrings = '5' try: from ladybug.skymodel import calc_horizontal_infrared from ladybug.datacollection import HourlyContinuousCollection from ladybug.datatype.energyflux import HorizontalInfraredRadiationIntensity 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): horiz_infrared = HourlyContinuousCollection.compute_function_aligned( calc_horizontal_infrared, [_sky_cover, _dry_bulb, _dew_point], HorizontalInfraredRadiationIntensity(), 'W/m2')
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # set default values _max_clo_ = _max_clo_ if _max_clo_ is not None else 1.0 _max_clo_temp_ = _max_clo_temp_ if _max_clo_temp_ is not None else -5 _min_clo_ = _min_clo_ if _min_clo_ is not None else 0.46 _min_clo_temp_ = _min_clo_temp_ if _min_clo_temp_ is not None else 26 # if the temperature is hourly continuous, simplify the values if isinstance(_temperature, HourlyContinuousCollection): date_times, temps = _temperature.datetimes, _temperature.values last_time, last_val = date_times[0].sub_hour(6), temps[0] new_vals = [] for v, dt in zip(temps, date_times): time_diff = dt - last_time if time_diff.seconds / 3600 >= 12: last_time, last_val = dt, v new_vals.append(last_val) _temperature = _temperature.duplicate() _temperature.values = new_vals # apply the analysis period if requests if period_ is not None and isinstance(_temperature, BaseCollection): _temperature = _temperature.filter_by_analysis_period(period_) clo = HourlyContinuousCollection.compute_function_aligned( schiavon_clo, [_temperature, _max_clo_, _max_clo_temp_, _min_clo_, _min_clo_temp_], ClothingInsulation(), 'clo')