| @@ 577-596 (lines=20) @@ | ||
| 574 | gp = entry.require_group('data') |
|
| 575 | self.__output_data_type(gp, data.data, 'data') |
|
| 576 | ||
| 577 | def __output_data(self, entry, data, name): |
|
| 578 | if isinstance(data, dict): |
|
| 579 | entry = entry.require_group(name) |
|
| 580 | entry.attrs[NX_CLASS] = 'NXcollection' |
|
| 581 | for key, value in data.items(): |
|
| 582 | self.__output_data(entry, value, key) |
|
| 583 | else: |
|
| 584 | try: |
|
| 585 | self.__create_dataset(entry, name, data) |
|
| 586 | except Exception: |
|
| 587 | try: |
|
| 588 | import json |
|
| 589 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 590 | self.__create_dataset(entry, name, data) |
|
| 591 | except Exception: |
|
| 592 | try: |
|
| 593 | data = cu._savu_encoder(data) |
|
| 594 | self.__create_dataset(entry, name, data) |
|
| 595 | except: |
|
| 596 | raise Exception('Unable to output %s to file.' % name) |
|
| 597 | ||
| 598 | def __create_dataset(self, entry, name, data): |
|
| 599 | if name not in list(entry.keys()): |
|
| @@ 350-368 (lines=19) @@ | ||
| 347 | nx_data.attrs['NX_class'] = 'NXdata' |
|
| 348 | self.__output_data(nx_data, value, key) |
|
| 349 | ||
| 350 | def __output_data(self, entry, data, name): |
|
| 351 | if isinstance(data, dict): |
|
| 352 | entry = entry.require_group(name) |
|
| 353 | entry.attrs['NX_class'] = 'NXcollection' |
|
| 354 | for key, value in data.items(): |
|
| 355 | self.__output_data(entry, value, key) |
|
| 356 | else: |
|
| 357 | try: |
|
| 358 | self.__create_dataset(entry, name, data) |
|
| 359 | except Exception: |
|
| 360 | try: |
|
| 361 | import json |
|
| 362 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 363 | self.__create_dataset(entry, name, data) |
|
| 364 | except Exception: |
|
| 365 | try: |
|
| 366 | self.__create_dataset(entry, name, data) |
|
| 367 | except: |
|
| 368 | raise Exception('Unable to output %s to file.' % name) |
|
| 369 | ||
| 370 | def __create_dataset(self, entry, name, data): |
|
| 371 | if name not in list(entry.keys()): |
|