I use h5py. I want to have a compound dataset of strings (column1) and regional_reference (column2) inside my HDF5 file. For this, I am trying to define a numpy dtype of String and Reference.
But even before this, I am failing to define a numpy dtype array of hdf5 regional references.
##map_h5py.py
import h5py
import numpy as np
h = h5py.File('testing_mapping.h5', 'a')
cell_names = ['cell0', 'cell1', 'cell2', 'cell3']
dummy_data = np.random.rand(4,20)
##create random data
dset = h.create_dataset('/data/Vm', data=dummy_data, dtype='float32')
#declare a data type
sp_type = np.dtype([('ref',h5py.special_dtype(ref=h5py.RegionReference))])
##this works - 1
refs_list = []
for ii in range(dset.shape[0]):
refs_list.append(dset.regionref[ii])
h.create_dataset('/map/Vm_list', data=refs_list, dtype=h5py.special_dtype(ref=h5py.RegionReference))
##this doesn't - 2
ref_dset = h.create_dataset('/map/Vm_pre', shape=(dset.shape[0],), dtype=sp_type)
for ii in range(dset.shape[0]):
ref_dset[ii] = dset.regionref[ii]
# #this doesn't - 3
ref_numpy = np.zeros(dset.shape[0], dtype=sp_type)
for ii in range(dset.shape[0]):
ref_numpy[ii] = dset.regionref[ii]
h.create_dataset('/map/Vm_post', data=ref_numpy, dtype=sp_type)
h.close()
The error in case of 2 and 3 is the following,
ref_numpy[ii] = dset.regionref[ii]
ValueError: Setting void-array with object members using buffer.