pycroscopy / sidpy

Python utilities for storing, processing, and visualizing spectroscopic and imaging data
https://pycroscopy.github.io/sidpy/
MIT License
11 stars 14 forks source link

write_simple_attributes fails #64

Closed ramav87 closed 4 years ago

ramav87 commented 4 years ago

write_simple_attributes fails because it cannot write enums objects in h5:

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last)

in 3 shape = (10,10,100) 4 dataset_name = 'testdataset' ----> 5 empty_dset = create_empty_dataset(shape, h5_group, dataset_name) ~/PycharmProjects/pyNSID/pyNSID/io/hdf_io.py in create_empty_dataset(shape, h5_group, name) 49 raise TypeError('h5_group should be a h5py.Group object') 50 ---> 51 return write_nsid_dataset(Dataset.from_array(np.zeros(shape)), h5_group, name) 52 53 ~/PycharmProjects/pyNSID/pyNSID/io/hdf_io.py in write_nsid_dataset(dataset, h5_group, main_data_name, verbose, **kwargs) 137 'main_data_name': dataset.title, 'data_type': dataset.data_type, 138 'modality': dataset.modality, 'source': dataset.source} --> 139 write_simple_attrs(h5_main, attrs_to_write) 140 # dset = write_main_dataset(h5_group, np.array(dataset), main_data_name, 141 # dataset.quantity, dataset.units, dataset.data_type, dataset.modality, ~/PycharmProjects/sidpy/sidpy/hdf/hdf_utils.py in write_simple_attrs(h5_obj, attrs, verbose) 396 if verbose: 397 print('Attribute cleaned into: {}'.format(clean_val)) --> 398 h5_obj.attrs[key] = clean_val 399 if verbose: 400 print('Wrote all (simple) attributes to {}: {}\n' h5py/_objects.pyx in h5py._objects.with_phil.wrapper() h5py/_objects.pyx in h5py._objects.with_phil.wrapper() //anaconda3/lib/python3.7/site-packages/h5py/_hl/attrs.py in __setitem__(self, name, value) 98 use the methods create() and modify(). 99 """ --> 100 self.create(name, data=value) 101 102 @with_phil //anaconda3/lib/python3.7/site-packages/h5py/_hl/attrs.py in create(self, name, data, shape, dtype) 182 # Make HDF5 datatype and dataspace for the H5A calls 183 if use_htype is None: --> 184 htype = h5t.py_create(original_dtype, logical=True) 185 htype2 = h5t.py_create(original_dtype) # Must be bit-for-bit representation rather than logical 186 else: h5py/h5t.pyx in h5py.h5t.py_create() h5py/h5t.pyx in h5py.h5t.py_create() h5py/h5t.pyx in h5py.h5t.py_create() TypeError: Object dtype dtype('O') has no native HDF5 equivalent`