| @@ 573-592 (lines=20) @@ | ||
| 570 | gp = entry.require_group('data') |
|
| 571 | self.__output_data_type(gp, data.data, 'data') |
|
| 572 | ||
| 573 | def __output_data(self, entry, data, name): |
|
| 574 | if isinstance(data, dict): |
|
| 575 | entry = entry.require_group(name) |
|
| 576 | entry.attrs[NX_CLASS] = 'NXcollection' |
|
| 577 | for key, value in data.items(): |
|
| 578 | self.__output_data(entry, value, key) |
|
| 579 | else: |
|
| 580 | try: |
|
| 581 | self.__create_dataset(entry, name, data) |
|
| 582 | except Exception: |
|
| 583 | try: |
|
| 584 | import json |
|
| 585 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 586 | self.__create_dataset(entry, name, data) |
|
| 587 | except Exception: |
|
| 588 | try: |
|
| 589 | data = cu._savu_encoder(data) |
|
| 590 | self.__create_dataset(entry, name, data) |
|
| 591 | except: |
|
| 592 | raise Exception('Unable to output %s to file.' % name) |
|
| 593 | ||
| 594 | def __create_dataset(self, entry, name, data): |
|
| 595 | if name not in list(entry.keys()): |
|
| @@ 319-337 (lines=19) @@ | ||
| 316 | nx_data.attrs['NX_class'] = 'NXdata' |
|
| 317 | self.__output_data(nx_data, value, key) |
|
| 318 | ||
| 319 | def __output_data(self, entry, data, name): |
|
| 320 | if isinstance(data, dict): |
|
| 321 | entry = entry.require_group(name) |
|
| 322 | entry.attrs['NX_class'] = 'NXcollection' |
|
| 323 | for key, value in data.items(): |
|
| 324 | self.__output_data(entry, value, key) |
|
| 325 | else: |
|
| 326 | try: |
|
| 327 | self.__create_dataset(entry, name, data) |
|
| 328 | except Exception: |
|
| 329 | try: |
|
| 330 | import json |
|
| 331 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 332 | self.__create_dataset(entry, name, data) |
|
| 333 | except Exception: |
|
| 334 | try: |
|
| 335 | self.__create_dataset(entry, name, data) |
|
| 336 | except: |
|
| 337 | raise Exception('Unable to output %s to file.' % name) |
|
| 338 | ||
| 339 | def __create_dataset(self, entry, name, data): |
|
| 340 | if name not in list(entry.keys()): |
|