Skip to content

Commit c344446

Browse files
committed
feat(datatype): Add several more units systems
This is needed to convert many of the inputs and outputs of EnergyPlus and DES simulations to IP.
1 parent b596c51 commit c344446

File tree

13 files changed

+373
-18
lines changed

13 files changed

+373
-18
lines changed

ladybug/datatype/conductance.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding=utf-8
2+
"""Conductance data type."""
3+
from __future__ import division
4+
5+
from .base import DataTypeBase
6+
7+
8+
class Conductance(DataTypeBase):
9+
"""Conductance
10+
"""
11+
_units = ('W/K', 'Btu/h-F')
12+
_si_units = ('W/K')
13+
_ip_units = ('Btu/h-F')
14+
_min = 0
15+
_abbreviation = 'G'
16+
17+
def _W_K_to_Btu_hF(self, value):
18+
return value / 0.5271751322
19+
20+
def _Btu_hF_to_W_K(self, value):
21+
return value * 0.5271751322
22+
23+
def to_unit(self, values, unit, from_unit):
24+
"""Return values converted to the unit given the input from_unit."""
25+
return self._to_unit_base('W/K', values, unit, from_unit)
26+
27+
def to_ip(self, values, from_unit):
28+
"""Return values in IP and the units to which the values have been converted."""
29+
if from_unit == 'Btu/h-F':
30+
return values, from_unit
31+
else:
32+
return self.to_unit(values, 'Btu/h-F', from_unit), 'Btu/h-F'
33+
34+
def to_si(self, values, from_unit):
35+
"""Return values in SI and the units to which the values have been converted."""
36+
if from_unit == 'W/K':
37+
return values, from_unit
38+
else:
39+
return self.to_unit(values, 'W/K', from_unit), 'W/K'

ladybug/datatype/conductivity.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# coding=utf-8
2+
"""Conductivity data type."""
3+
from __future__ import division
4+
5+
from .base import DataTypeBase
6+
7+
8+
class Conductivity(DataTypeBase):
9+
"""Conductivity
10+
"""
11+
_units = ('W/m-K', 'Btu/h-ft-F', 'cal/s-cm-C')
12+
_si_units = ('W/m-K',)
13+
_ip_units = ('Btu/h-ft-F',)
14+
_min = 0
15+
_abbreviation = 'k'
16+
17+
def _W_mK_to_Btu_hftF(self, value):
18+
return value / 1.7295772056
19+
20+
def _Btu_hftF_to_W_mK(self, value):
21+
return value * 1.7295772056
22+
23+
def _W_mK_to_cal_scmC(self, value):
24+
return value / 418.4
25+
26+
def _cal_scmC_to_W_mK(self, value):
27+
return value * 418.4
28+
29+
def to_unit(self, values, unit, from_unit):
30+
"""Return values converted to the unit given the input from_unit."""
31+
return self._to_unit_base('W/m-K', values, unit, from_unit)
32+
33+
def to_ip(self, values, from_unit):
34+
"""Return values in IP and the units to which the values have been converted."""
35+
if from_unit == 'Btu/h-ft-F':
36+
return values, from_unit
37+
else:
38+
return self.to_unit(values, 'Btu/h-ft-F', from_unit), 'Btu/h-ft-F'
39+
40+
def to_si(self, values, from_unit):
41+
"""Return values in SI and the units to which the values have been converted."""
42+
if from_unit == 'W/m-K':
43+
return values, from_unit
44+
else:
45+
return self.to_unit(values, 'W/m-K', from_unit), 'W/m-K'

