gafusion / omas

Ordered Multidimensional Array Structure
http://gafusion.github.io/omas
MIT License
30 stars 15 forks source link

Fancy slicing doesn't work with uncertain data #136

Closed eldond closed 3 years ago

eldond commented 3 years ago

pulse_schedule.position_control.x_point[:].z.reference.data is listed as having type FLT_1D (uncertain) on https://gafusion.github.io/omas/schema/schema_pulse%20schedule.html . So, it should be valid to assign

ods = ODS()
ods['pulse_schedule']['position_control']['x_point'][0]['z']['reference']['data'] = [ufloat(1.019, 0.02), ufloat(1.019, 0.02)]

And indeed this has been accepted and will print:

print(ods['pulse_schedule.position_control.x_point.0.z.reference.data'])
[1.019+/-0.02 1.019+/-0.02]

as expected. However, if the values were not uncertain, then the 0 should be replaceable with :, as in

print(ods['pulse_schedule.position_control.x_point.:.z.reference.data'])

however this results in ValueError: Not an IMAS data type O:

ValueError: Not an IMAS data type O ``` Error in "OMFIT command box #18" at line 3 print(ods['pulse_schedule.position_control.x_point.:.z.reference.data']) ValueError: Not an IMAS data type O Press to see full error report... Traceback (most recent call last): File "/home/eldond/OMFIT-source/omfit/classes/OMFITx.py", line 4068, in manage_user_errors tmp=command(**kw) File "/home/eldond/OMFIT-source/omfit/utils_tk.py", line 1060, in GlobLoc_tk return py.run(_relLoc=self.namespace, _OMFITscriptsDict=False, _OMFITconsoleDict=True, noGUI=None) File "/home/eldond/OMFIT-source/omfit/classes/omfit_python.py", line 1082, in run result = self.__run__(**kw) File "/home/eldond/OMFIT-source/omfit/classes/omfit_python.py", line 930, in __run__ tmp = execGlobLoc( File "/home/eldond/OMFIT-source/omfit/classes/omfit_python.py", line 129, in f_locked return f(*args, **kw) File "/home/eldond/OMFIT-source/omfit/classes/omfit_python.py", line 362, in execGlobLoc exec(compile(execString, filename, "exec"), GlobLoc) File "/home/eldond/tmp/eldond/eldond/OMFIT/OMFIT_2020-10-28_13_18_12_659490/project/OMFIT command box #18", line 3, in print(ods['pulse_schedule.position_control.x_point.:.z.reference.data']) File "/home/eldond/omas/omas/omas_core.py", line 1126, in __getitem__ return value.__getitem__(key[1:], cocos_and_coords) File "/home/eldond/omas/omas/omas_core.py", line 1126, in __getitem__ return value.__getitem__(key[1:], cocos_and_coords) File "/home/eldond/omas/omas/omas_core.py", line 1126, in __getitem__ return value.__getitem__(key[1:], cocos_and_coords) File "/home/eldond/omas/omas/omas_core.py", line 1094, in __getitem__ raise ValueError('Not an IMAS data type %s' % dtype.char) ValueError: Not an IMAS data type O ```

And I confirm that stripping the uncertainties returns ODS to expected behavior:

ods['pulse_schedule']['position_control']['x_point'][0]['z']['reference']['data'] = [1.019, 1.019]
print(ods['pulse_schedule.position_control.x_point.:.z.reference.data'])
[[1.019 1.019]]

I need the uncertainties to carry tolerances mentioned in https://github.com/gafusion/OMFIT-source/issues/4811.