Skip to content

Commit

Permalink
fix(datatype): Putting epw missing, min, and max valules on EPW
Browse files Browse the repository at this point in the history
After realizing that the code for the epw values on the data type objects did not pass the smell test, we are putting them back on the EPW field object.  I now agree that this makes more sense and we never should have moved them.
  • Loading branch information
Chris Mackey committed Mar 9, 2019
1 parent 8a5c5d9 commit 61b6035
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 192 deletions.
7 changes: 1 addition & 6 deletions ladybug/_datacollectionbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,13 @@ def compute_function_aligned(funct, data_collections, data_type, unit):
return result

def is_in_data_type_range(self, raise_exception=True):
"""Check if the Data Collection values are in permissable ranges for the data_type.
"""Check if collection values are in physically possible ranges for the data_type.
If this method returns False, the Data Collection's data is
physically or mathematically impossible for the data_type."""
return self._header.data_type.is_in_range(
self._values, self._header.unit, raise_exception)

def is_in_epw_range(self, raise_exception=True):
"""Check if Data Collection values are in permissable ranges for EPW files."""
return self._header.data_type.is_in_range_epw(
self._values, self._header.unit, raise_exception)

@staticmethod
def _check_conditional_statement(statement, num_collections):
"""Method to check conditional statements to be sure that they are valid.
Expand Down
3 changes: 0 additions & 3 deletions ladybug/datatype/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ def isAngle(self):
class WindDirection(Angle):
_name = 'Wind Direction'
_abbreviation = 'WD'
_min_epw = 0
_max_epw = 360
_missing_epw = 999
70 changes: 1 addition & 69 deletions ladybug/datatype/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ class DataTypeBase(object):
when point_in_time is also True.
(False Examples: Temperature, Irradiance, Illuminance)
(True Examples: Energy, Radiation)
min_epw: Lower limit for the data type when it occurs in EPW files.
(Default: -inf)
max_epw: Upper limit for the data type when it occurs in EPW files.
(Default: +inf)
missing_epw: Missing value for the data type when it occurs in EPW files.
(Default: None)
"""
_name = None
_units = [None]
Expand All @@ -62,10 +56,6 @@ class DataTypeBase(object):
_point_in_time = True
_cumulative = False

_min_epw = float('-inf')
_max_epw = float('+inf')
_missing_epw = None

_type_enumeration = None

def __init__(self, name=None):
Expand Down Expand Up @@ -146,14 +136,8 @@ def to_si(self, values, from_unit=None):
'to_si is not implemented on %s' % self.__class__.__name__
)

def is_missing(self, value):
"""Check if a value contains missing data when in an EPW."""
if value == self.missing_epw:
return True
return False

def is_in_range(self, values, unit=None, raise_exception=True):
"""Check if a list of values is within acceptable ranges.
"""Check if a list of values is within physically/mathematically possible range.
Args:
values: A list of values.
Expand Down Expand Up @@ -187,43 +171,6 @@ def is_in_range(self, values, unit=None, raise_exception=True):
)
return True

def is_in_range_epw(self, values, unit=None, raise_exception=True):
"""Check if a list of values is within acceptable ranges for an EPW file.
Args:
values: A list of values.
unit: The unit of the values. If not specified, the default metric
unit will be assumed.
raise_exception: Set to True to raise an exception if not in range.
"""
self._is_numeric(values)
if unit is None or unit == self.units[0]:
minimum = self.min_epw
maximum = self.max_epw
else:
namespace = {'self': self}
self.is_unit_acceptable(unit, True)
min_statement = "self._{}_to_{}(self.min_epw)".format(
self._clean(self.units[0]), self._clean(unit))
max_statement = "self._{}_to_{}(self.max_epw)".format(
self._clean(self.units[0]), self._clean(unit))
minimum = eval(min_statement, namespace)
maximum = eval(max_statement, namespace)

for value in values:
if self.is_missing(value):
continue
if value < minimum or value > maximum:
if not raise_exception:
return False
else:
raise ValueError(
'{0} should be between {1} and {2}. Got {3}'.format(
self.__class__.__name__, self.min, self.max, value
)
)
return True

def duplicate(self):
"""Return a copy of the data type."""
return self.__class__(self.name)
Expand Down Expand Up @@ -328,21 +275,6 @@ def cumulative(self):
"""Whether the data type is cumulative."""
return self._cumulative

@property
def min_epw(self):
"""Minimum acceptable value for an EPW."""
return self._min_epw

@property
def max_epw(self):
"""Maxmimum acceptable value for an EPW."""
return self._max_epw

@property
def missing_epw(self):
"""Missing value for an EPW."""
return self._missing_epw

@property
def isDataType(self):
"""Return True."""
Expand Down
2 changes: 0 additions & 2 deletions ladybug/datatype/energyflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class EffectiveRadiantField(EnergyFlux):
class Irradiance(EnergyFlux):
_min = 0
_abbreviation = 'Qsolar'
_min_epw = 0
_missing_epw = 9999

@property
def isIrradiance(self):
Expand Down
2 changes: 0 additions & 2 deletions ladybug/datatype/energyintensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def isEnergyIntensity(self):
class Radiation(EnergyIntensity):
_min = 0
_abbreviation = 'Esolar'
_min_epw = 0
_missing_epw = 9999

@property
def isRadiation(self):
Expand Down
18 changes: 0 additions & 18 deletions ladybug/datatype/fraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ class PercentagePeopleDissatisfied(Fraction):
class RelativeHumidity(Fraction):
_min = 0
_abbreviation = 'RH'
_min_epw = 0
_max_epw = 1.1
_missing_epw = 999


class HumidityRatio(Fraction):
Expand All @@ -79,42 +76,27 @@ class TotalSkyCover(Fraction):
_min = 0
_max = 1
_abbreviation = 'CC'
_min_epw = 0
_max_epw = 1
_missing_epw = 99


class OpaqueSkyCover(Fraction):
# (used if Horizontal IR Intensity missing)
_min = 0
_max = 1
_abbreviation = 'OSC'
_min_epw = 0
_max_epw = 1
_missing_epw = 99


class AerosolOpticalDepth(Fraction):
_min = 0
_max = 1
_abbreviation = 'AOD'
_min_epw = 0
_max_epw = 1
_missing_epw = 0.999


class Albedo(Fraction):
_min = 0
_max = 1
_abbreviation = 'a'
_min_epw = 0
_max_epw = 1
_missing_epw = 0.999


class LiquidPrecipitationQuantity(Fraction):
_min = 0
_abbreviation = 'LPQ'
_min_epw = 0
_max_epw = 1
_missing_epw = 99
32 changes: 9 additions & 23 deletions ladybug/datatype/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
class GenericType(DataTypeBase):
"""Type for any data type that is not currently implemented."""
def __init__(self, name, unit, min=float('-inf'), max=float('+inf'),
abbreviation=None, unit_descr='', point_in_time=True,
cumulative=False, min_epw=float('-inf'), max_epw=float('+inf'),
missing_epw=None):
abbreviation=None, unit_descr=None, point_in_time=True,
cumulative=False):
"""Initalize Generic Type.
Args:
Expand All @@ -21,8 +20,10 @@ def __init__(self, name, unit, min=float('-inf'), max=float('+inf'),
max: Optional upper limit for the data type, values above which should be
physically or mathematically impossible. (Default: +inf)
abbreviation: An optional abbreviation for the data type as text.
unit_descr: An optional description of the units if numerical values
of these units relate to specific categories.
unit_descr: An optional dictionary describing categories that the numerical
values of the units relate to. For example:
{-1: 'Cold', 0: 'Neutral', +1: 'Hot'}
{0: 'False', 1: 'True'}
point_in_time: Boolean to note whether the data type represents conditions
at a single instant in time (True) as opposed to being an average or
accumulation over time (False) when it is found in hourly lists of data.
Expand All @@ -31,12 +32,6 @@ def __init__(self, name, unit, min=float('-inf'), max=float('+inf'),
is represented over time (True) or it can only be averaged over time
to be meaningful (False). Note that cumulative cannot be True
when point_in_time is also True. (Default: False)
min_epw: Lower limit for the data type when it occurs in EPW files.
(Default: -inf)
max_epw: Upper limit for the data type when it occurs in EPW files.
(Default: +inf)
missing_epw: Missing value for the data type when it occurs in EPW files.
(Default: None)
"""
assert isinstance(name, str), 'name must be a string. Got {}.'.format(type(name))
assert isinstance(unit, str), 'unit must be a string. Got {}.'.format(type(unit))
Expand All @@ -47,22 +42,16 @@ def __init__(self, name, unit, min=float('-inf'), max=float('+inf'),
if abbreviation is not None:
assert isinstance(abbreviation, str), 'abbreviation must be a ' \
'string. Got {}.'.format(type(abbreviation))
assert isinstance(unit_descr, str), 'unit_descr must be a ' \
'string. Got {}.'.format(type(unit_descr))
if unit_descr is not None:
assert isinstance(unit_descr, dict), 'unit_descr must be a ' \
'dictionary. Got {}.'.format(type(unit_descr))
assert isinstance(point_in_time, bool), 'point_in_time must be a ' \
'boolean. Got {}.'.format(type(point_in_time))
assert isinstance(cumulative, bool), 'cumulative must be a ' \
'boolean. Got {}.'.format(type(cumulative))
if point_in_time is True:
assert cumulative is False, 'cumulative cannot be True when ' \
'point_in_time is also True.'
assert isinstance(min_epw, (float, int)), 'min_epw must be a number. ' \
'Got {}.'.format(type(min_epw))
assert isinstance(max_epw, (float, int)), 'max_epw must be a number. ' \
'Got {}.'.format(type(max_epw))
if missing_epw is not None:
assert isinstance(missing_epw, (float, int)), 'missing_epw must be' \
'a number .Got {}.'.format(type(missing_epw))

self._name = name
self._units = [unit]
Expand All @@ -72,9 +61,6 @@ def __init__(self, name, unit, min=float('-inf'), max=float('+inf'),
self._unit_descr = unit_descr
self._point_in_time = point_in_time
self._cumulative = cumulative
self._min_epw = min_epw
self._max_epw = max_epw
self._missing_epw = missing_epw

def to_ip(self, values, from_unit):
"""Return values in IP and the units to which the values have been converted."""
Expand Down
2 changes: 0 additions & 2 deletions ladybug/datatype/illuminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Illuminance(DataTypeBase):
_min = 0
_abbreviation = 'Ev'
_point_in_time = False
_min_epw = 0
_missing_epw = 999999 # note will be missing if >= 999900

def _lux_to_fc(self, value):
return value / 10.7639
Expand Down
2 changes: 0 additions & 2 deletions ladybug/datatype/luminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Luminance(DataTypeBase):
_min = 0
_abbreviation = 'Lv'
_point_in_time = False
_min_epw = 0
_missing_epw = 9999 # note will be missing if >= 999900

def _cd_m2_to_cd_ft2(self, value):
return value / 10.7639
Expand Down
3 changes: 0 additions & 3 deletions ladybug/datatype/pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,3 @@ def isPressure(self):
class AtmosphericStationPressure(Pressure):
_min = 0
_abbreviation = 'Patm'
_min_epw = 31000
_max_epw = 120000
_missing_epw = 999999
3 changes: 0 additions & 3 deletions ladybug/datatype/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ def isSpeed(self):

class WindSpeed(Speed):
_abbreviation = 'WS'
_min_epw = 0
_max_epw = 40
_missing_epw = 999


class AirSpeed(Speed):
Expand Down
6 changes: 0 additions & 6 deletions ladybug/datatype/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,10 @@ def isTemperature(self):

class DryBulbTemperature(Temperature):
_abbreviation = 'DBT'
_min_epw = -70
_max_epw = 70
_missing_epw = 99.9


class DewPointTemperature(Temperature):
_abbreviation = 'DPT'
_min_epw = -70
_max_epw = 70
_missing_epw = 99.9


class WetBulbTemperature(Temperature):
Expand Down
Loading

0 comments on commit 61b6035

Please sign in to comment.