ladybug/datatype/density.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# coding=utf-8
2+
"""Density data type."""
3+
from __future__ import division
4+
5+
from .base import DataTypeBase
6+
7+
8+
class Density(DataTypeBase):
9+
"""Density
10+
"""
11+
_units = ('kg/m3', 'lb/ft3', 'g/cm3', 'oz/in3')
12+
_si_units = ('kg/m3', 'g/cm3')
13+
_ip_units = ('lb/ft3', 'oz/in3')
14+
_min = 0
15+
_abbreviation = 'rho'
16+
17+
def _kg_m3_to_lb_ft3(self, value):
18+
return value * 0.062428
19+
20+
def _kg_m3_to_g_cm3(self, value):
21+
return value * 0.001
22+
23+
def _kg_m3_to_oz_in3(self, value):
24+
return value * 0.000578037
25+
26+
def _lb_ft3_to_kg_m3(self, value):
27+
return value / 0.062428
28+
29+
def _g_cm3_to_kg_m3(self, value):
30+
return value / 0.001
31+
32+
def _oz_in3_to_kg_m3(self, value):
33+
return value / 0.000578037
34+
35+
def to_unit(self, values, unit, from_unit):
36+
"""Return values converted to the unit given the input from_unit."""
37+
return self._to_unit_base('kg/m3', values, unit, from_unit)
38+
39+
def to_ip(self, values, from_unit):
40+
"""Return values in IP and the units to which the values have been converted."""
41+
if from_unit in self.ip_units:
42+
return values, from_unit
43+
elif from_unit == 'g/cm3':
44+
return self.to_unit(values, 'oz/in3', from_unit), 'oz/in3'
45+
else:
46+
return self.to_unit(values, 'lb/ft3', from_unit), 'lb/ft3'
47+
48+
def to_si(self, values, from_unit):
49+
"""Return values in SI and the units to which the values have been converted."""
50+
if from_unit in self.si_units:
51+
return values, from_unit
52+
elif from_unit == 'oz/in3':
53+
return self.to_unit(values, 'g/cm3', from_unit), 'g/cm3'
54+
else:
55+
return self.to_unit(values, 'kg/m3', from_unit), 'kg/m3'

ladybug/datatype/illuminance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Illuminance(DataTypeBase):
99
"""Illuminance
1010
"""
1111
_units = ('lux', 'fc')
12-
_si_units = ('lux')
13-
_ip_units = ('fc')
12+
_si_units = ('lux',)
13+
_ip_units = ('fc',)
1414
_min = 0
1515
_abbreviation = 'Ev'
1616
_point_in_time = False

ladybug/datatype/luminance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Luminance(DataTypeBase):
99
"""Luminance
1010
"""
1111
_units = ('cd/m2', 'cd/ft2')
12-
_si_units = ('cd/m2')
13-
_ip_units = ('cd/ft2')
12+
_si_units = ('cd/m2',)
13+
_ip_units = ('cd/ft2',)
1414
_min = 0
1515
_abbreviation = 'Lv'
1616
_point_in_time = False

ladybug/datatype/resistance.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding=utf-8
2+
"""Resistance data type."""
3+
from __future__ import division
4+
5+
from .base import DataTypeBase
6+
7+
8+
class Resistance(DataTypeBase):
9+
"""Resistance
10+
"""
11+
_units = ('K/W', 'F-h/Btu')
12+
_si_units = ('K/W',)
13+
_ip_units = ('F-h/Btu',)
14+
_min = 0
15+
_abbreviation = 'R'
16+
17+
def _K_W_to_Fh_Btu(self, value):
18+
return value * 0.5271751322
19+
20+
def _Fh_Btu_to_K_W(self, value):
21+
return value / 0.5271751322
22+
23+
def to_unit(self, values, unit, from_unit):
24+
"""Return values converted to the unit given the input from_unit."""
25+
return self._to_unit_base('K/W', values, unit, from_unit)
26+
27+
def to_ip(self, values, from_unit):
28+
"""Return values in IP and the units to which the values have been converted."""
29+
if from_unit in self.ip_units:
30+
return values, from_unit
31+
else:
32+
return self.to_unit(values, 'F-h/Btu', from_unit), 'F-h/Btu'
33+
34+
def to_si(self, values, from_unit):
35+
"""Return values in SI and the units to which the values have been converted."""
36+
if from_unit in self.si_units:
37+
return values, from_unit
38+
else:
39+
return self.to_unit(values, 'K/W', from_unit), 'K/W'

