| @@ 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()): |
|
| @@ 337-355 (lines=19) @@ | ||
| 334 | nx_data.attrs['NX_class'] = 'NXdata' |
|
| 335 | self.__output_data(nx_data, value, key) |
|
| 336 | ||
| 337 | def __output_data(self, entry, data, name): |
|
| 338 | if isinstance(data, dict): |
|
| 339 | entry = entry.require_group(name) |
|
| 340 | entry.attrs['NX_class'] = 'NXcollection' |
|
| 341 | for key, value in data.items(): |
|
| 342 | self.__output_data(entry, value, key) |
|
| 343 | else: |
|
| 344 | try: |
|
| 345 | self.__create_dataset(entry, name, data) |
|
| 346 | except Exception: |
|
| 347 | try: |
|
| 348 | import json |
|
| 349 | data = np.array([json.dumps(data).encode("ascii")]) |
|
| 350 | self.__create_dataset(entry, name, data) |
|
| 351 | except Exception: |
|
| 352 | try: |
|
| 353 | self.__create_dataset(entry, name, data) |
|
| 354 | except: |
|
| 355 | raise Exception('Unable to output %s to file.' % name) |
|
| 356 | ||
| 357 | def __create_dataset(self, entry, name, data): |
|
| 358 | if name not in list(entry.keys()): |
|