Skip to content

Commit

Permalink
feat(datatype): Added data types for Specific Energy (Enthalpy) and T…
Browse files Browse the repository at this point in the history
…emperature Time (Degree Days)

Also, I started regretting that the data type for handling fractional values was written as 'percentage' instead of 'fraction.' It seems that I was narrow-mindedly thinking of relative humidity in EPW files when I set up that type. So I am fixing it here before we start having more dependencies on it. Right now, it shouldn't really break anything outside of the API.
  • Loading branch information
Chris Mackey authored Mar 8, 2019
2 parents ceae4e2 + 8a5c5d9 commit e8ec5a7
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 60 deletions.
86 changes: 43 additions & 43 deletions ladybug/datatype/percentage.py → ladybug/datatype/fraction.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# coding=utf-8
"""Percentage data type."""
"""Fraction data type."""
from __future__ import division

from .base import DataTypeBase


class Percentage(DataTypeBase):
"""Percentage"""
_units = ('%', 'fraction', 'tenths', 'thousandths', 'okta')
_si_units = ('%', 'fraction', 'tenths', 'thousandths', 'okta')
_ip_units = ('%', 'fraction', 'tenths', 'thousandths', 'okta')
class Fraction(DataTypeBase):
"""Fraction"""
_units = ('fraction', '%', 'tenths', 'thousandths', 'okta')
_si_units = ('fraction', '%', 'tenths', 'thousandths', 'okta')
_ip_units = ('fraction', '%', 'tenths', 'thousandths', 'okta')
_abbreviation = 'Pct'

def _pct_to_fraction(self, value):
return value / 100.

def _pct_to_tenths(self, value):
return value / 10.
def _fraction_to_pct(self, value):
return value * 100.

def _pct_to_thousandths(self, value):
def _fraction_to_tenths(self, value):
return value * 10.

def _pct_to_okta(self, value):
return value / 12.5
def _fraction_to_thousandths(self, value):
return value * 1000.

def _fraction_to_pct(self, value):
return value * 100.
def _fraction_to_okta(self, value):
return value * 12.5

def _tenths_to_pct(self, value):
return value * 10.
def _pct_to_fraction(self, value):
return value / 100.

def _thousandths_to_pct(self, value):
def _tenths_to_fraction(self, value):
return value / 10.

def _okta_to_pct(self, value):
return value * 12.5
def _thousandths_to_fraction(self, value):
return value / 1000.

def _okta_to_fraction(self, value):
return value / 12.5