ladybug/datatype/resistivity.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding=utf-8
2+
"""Resistivity data type."""
3+
from __future__ import division
4+
5+
from .base import DataTypeBase
6+
7+
8+
class Resistivity(DataTypeBase):
9+
"""Resistivity
10+
"""
11+
_units = ('K-m/W', 'F-ft-h/Btu')
12+
_si_units = ('K-m/W',)
13+
_ip_units = ('F-ft-h/Btu',)
14+
_min = 0
15+
_abbreviation = 'rho'
16+
17+
def _Km_W_to_Ffth_Btu(self, value):
18+
return value * 1.7295772056
19+
20+
def _Ffth_Btu_to_Km_W(self, value):
21+
return value / 1.7295772056
22+
23+
def to_unit(self, values, unit, from_unit):
24+
"""Return values converted to the unit given the input from_unit."""
25+
return self._to_unit_base('K-m/W', values, unit, from_unit)
26+
27+
def to_ip(self, values, from_unit):
28+
"""Return values in IP and the units to which the values have been converted."""
29+
if from_unit in self.ip_units:
30+
return values, from_unit
31+
else:
32+
return self.to_unit(values, 'F-ft-h/Btu', from_unit), 'F-ft-h/Btu'
33+
34+
def to_si(self, values, from_unit):
35+
"""Return values in SI and the units to which the values have been converted."""
36+
if from_unit in self.si_units:
37+
return values, from_unit
38+
else:
39+
return self.to_unit(values, 'K-m/W', from_unit), 'K-m/W'

ladybug/datatype/rvalue.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,53 @@
88
class RValue(DataTypeBase):
99
"""R Value
1010
"""
11-
_units = ('m2-K/W', 'h-ft2-F/Btu', 'clo')
12-
_si_units = ('m2-K/W', 'clo')
13-
_ip_units = ('h-ft2-F/Btu', 'clo')
11+
_units = ('K-m2/W', 'F-ft2-h/Btu', 'clo', 'm2-K/W', 'h-ft2-F/Btu')
12+
_si_units = ('K-m2/W', 'm2-K/W', 'clo')
13+
_ip_units = ('F-ft2-h/Btu', 'h-ft2-F/Btu', 'clo')
1414
_min = 0
1515
_abbreviation = 'Rval'
1616

17-
def _m2K_W_to_hft2F_Btu(self, value):
17+
def _Km2_W_to_Fft2h_Btu(self, value):
1818
return value * 5.678263337
1919

20-
def _m2K_W_to_clo(self, value):
20+
def _Km2_W_to_clo(self, value):
2121
return value / 0.155
2222

23-
def _hft2F_Btu_to_m2K_W(self, value):
23+
def _Km2_W_to_m2K_W(self, value):
24+
return value
25+
26+
def _Km2_W_to_hft2F_Btu(self, value):
27+
return value * 5.678263337
28+
29+
def _Fft2h_Btu_to_Km2_W(self, value):
2430
return value / 5.678263337
2531

26-
def _clo_to_m2K_W(self, value):
32+
def _clo_to_Km2_W(self, value):
2733
return value * 0.155
2834

35+
def _m2K_W_to_Km2_W(self, value):
36+
return value
37+
38+
def _hft2F_Btu_to_Km2_W(self, value):
39+
return value / 5.678263337
40+
2941
def to_unit(self, values, unit, from_unit):
3042
"""Return values converted to the unit given the input from_unit."""
31-
return self._to_unit_base('m2-K/W', values, unit, from_unit)
43+
return self._to_unit_base('K-m2/W', values, unit, from_unit)
3244

