Changeset 450
- Timestamp:
- 08/20/10 18:14:40 (18 months ago)
- Location:
- branches/parameter_set_schema_validation
- Files:
-
- 3 added
- 1 modified
- 1 moved
-
setup.py (modified) (1 diff)
-
src/parameters (added)
-
src/parameters/__init__.py (moved) (moved from branches/parameter_set_schema_validation/src/parameters.py) (9 diffs)
-
src/parameters/validators.py (added)
-
test/test_validators.py (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/parameter_set_schema_validation/setup.py
r400 r450 14 14 'NeuroTools.spike2.sonpy', 15 15 'NeuroTools.datastore', 16 'NeuroTools.parameters', 16 17 'NeuroTools.datastore.django_orm', 17 18 ], -
branches/parameter_set_schema_validation/src/parameters/__init__.py
r439 r450 9 9 10 10 Parameter 11 ParameterRange - for specifying a list of possible values for a given parameter. 12 ParameterSet - for representing/managing hierarchical parameter sets. 13 ParameterTable - a sub-class of ParameterSet that can represent a table of parameters. 14 ParameterSpace - a collection of ParameterSets, representing multiple points in 15 parameter space. 11 ParameterRange - for specifying a list of possible values for a given parameter. 12 ParameterSet - for representing/managing hierarchical parameter sets. 13 ParameterTable - a sub-class of ParameterSet that can represent a table of parameters. 14 ParameterSpace - a collection of ParameterSets, representing multiple points in 15 parameter space. 16 ParameterSchema - a sub-class of ParameterSet, which may also contain 17 18 16 19 17 20 Functions … … 28 31 from NeuroTools import check_dependency 29 32 from NeuroTools.random import ParameterDist, GammaDist, UniformDist, NormalDist 30 33 #from NeuroTools.parameters.validators import schema_checkers_namespace 34 #from NeuroTools.parameters.validators import Subclass 31 35 32 36 def isiterable(x): … … 159 163 160 164 @staticmethod 161 def read_from_str(s ):165 def read_from_str(s,update_namespace=None): 162 166 """ 163 167 ParameterSet definition s should be a Python dict definition … … 185 189 UniformDist=UniformDist, 186 190 NormalDist=NormalDist, 187 pi=numpy.pi)) 191 pi=numpy.pi)) 192 if update_namespace: 193 global_dict.update(update_namespace) 194 188 195 try: 189 196 D = eval(s, global_dict) … … 197 204 raise Exception("'%s' is not allowed as a parameter name." % k) 198 205 199 def __init__(self, initialiser, label=None ):200 206 def __init__(self, initialiser, label=None, update_namespace=None): 207 201 208 def walk(d, label): 202 209 # Iterate through the dictionary `d`, replacing `dict`s by … … 228 235 f.close() 229 236 230 initialiser = ParameterSet.read_from_str(pstr )237 initialiser = ParameterSet.read_from_str(pstr,update_namespace) 231 238 232 239 # By this stage, `initialiser` should be a dict. Iterate through it, … … 243 250 self[k] = v 244 251 else: 245 raise TypeError("`initialiser` must be a `dict`, a `ParameterSet` object or a valid URL")246 252 raise TypeError("`initialiser` must be a `dict`, a `ParameterSet` object, a string, or a valid URL") 253 247 254 # Set the label 248 255 if hasattr(initialiser, 'label'): … … 256 263 self.names = self.keys 257 264 self.parameters = self.items 265 258 266 259 267 def flat(self): … … 298 306 else: 299 307 # nested set 300 dict.__getitem__(self,split[0])[split[1]]=value 308 try: 309 dict.__getitem__(self,split[0])[split[1]]=value 310 except KeyError: 311 # setting nested name without parent existing 312 # create parent 313 dict.__setitem__(self,split[0],{}) 314 # and try again 315 dict.__getitem__(self,split[0])[split[1]]=value 301 316 302 317 # should __len__() be the usual dict length, or the flattened length? Probably the former for consistency with dicts
