-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathunits_test.py
More file actions
132 lines (122 loc) · 6.39 KB
/
Copy pathunits_test.py
File metadata and controls
132 lines (122 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import unittest
from sympy import sympify
from nineml import units as un
from nineml.serialization.xml import XMLUnserializer
all_dims = [getattr(un, d) for d in dir(un)
if isinstance(getattr(un, d), un.Dimension)]
class TestUnitsDimensions(unittest.TestCase):
def test_xml_540degree_roundtrip(self):
document1 = XMLUnserializer(root=units_xml_str).unserialize()
xml = document1.serialize()
document2 = XMLUnserializer(xml).unserialize()
self.assertEquals(document1, document2)
def test_sympy(self):
for dim in (un.temperature, un.capacitance, un.resistance, un.charge,
un.voltage, un.specificCapacitance):
sympy_dim = sympify(dim)
new_dim = un.Dimension.from_sympy(sympy_dim)
self.assertEquals(dim, new_dim,
"Sympy roundtrip failed for {}".format(dim))
def test_accessors(self):
for i, (abbrev, name) in enumerate((
('m', 'mass'), ('l', 'length'), ('t', 'time'), ('i', 'current'),
('n', 'amount'), ('k', 'temperature'),
('j', 'luminous_intensity'))):
for dim in all_dims:
self.assertEqual(getattr(dim, abbrev), dim._dims[i])
self.assertEqual(getattr(dim, name), dim._dims[i])
units_xml_str = """<?xml version="1.0" encoding="UTF-8"?>
<NineML xmlns="http://nineml.net/9ML/2.0">
<Annotations>
<Text>
As NineML uses the format for units/dimensions that was developed for LEMS
the units/dimension defined on this page have been copied from the example
LEMS units/dimension that can be found here
https://github.com/NeuroML/NeuroML2/blob/master/NeuroML2CoreTypes/NeuroMLCoreDimensions.xml
</Text>
</Annotations>
<Dimension name="time" t="1"/>
<Dimension name="per_time" t="-1"/>
<Dimension name="voltage" m="1" l="2" t="-3" i="-1"/>
<Dimension name="per_voltage" m="-1" l="-2" t="3" i="1"/>
<Dimension name="conductance" m="-1" l="-2" t="3" i="2"/>
<Dimension name="conductanceDensity" m="-1" l="-4" t="3" i="2"/>
<Dimension name="capacitance" m="-1" l="-2" t="4" i="2"/>
<Dimension name="specificCapacitance" m="-1" l="-4" t="4" i="2"/>
<Dimension name="resistance" m="1" l="2" t="-3" i="-2"/>
<Dimension name="resistivity" m="2" l="2" t="-3" i="-2"/>
<Dimension name="charge" i="1" t="1"/>
<Dimension name="charge_per_mole" i="1" t="1" n="-1"/>
<Dimension name="current" i="1"/>
<Dimension name="currentDensity" i="1" l="-2"/>
<Dimension name="length" l="1"/>
<Dimension name="area" l="2"/>
<Dimension name="volume" l="3"/>
<Dimension name="concentration" l="-3" n="1"/>
<Dimension name="substance" n="1"/>
<Dimension name="permeability" l="1" t="-1"/>
<Dimension name="temperature" k="1"/>
<Dimension name="idealGasConstantDims" m="1" l="2" t="-2" k="-1" n="-1"/>
<Dimension name="rho_factor" l="-1" n="1" i="-1" t="-1"/>
<Unit symbol="s" dimension="time" power="0"/>
<Unit symbol="per_s" dimension="per_time" power="0"/>
<Unit symbol="Hz" dimension="per_time" power="0"/>
<Unit symbol="ms" dimension="time" power="-3"/>
<Unit symbol="per_ms" dimension="per_time" power="3"/>
<Unit symbol="m" dimension="length" power="0"/>
<Unit symbol="cm" dimension="length" power="-2"/>
<Unit symbol="um" dimension="length" power="-6"/>
<Unit symbol="m2" dimension="area" power="0"/>
<Unit symbol="cm2" dimension="area" power="-4"/>
<Unit symbol="um2" dimension="area" power="-12"/>
<Unit symbol="m3" dimension="volume" power="0"/>
<Unit symbol="cm3" dimension="volume" power="-6"/>
<Unit symbol="litre" dimension="volume" power="-3"/>
<Unit symbol="um3" dimension="volume" power="-18"/>
<Unit symbol="V" dimension="voltage" power="0"/>
<Unit symbol="mV" dimension="voltage" power="-3"/>
<Unit symbol="per_V" dimension="per_voltage" power="0"/>
<Unit symbol="per_mV" dimension="per_voltage" power="3"/>
<Unit symbol="ohm" dimension="resistance" power="0"/>
<Unit symbol="kohm" dimension="resistance" power="3"/>
<Unit symbol="Mohm" dimension="resistance" power="6"/>
<Unit symbol="S" dimension="conductance" power="0"/>
<Unit symbol="mS" dimension="conductance" power="-3"/>
<Unit symbol="uS" dimension="conductance" power="-6"/>
<Unit symbol="nS" dimension="conductance" power="-9"/>
<Unit symbol="pS" dimension="conductance" power="-12"/>
<Unit symbol="S_per_m2" dimension="conductanceDensity" power="0"/>
<Unit symbol="mS_per_cm2" dimension="conductanceDensity" power="1"/>
<Unit symbol="S_per_cm2" dimension="conductanceDensity" power="4"/>
<Unit symbol="F" dimension="capacitance" power="0"/>
<Unit symbol="uF" dimension="capacitance" power="-6"/>
<Unit symbol="nF" dimension="capacitance" power="-9"/>
<Unit symbol="pF" dimension="capacitance" power="-12"/>
<Unit symbol="F_per_m2" dimension="specificCapacitance" power="0"/>
<Unit symbol="uF_per_cm2" dimension="specificCapacitance" power="-2"/>
<Unit symbol="ohm_m" dimension="resistivity" power="0"/>
<Unit symbol="kohm_cm" dimension="resistivity" power="1"/>
<Unit symbol="ohm_cm" dimension="resistivity" power="-2"/>
<Unit symbol="C" dimension="charge" power="0"/>
<Unit symbol="C_per_mol" dimension="charge_per_mole" power="0"/>
<Unit symbol="A" dimension="current" power="0"/>
<Unit symbol="uA" dimension="current" power="-6"/>
<Unit symbol="nA" dimension="current" power="-9"/>
<Unit symbol="pA" dimension="current" power="-12"/>
<Unit symbol="A_per_m2" dimension="currentDensity" power="0"/>
<Unit symbol="uA_per_cm2" dimension="currentDensity" power="-2"/>
<Unit symbol="mA_per_cm2" dimension="currentDensity" power="1"/>
<Unit symbol="mol_per_m3" dimension="concentration" power="0"/>
<Unit symbol="mol_per_cm3" dimension="concentration" power="6"/>
<Unit symbol="M" dimension="concentration" power="3"/>
<Unit symbol="mM" dimension="concentration" power="0"/>
<Unit symbol="mol" dimension="substance" power="0"/>
<Unit symbol="m_per_s" dimension="permeability" power="0"/>
<Unit symbol="cm_per_s" dimension="permeability" power="-2"/>
<Unit symbol="um_per_ms" dimension="permeability" power="-3"/>
<Unit symbol="cm_per_ms" dimension="permeability" power="1"/>
<Unit symbol="degC" dimension="temperature" offset="273.15"/>
<Unit symbol="K" dimension="temperature" power="0"/>
<Unit symbol="J_per_K_per_mol" dimension="idealGasConstantDims" power="0"/>
<Unit symbol="mol_per_m_per_A_per_s" dimension="rho_factor" power="0"/>
</NineML>"""