366 |
- a ParameterSet object |
- a ParameterSet object |
367 |
- a Simulation object |
- a Simulation object |
368 |
- a Model object |
- a Model object |
369 |
- any other object (not considered by writeESySXML and writeXML) |
- a numarray object |
370 |
|
- a list of booleans |
371 |
|
- any other object (not considered by writeESySXML and writeXML) |
372 |
|
|
373 |
Example how to create an ESySParameters object:: |
Example how to create an ESySParameters object:: |
374 |
|
|
480 |
|
|
481 |
val = document.createElement('Value') |
val = document.createElement('Value') |
482 |
|
|
483 |
if isinstance(value,ParameterSet): |
if isinstance(value,(ParameterSet,Link)): |
|
value.toDom(document, val) |
|
|
param.appendChild(val) |
|
|
elif isinstance(value, Link): |
|
484 |
value.toDom(document, val) |
value.toDom(document, val) |
485 |
param.appendChild(val) |
param.appendChild(val) |
486 |
elif isinstance(value, numarray.NumArray): |
elif isinstance(value, numarray.NumArray): |
493 |
shape = str(shape) |
shape = str(shape) |
494 |
|
|
495 |
arraytype = value.type() |
arraytype = value.type() |
496 |
val.appendChild(dataNode(document, 'ArrayType', str(arraytype))) |
numarrayElement = document.createElement('NumArray') |
497 |
val.appendChild(dataNode(document, 'Shape', shape)) |
numarrayElement.appendChild(dataNode(document, 'ArrayType', str(arraytype))) |
498 |
val.appendChild(dataNode(document, 'Data', ' '.join( |
numarrayElement.appendChild(dataNode(document, 'Shape', shape)) |
499 |
|
numarrayElement.appendChild(dataNode(document, 'Data', ' '.join( |
500 |
[str(x) for x in numarray.reshape(value, size)]))) |
[str(x) for x in numarray.reshape(value, size)]))) |
501 |
|
val.appendChild(numarrayElement) |
502 |
param.appendChild(val) |
param.appendChild(val) |
503 |
elif isinstance(value,StringType): |
elif isinstance (value, list): |
504 |
param.appendChild(dataNode(document, 'Value', value)) |
param.appendChild(dataNode(document, 'Value', ' '.join( |
505 |
|
[str(x) for x in value]) |
506 |
|
)) |
507 |
else: |
else: |
508 |
param.appendChild(dataNode(document, 'Value', str(value))) |
param.appendChild(dataNode(document, 'Value', str(value))) |
509 |
|
|
535 |
return int(doc.nodeValue.strip()) |
return int(doc.nodeValue.strip()) |
536 |
|
|
537 |
def _boolfromValue(doc): |
def _boolfromValue(doc): |
538 |
return bool(doc.nodeValue.strip()) |
return _boolfromstring(doc.nodeValue.strip()) |
539 |
|
|
540 |
def _nonefromValue(doc): |
def _nonefromValue(doc): |
541 |
return None |
return None |
542 |
|
|
543 |
def _numarrayfromValue(doc): |
def _numarrayfromValue(doc): |
544 |
for node in doc: |
for node in _children(doc): |
545 |
if node.tagName == 'ArrayType': |
if node.tagName == 'ArrayType': |
546 |
arraytype = node.firstChild.nodeValue.strip() |
arraytype = node.firstChild.nodeValue.strip() |
547 |
if node.tagName == 'Shape': |
if node.tagName == 'Shape': |
552 |
data = [float(x) for x in data.split()] |
data = [float(x) for x in data.split()] |
553 |
return numarray.reshape(numarray.array(data, type=getattr(numarray, arraytype)), |
return numarray.reshape(numarray.array(data, type=getattr(numarray, arraytype)), |
554 |
shape) |
shape) |
555 |
|
|
556 |
|
def _listfromValue(doc): |
557 |
|
return [_boolfromstring(x) for x in doc.nodeValue.split()] |
558 |
|
|
559 |
|
|
560 |
|
def _boolfromstring(s): |
561 |
|
if s == 'True': |
562 |
|
return True |
563 |
|
else: |
564 |
|
return False |
565 |
# Mapping from text types in the xml to methods used to process trees of that type |
# Mapping from text types in the xml to methods used to process trees of that type |
566 |
ptypemap = {"Simulation": Simulation.fromDom, |
ptypemap = {"Simulation": Simulation.fromDom, |
567 |
"Model":Model.fromDom, |
"Model":Model.fromDom, |
571 |
"int":_intfromValue, |
"int":_intfromValue, |
572 |
"str":_stringfromValue, |
"str":_stringfromValue, |
573 |
"bool":_boolfromValue, |
"bool":_boolfromValue, |
574 |
|
"list":_listfromValue, |
575 |
|
"NumArray":_numarrayfromValue, |
576 |
"NoneType":_nonefromValue, |
"NoneType":_nonefromValue, |
577 |
} |
} |
578 |
|
|
590 |
|
|
591 |
if childnode.tagName == "Value": |
if childnode.tagName == "Value": |
592 |
nodes = _children(childnode) |
nodes = _children(childnode) |
593 |
if ptype == 'NumArray': |
# if ptype == 'NumArray': |
594 |
pvalue = _numarrayfromValue(nodes) |
# pvalue = _numarrayfromValue(nodes) |
595 |
else: |
# else: |
596 |
pvalue = ptypemap[ptype](nodes[0]) |
pvalue = ptypemap[ptype](nodes[0]) |
597 |
|
|
598 |
parameters[pname] = pvalue |
parameters[pname] = pvalue |
599 |
|
|