| @@ 620-639 (lines=20) @@ | ||
| 617 | gp = entry.require_group('data') |
|
| 618 | self.__output_data_type(gp, data.data, 'data') |
|
| 619 | ||
| 620 | def __output_data(self, entry, data, name): |
|
| 621 | if isinstance(data, dict): |
|
| 622 | entry = entry.require_group(name) |
|
| 623 | entry.attrs[NX_CLASS] = 'NXcollection' |
|
| 624 | for key, value in data.items(): |
|
| 625 | self.__output_data(entry, value, key) |
|
| 626 | else: |
|
| 627 | try: |
|
| 628 | self.__create_dataset(entry, name, data) |
|
| 629 | except Exception: |
|
| 630 | try: |
|
| 631 | import json |
|
| 632 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 633 | self.__create_dataset(entry, name, data) |
|
| 634 | except Exception: |
|
| 635 | try: |
|
| 636 | data = cu._savu_encoder(data) |
|
| 637 | self.__create_dataset(entry, name, data) |
|
| 638 | except: |
|
| 639 | raise Exception('Unable to output %s to file.' % name) |
|
| 640 | ||
| 641 | def __create_dataset(self, entry, name, data): |
|
| 642 | if name not in list(entry.keys()): |
|
| @@ 372-390 (lines=19) @@ | ||
| 369 | nx_data.attrs['NX_class'] = 'NXdata' |
|
| 370 | self.__output_data(nx_data, value, key) |
|
| 371 | ||
| 372 | def __output_data(self, entry, data, name): |
|
| 373 | if isinstance(data, dict): |
|
| 374 | entry = entry.require_group(name) |
|
| 375 | entry.attrs['NX_class'] = 'NXcollection' |
|
| 376 | for key, value in data.items(): |
|
| 377 | self.__output_data(entry, value, key) |
|
| 378 | else: |
|
| 379 | try: |
|
| 380 | self.__create_dataset(entry, name, data) |
|
| 381 | except Exception: |
|
| 382 | try: |
|
| 383 | import json |
|
| 384 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 385 | self.__create_dataset(entry, name, data) |
|
| 386 | except Exception: |
|
| 387 | try: |
|
| 388 | self.__create_dataset(entry, name, data) |
|
| 389 | except: |
|
| 390 | raise Exception('Unable to output %s to file.' % name) |
|
| 391 | ||
| 392 | def __create_dataset(self, entry, name, data): |
|
| 393 | if name not in list(entry.keys()): |
|