Skip to content

Commit a49e808

Browse files
author
Darren Dale
committed
units now register themselves
all units *appear* to be working constants also *appear* to be working
1 parent 147726b commit a49e808

File tree

18 files changed

+284
-287
lines changed

18 files changed

+284
-287
lines changed

quantities/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@
5050
__version__ = '0.1(bzr)'
5151

5252

53-
#from quantity import Quantity, ProtectedUnitsError
5453
from quantity import Quantity
5554

56-
#from parser import unit_registry
57-
#
58-
#import units
59-
#from units import *
60-
#
61-
#import constants
62-
#from constants import *
55+
from parser import unit_registry
56+
57+
import units
58+
from units import *
59+
60+
import constants
61+
from constants import *

quantities/constants/codata.py

Lines changed: 169 additions & 169 deletions
Large diffs are not rendered by default.

quantities/constants/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def _cd(name):
1010
entry = _pc[name]
11-
q = Quantity(entry['value'], entry['units'])
11+
q = Quantity(entry['value'], 'd', entry['units'])
1212
q.precision = entry['precision']
1313
return q
1414

quantities/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def __getitem__(self, label):
7474
try:
7575
_unit = self.__registry[label.lower()]
7676
except:
77-
_unit = self.__registry['compound'](label)
77+
_unit = self.__registry['UnitQuantity'](label)
7878

7979
# this check should be more robust:
80-
if hasattr(_unit, 'modify_units'):
81-
return copy.deepcopy(_unit)
80+
if hasattr(_unit, '_dimensionality'):
81+
return _unit
8282
else:
8383
raise "unrecognized unit: %s"%_unit
8484

quantities/quantity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from quantities.dimensionality import BaseDimensionality, \
99
MutableDimensionality, ImmutableDimensionality
10+
from quantities.parser import unit_registry
1011

1112

1213
class HasDimensionality(numpy.ndarray):
@@ -109,6 +110,8 @@ class Quantity(HasDimensionality):
109110
__array_priority__ = 21
110111

111112
def __init__(self, magnitude, dtype='d', units={}, mutable=True):
113+
if isinstance(units, str):
114+
units = unit_registry[units].dimensionality
112115
if isinstance(units, HasDimensionality):
113116
units = units.dimensionality
114117
assert isinstance(units, (BaseDimensionality, dict))

quantities/units/__init__.py

Lines changed: 67 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,70 @@
11
"""
22
"""
33

4-
#from quantities.parser import unit_registry
5-
#
6-
#import acceleration
7-
#unit_registry.update(acceleration)
8-
#from acceleration import *
9-
#
10-
#import angle
11-
#unit_registry.update(angle)
12-
#from angle import *
13-
#
14-
#import area
15-
#unit_registry.update(area)
16-
#from area import *
17-
#
18-
#import compound
19-
#unit_registry.update(compound)
20-
#from compound import *
21-
#
22-
#import dimensionless
23-
#unit_registry.update(dimensionless)
24-
#from dimensionless import *
25-
#
26-
#import electromagnetism
27-
#unit_registry.update(electromagnetism)
28-
#from electromagnetism import *
29-
#
30-
#import energy
31-
#unit_registry.update(energy)
32-
#from energy import *
33-
#
34-
#import force
35-
#unit_registry.update(force)
36-
#from force import *
37-
#
38-
#import frequency
39-
#unit_registry.update(frequency)
40-
#from frequency import *
41-
#
42-
#import heat
43-
#unit_registry.update(heat)
44-
#from heat import *
45-
#
46-
#import information
47-
#unit_registry.update(information)
48-
#from information import *
49-
#
50-
#import length
51-
#unit_registry.update(length)
52-
#from length import *
53-
#
54-
#import mass
55-
#unit_registry.update(mass)
56-
#from mass import *
57-
#
58-
#import power
59-
#unit_registry.update(power)
60-
#from power import *
61-
#
62-
#import pressure
63-
#unit_registry.update(pressure)
64-
#from pressure import *
65-
#
66-
#import radiation
67-
#unit_registry.update(radiation)
68-
#from radiation import *
69-
#
70-
#import substance
71-
#unit_registry.update(substance)
72-
#from substance import *
73-
#
74-
#import temperature
75-
#unit_registry.update(temperature)
76-
#from temperature import *
77-
#
78-
#import time
79-
#unit_registry.update(time)
80-
#from time import *
81-
#
82-
#import velocity
83-
#unit_registry.update(velocity)
84-
#from velocity import *
85-
#
86-
#import viscosity
87-
#unit_registry.update(viscosity)
88-
#from viscosity import *
89-
#
90-
#import volume
91-
#unit_registry.update(volume)
92-
#from volume import *
4+
from quantities.parser import unit_registry
5+
6+
import acceleration
7+
from acceleration import *
8+
9+
import angle
10+
from angle import *
11+
12+
import area
13+
from area import *
14+
15+
import compound
16+
from compound import *
17+
18+
import dimensionless
19+
from dimensionless import *
20+
21+
import electromagnetism
22+
from electromagnetism import *
23+
24+
import energy
25+
from energy import *
26+
27+
import force
28+
from force import *
29+
30+
import frequency
31+
from frequency import *
32+
33+
import heat
34+
from heat import *
35+
36+
import information
37+
from information import *
38+
39+
import length
40+
from length import *
41+
42+
import mass
43+
from mass import *
44+
45+
import power
46+
from power import *
47+
48+
import pressure
49+
from pressure import *
50+
51+
import radiation
52+
from radiation import *
53+
54+
import substance
55+
from substance import *
56+
57+
import temperature
58+
from temperature import *
59+
60+
import time
61+
from time import *
62+
63+
import velocity
64+
from velocity import *
65+
66+
import viscosity
67+
from viscosity import *
68+
69+
import volume
70+
from volume import *

quantities/units/angle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
degree_west = degrees_west = degree_W= degrees_W = UnitAngle('degrees_W')
1919
degree_true = degrees_true = degree_T = degrees_T = UnitAngle('degrees_T')
2020

21-
sr = steradian = steradians = UnitQuantity('steradian')
21+
sr = steradian = steradians = UnitQuantity('sr')
2222

2323
del UnitQuantity

quantities/units/dimensionless.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
"""
33

4-
from unitquantities import UnitQuantity
4+
from quantities.units.unitquantity import Dimensionless
55

6-
dimensionless = UnitQuantity('')
6+
dimensionless = Dimensionless('dimensionless')

quantities/units/electromagnetism.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
"""
33

4-
from quantities.units.unitquantities import UnitCurrent, \
4+
from quantities.units.unitquantity import UnitCurrent, \
55
UnitLuminousIntensity, UnitQuantity
66
from quantities.units.time import s
77
from quantities.units.length import m

quantities/units/heat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
from quantities.units.power import W
88

99

10-
clo = clos = compound('clo', 1.55e-1*K*m**2/W)
10+
clo = clos = UnitQuantity('clo', 1.55e-1*K*m**2/W)
1111

1212
del UnitQuantity, K, m, W

0 commit comments

Comments
 (0)