import copy as _copy
-import numpy as _numpy
-
from . import LOG as _LOG
class Setting (object):
"A named setting with arbitrary text values."
- def __init__(self, name, help='', default=None):
+ def __init__(self, name, help='', default=None):
self.name = name
self._help = help
self.default = default
return ret.strip()
def convert_from_text(self, value):
- if (isinstance(value, _numpy.ndarray) and
- value.dtype.type == _numpy.string_):
- value = str(value)
return dict(self.choices)[value]
def convert_to_text(self, value):
import types as _types
import h5py as _h5py
+import numpy as _numpy
from .. import LOG as _LOG
from .. import config as _config
for s in config.settings:
if s.name not in group.keys():
continue
- elif isinstance(s, (_config.BooleanSetting,
- _config.NumericSetting,
- _config.FloatListSetting)):
- v = group[s.name][...]
- if isinstance(v, _types.StringTypes):
- # convert back from None, etc.
- v = s.convert_from_text(v)
- elif isinstance(s, _config.FloatListSetting):
- v = list(v) # convert from numpy array
- config[s.name] = v
- elif isinstance(s, _config.ConfigListSetting):
+ if isinstance(s, _config.ConfigListSetting):
try:
cwg = h5_create_group(group, s.name)
except ValueError:
config[s.name] = s.config_class()
self._load(config=config[s.name], group=cwg)
else:
- config[s.name] = s.convert_from_text(group[s.name][...])
+ v = group[s.name][...]
+ if isinstance(s, _config.BooleanSetting):
+ if isinstance(v, _numpy.ndarray):
+ v = bool(v) # array(True, dtype=bool) -> True
+ elif (isinstance(v, _numpy.ndarray) and
+ v.dtype.type == _numpy.string_):
+ v = str(v) # array('abc', dtype='|S3') -> 'abc'
+ elif isinstance(s, _config.FloatListSetting):
+ v = list(v) # convert from numpy array
+ if isinstance(v, _types.StringTypes):
+ # convert back from None, etc.
+ v = s.convert_from_text(v)
+ config[s.name] = v
finally:
if f:
f.close()