def to_unit(self, values, unit, from_unit):
"""Return values converted to the unit given the input from_unit."""
return self._to_unit_base('%', values, unit, from_unit)
return self._to_unit_base('fraction', 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."""
Expand All @@ -49,72 +49,72 @@ def to_si(self, values, from_unit):
return values, from_unit

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


class PercentagePeopleDissatisfied(Percentage):
class PercentagePeopleDissatisfied(Fraction):
_min = 0
_max = 100
_max = 1
_abbreviation = 'PPD'


class RelativeHumidity(Percentage):
class RelativeHumidity(Fraction):
_min = 0
_abbreviation = 'RH'
_min_epw = 0
_max_epw = 110
_max_epw = 1.1
_missing_epw = 999


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


class TotalSkyCover(Percentage):
class TotalSkyCover(Fraction):
# (used if Horizontal IR Intensity missing)
_min = 0
_max = 100
_max = 1
_abbreviation = 'CC'
_min_epw = 0
_max_epw = 100
_max_epw = 1
_missing_epw = 99


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


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


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


class LiquidPrecipitationQuantity(Percentage):
class LiquidPrecipitationQuantity(Fraction):
_min = 0
_abbreviation = 'LPQ'
_min_epw = 0
_max_epw = 100
_max_epw = 1
_missing_epw = 99
77 changes: 77 additions & 0 deletions ladybug/datatype/specificenergy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# coding=utf-8
"""Energy data type."""
from __future__ import division

from .base import DataTypeBase


class SpecificEnergy(DataTypeBase):
"""Energy"""
_units = ('kWh/kg', 'kBtu/lb', 'Wh/kg', 'Btu/lb', 'J/kg', 'kJ/kg')
_si_units = ('kWh/kg', 'Wh/kg', 'J/kg', 'kJ/kg')
_ip_units = ('Btu/lb', 'kBtu/lb')
_abbreviation = 'E/m'
_point_in_time = False
_cumulative = True

def _kWh_kg_to_kBtu_lb(self, value):
return value * 1.54772

def _kWh_kg_to_Wh_kg(self, value):
return value * 1000.

def _kWh_kg_to_Btu_lb(self, value):
return value * 1547.72

def _kWh_kg_to_J_kg(self, value):
return value * 3600000.

def _kWh_kg_to_kJ_kg(self, value):
return value * 3600.

def _kBtu_lb_to_kWh_kg(self, value):
return value / 1.54772

def _Wh_kg_to_kWh_kg(self, value):
return value / 1000.

def _Btu_lb_to_kWh_kg(self, value):
return value / 1547.72

def _J_kg_to_kWh_kg(self, value):
return value / 3600000.

def _kJ_kg_to_kWh_kg(self, value):
return value / 3600.

def to_unit(self, values, unit, from_unit):
"""Return values converted to the unit given the input from_unit."""
return self._to_unit_base('kWh/kg', 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 in self.ip_units:
return values, from_unit
elif from_unit == 'kJ/kg':
return self.to_unit(values, 'Btu/lb', from_unit), 'Btu/lb'
else:
return self.to_unit(values, 'kBtu/lb', from_unit), 'kBtu/lb'

def to_si(self, values, from_unit):
"""Return values in SI and the units to which the values have been converted."""
if from_unit in self.si_units:
return values, from_unit
elif from_unit == 'Btu/lb':
return self.to_unit(values, 'kJ/kg', from_unit), 'kJ/kg'
else:
return self.to_unit(values, 'kWh/kg', from_unit), 'kWh/kg'

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


class Enthalpy(SpecificEnergy):
_abbreviation = 'Enth'
_min = 0
4 changes: 4 additions & 0 deletions ladybug/datatype/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class DewPointTemperature(Temperature):
_missing_epw = 99.9


class WetBulbTemperature(Temperature):
_abbreviation = 'WBT'


class SkyTemperature(Temperature):
_abbreviation = 'Tsky'

Expand Down
66 changes: 66 additions & 0 deletions ladybug/datatype/temperaturetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# coding=utf-8
"""Temperature-Time data type."""
from __future__ import division

from .base import DataTypeBase


class TemperatureTime(DataTypeBase):
"""Temperature-Time"""
_units = ('degC-days', 'degF-days', 'degC-hours', 'degF-hours')
_si_units = ('degC-days', 'degC-hours')
_ip_units = ('degF-days', 'degF-hours')
_abbreviation = 'degTime'

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

def _degCdays_to_degChours(self, value):
return value * 24.

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

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

def _degChours_to_degCdays(self, value):
return value / 24.

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

def to_unit(self, values, unit, from_unit):
"""Return values converted to the unit given the input from_unit."""
return self._to_unit_base('degC-days', 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 in self._ip_units:
return values, from_unit
elif from_unit == 'degC-hours':
return self.to_unit(values, 'degF-hours', from_unit), 'degF-hours'
else:
return self.to_unit(values, 'degF-days', from_unit), 'degF-days'

def to_si(self, values, from_unit):
"""Return values in SI and the units to which the values have been converted."""
if from_unit in self._si_units:
return values, from_unit
elif from_unit == 'degF-hours':
return self.to_unit(values, 'degC-hours', from_unit), 'degC-hours'
else:
return self.to_unit(values, 'degC-days', from_unit), 'degC-days'

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


class CoolingDegreeTime(TemperatureTime):
_abbreviation = 'coolTime'


class HeatingDegreeTime(TemperatureTime):
_abbreviation = 'heatTime'
6 changes: 3 additions & 3 deletions ladybug/designday.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .sunpath import Sunpath

from .datatype import angle, energyflux, energyintensity, \
percentage, pressure, speed, temperature
fraction, pressure, speed, temperature

from .skymodel import ashrae_revised_clear_sky, \
ashrae_clear_sky, calc_horizontal_infrared
Expand Down Expand Up @@ -663,7 +663,7 @@ def hourly_relative_humidity(self):
rh_data = [rel_humid_from_db_dpt(x, y) for x, y in zip(
self._dry_bulb_condition.hourly_values, dpt_data)]
return self._get_daily_data_collections(
percentage.RelativeHumidity(), '%', rh_data)
fraction.RelativeHumidity(), '%', rh_data)

@property
def hourly_barometric_pressure(self):
Expand Down Expand Up @@ -705,7 +705,7 @@ def hourly_solar_radiation(self):
def hourly_sky_cover(self):
"""A data collection containing hourly sky cover values in tenths."""
return self._get_daily_data_collections(
percentage.TotalSkyCover(), 'tenths', self._sky_condition.hourly_sky_cover)
fraction.TotalSkyCover(), 'tenths', self._sky_condition.hourly_sky_cover)

@property
def hourly_horizontal_infrared(self):
Expand Down
Loading

0 comments on commit e8ec5a7

Please sign in to comment.