Skip to content

Commit

Permalink
feat(datatype): Add new data types for thermal comfort
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Mackey committed Mar 2, 2019
1 parent 1b4ecec commit 1fe24a9
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
11 changes: 9 additions & 2 deletions ladybug/_datacollectionbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ def get_aligned_collection(self, value=0, data_type=None, unit=None):
number of values and have matching datetimes.
Args:
value: The value to be repeated in the aliged collection values.
value: A value to be repeated in the aliged collection values or
A list of values that has the same length as this collection.
Default: 0.
data_type: The data type of the aligned collection. Default is to
use the data type of this collection.
Expand All @@ -305,7 +306,13 @@ def get_aligned_collection(self, value=0, data_type=None, unit=None):
else:
data_type = self.header.data_type
unit = unit or self.header.unit
values = [value] * len(self._values)
if isinstance(value, Iterable) and not isinstance(value, (str, dict)):
assert len(value) == len(self._values), "Length of value ({}) must match "\
"the length of this collection's values ({})".format(
len(value), len(self._values))
values = value
else:
values = [value] * len(self._values)
header = Header(data_type, unit, self.header.analysis_period,
self.header.metadata)
collection = self.__class__(header, values, self.datetimes)
Expand Down
11 changes: 9 additions & 2 deletions ladybug/datacollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,8 @@ def get_aligned_collection(self, value=0, data_type=None, unit=None):
have the same number of values and have matching datetimes.
Args:
value: The value to be repeated in the aliged collection values.
value: A value to be repeated in the aliged collection values or
A list of values that has the same length as this collection.
Default: 0.
data_type: The data type of the aligned collection. Default is to
use the data type of this collection.
Expand All @@ -883,7 +884,13 @@ def get_aligned_collection(self, value=0, data_type=None, unit=None):
else:
data_type = self.header.data_type
unit = unit or self.header.unit
values = [value] * len(self._values)
if isinstance(value, Iterable) and not isinstance(value, (str, dict)):
assert len(value) == len(self._values), "Length of value ({}) must match "\
"the length of this collection's values ({})".format(
len(value), len(self._values))
values = value
else:
values = [value] * len(self._values)
header = Header(data_type, unit, self.header.analysis_period,
self.header.metadata)
return self.__class__(header, values)
Expand Down
6 changes: 6 additions & 0 deletions ladybug/datatype/percentage.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class RelativeHumidity(Percentage):
_missing_epw = 999


class HumidityRatio(Percentage):
_min = 0
_max = 100
_abbreviation = 'HR'


class TotalSkyCover(Percentage):
# (used if Horizontal IR Intensity missing)
_min = 0
Expand Down
60 changes: 60 additions & 0 deletions ladybug/datatype/temperaturedelta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# coding=utf-8
"""Temperature Delta data type."""
from __future__ import division

from .base import DataTypeBase


class TemperatureDelta(DataTypeBase):
"""Temperature"""
_units = ('C', 'F', 'K')
_si_units = ('C', 'K')
_ip_units = ('F')
_abbreviation = 'DeltaT'

def _C_to_F(self, value):
return value * 9. / 5.

def _C_to_K(self, value):
return value

def _F_to_C(self, value):
return value * (5. / 9.)

def _K_to_C(self, value):
return value

def to_unit(self, values, unit, from_unit):
"""Return values converted to the unit given the input from_unit."""
return self._to_unit_base('C', values, unit, from_unit)

def to_ip(self, values, from_unit):
"""Return values in IP and the units to which the values have been converted."""
if from_unit == 'F':
return values, from_unit
else:
return self.to_unit(values, 'F', from_unit), 'F'

def to_si(self, values, from_unit):
"""Return values in SI and the units to which the values have been converted."""
if from_unit == 'C' or from_unit == 'K':
return values, from_unit
else:
return self.to_unit(values, 'C', from_unit), 'C'

@property
def isTemperatureDelta(self):
"""Return True."""
return True


class AirTemperatureDelta(TemperatureDelta):
_abbreviation = 'DeltaTair'


class RadiantTemperatureDelta(TemperatureDelta):
_abbreviation = 'DeltaTrad'


class OperativeTemperatureDelta(TemperatureDelta):
_abbreviation = 'DeltaTo'
7 changes: 7 additions & 0 deletions ladybug/datatype/thermalcondition.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class PredictedMeanVote(ThermalCondition):
'+1 = Slightly Warm, +2 = Warm, +3 = Hot'


class DiscomfortReason(ThermalCondition):
_abbreviation = 'RDiscomf'
_unit_descr = '-2 = Too Dry, -1 = Too Cold, \n' \
'0 = Comfortable, \n' \
'+1 = Too Hot, +2 = Too Humid'


class UTCICondition(ThermalCondition):
_abbreviation = 'UTCIcond'
_unit_descr = '-4 = Extreme Cold, -3 = Very Strong Cold, '\
Expand Down

0 comments on commit 1fe24a9

Please sign in to comment.