-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datatype): Added data types for Specific Energy (Enthalpy) and T…
…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
Showing
8 changed files
with
247 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.