| @@ 604-623 (lines=20) @@ | ||
| 601 | gp = entry.require_group('data') |
|
| 602 | self.__output_data_type(gp, data.data, 'data') |
|
| 603 | ||
| 604 | def __output_data(self, entry, data, name): |
|
| 605 | if isinstance(data, dict): |
|
| 606 | entry = entry.require_group(name) |
|
| 607 | entry.attrs[NX_CLASS] = 'NXcollection' |
|
| 608 | for key, value in data.items(): |
|
| 609 | self.__output_data(entry, value, key) |
|
| 610 | else: |
|
| 611 | try: |
|
| 612 | self.__create_dataset(entry, name, data) |
|
| 613 | except Exception: |
|
| 614 | try: |
|
| 615 | import json |
|
| 616 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 617 | self.__create_dataset(entry, name, data) |
|
| 618 | except Exception: |
|
| 619 | try: |
|
| 620 | data = cu._savu_encoder(data) |
|
| 621 | self.__create_dataset(entry, name, data) |
|
| 622 | except: |
|
| 623 | raise Exception('Unable to output %s to file.' % name) |
|
| 624 | ||
| 625 | def __create_dataset(self, entry, name, data): |
|
| 626 | if name not in list(entry.keys()): |
|
| @@ 373-391 (lines=19) @@ | ||
| 370 | nx_data.attrs['NX_class'] = 'NXdata' |
|
| 371 | self.__output_data(nx_data, value, key) |
|
| 372 | ||
| 373 | def __output_data(self, entry, data, name): |
|
| 374 | if isinstance(data, dict): |
|
| 375 | entry = entry.require_group(name) |
|
| 376 | entry.attrs['NX_class'] = 'NXcollection' |
|
| 377 | for key, value in data.items(): |
|
| 378 | self.__output_data(entry, value, key) |
|
| 379 | else: |
|
| 380 | try: |
|
| 381 | self.__create_dataset(entry, name, data) |
|
| 382 | except Exception: |
|
| 383 | try: |
|
| 384 | import json |
|
| 385 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 386 | self.__create_dataset(entry, name, data) |
|
| 387 | except Exception: |
|
| 388 | try: |
|
| 389 | self.__create_dataset(entry, name, data) |
|
| 390 | except: |
|
| 391 | raise Exception('Unable to output %s to file.' % name) |
|
| 392 | ||
| 393 | def __create_dataset(self, entry, name, data): |
|
| 394 | if name not in list(entry.keys()): |
|