Skip to content

Commit 3518953

Browse files
committed
Update params with either Units or unit string
1 parent 7ebcedc commit 3518953

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

simtool/params.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
from mendeleev import element
1111
import PIL.Image
12-
from pint import UnitRegistry
12+
from pint import Unit,UnitRegistry
1313
from .encode import JsonEncoder
1414

1515

@@ -40,10 +40,13 @@ def __init__(self, **kwargs):
4040
if hasattr(self, 'units'):
4141
units = kwargs.get('units')
4242
if units:
43-
try:
44-
self['units'] = ureg.parse_units(units)
45-
except:
46-
raise ValueError('Unrecognized units: %s' % (units))
43+
if isinstance(units,Unit):
44+
self['units'] = units
45+
else:
46+
try:
47+
self['units'] = ureg.parse_units(units)
48+
except:
49+
raise ValueError('Unrecognized units: %s' % (units))
4750
if hasattr(self, 'min'):
4851
self['min'] = self._getNumericValueFromQuantity(kwargs.get('min'),checkMinMax=False)
4952
if hasattr(self, 'max'):

0 commit comments

Comments
 (0)