3345
def to_ip(self, values, from_unit):
3446
"""Return values in IP and the units to which the values have been converted."""
3547
if from_unit in self.ip_units:
3648
return values, from_unit
3749
else:
38-
return self.to_unit(values, 'h-ft2-F/Btu', from_unit), 'h-ft2-F/Btu'
50+
return self.to_unit(values, 'F-ft2-h/Btu', from_unit), 'F-ft2-h/Btu'
3951

4052
def to_si(self, values, from_unit):
4153
"""Return values in SI and the units to which the values have been converted."""
4254
if from_unit in self.si_units:
4355
return values, from_unit
4456
else:
45-
return self.to_unit(values, 'm2-K/W', from_unit), 'm2-K/W'
57+
return self.to_unit(values, 'K-m2/W', from_unit), 'K-m2/W'
4658

4759

4860
class ClothingInsulation(RValue):
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# coding=utf-8
2+
"""Specific Heat Capacity data type."""
3+
from __future__ import division
4+
5+
from .base import DataTypeBase
6+
7+
8+
class SpecificHeatCapacity(DataTypeBase):
9+
"""Specific Heat Capacity"""
10+
_units = ('J/kg-K', 'Btu/lb-F', 'kWh/kg-K', 'kBtu/lb-F', 'kJ/kg-K')
11+
_si_units = ('J/kg-K', 'kWh/kg-K', 'kJ/kg-K')
12+
_ip_units = ('Btu/lb-F', 'kBtu/lb-F')
13+
_min = 0
14+
_abbreviation = 'c'
15+
16+
def _J_kgK_to_Btu_lbF(self, value):
17+
return value / 4186.8
18+
19+
def _J_kgK_to_kWh_kgK(self, value):
20+
return value / 3600000.
21+
22+
def _J_kgK_to_kBtu_lbF(self, value):
23+
return value / 4186800.
24+
25+
def _J_kgK_to_kJ_kgK(self, value):
26+
return value / 1000.
27+
28+
def _Btu_lbF_to_J_kgK(self, value):
29+
return value * 4186.8
30+
31+
def _kWh_kgK_to_J_kgK(self, value):
32+
return value * 3600000.
33+
34+
def _kBtu_lbF_to_J_kgK(self, value):
35+
return value * 4186800.
36+
37+
def _kJ_kgK_to_J_kgK(self, value):
38+
return value * 1000.
39+
40+
def to_unit(self, values, unit, from_unit):
41+
"""Return values converted to the unit given the input from_unit."""
42+
return self._to_unit_base('J/kg-K', values, unit, from_unit)
43+
44+
def to_ip(self, values, from_unit):
45+
"""Return values in IP and the units to which the values have been converted."""
46+
if from_unit in self.ip_units:
47+
return values, from_unit
48+
elif from_unit == 'kWh/kg-K':
49+
return self.to_unit(values, 'kBtu/lb-F', from_unit), 'kBtu/lb-F'
50+
else:
51+
return self.to_unit(values, 'Btu/lb-F', from_unit), 'Btu/lb-F'
52+
53+
def to_si(self, values, from_unit):
54+
"""Return values in SI and the units to which the values have been converted."""
55+
if from_unit in self.si_units:
56+
return values, from_unit
57+
elif from_unit == 'kBtu/lb-F':
58+
return self.to_unit(values, 'kWh/kg-K', from_unit), 'kWh/kg-K'
59+
else:
60+
return self.to_unit(values, 'J/kg-K', from_unit), 'J/kg-K'

ladybug/datatype/temperature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Temperature(DataTypeBase):
1010
"""
1111
_units = ('C', 'F', 'K')
1212
_si_units = ('C', 'K')
13-
_ip_units = ('F')
13+
_ip_units = ('F',)
1414
_min = -273.15
1515
_abbreviation = 'T'
1616

0 commit comments

Comments
 (0)