Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iraikov/neuroh5
Browse files Browse the repository at this point in the history
  • Loading branch information
iraikov committed Aug 12, 2024
2 parents e3964ae + 6a7ca00 commit a9a8060
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions tests/test_write_cell_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,40 @@ def h5_concat_dataset(dset, data):
dset[dsize:] = data
return dset

with h5py.File(output_path, "a") as h5:

n_pop = 1
defs = []
pop_def = (pop_name,0,1000000,0)
defs.append(pop_def)

# create an HDF5 enumerated type for the population label
mapping = { name: idx for name, start, count, idx in defs }
dt = h5py.special_dtype(enum=(np.uint16, mapping))
h5[path_population_labels] = dt

dt = np.dtype([("Start", np.uint64), ("Count", np.uint32),
("Population", h5[path_population_labels].dtype)])
h5[path_population_range] = dt

# create an HDF5 compound type for population ranges
dt = h5[path_population_range].dtype

g = h5_get_group (h5, grp_h5types)

dset = h5_get_dataset(g, grp_populations, maxshape=(n_pop,), dtype=dt)
dset.resize((n_pop,))
a = np.zeros(n_pop, dtype=dt)
idx = 0
for name, start, count, idx in defs:
a[idx]["Start"] = start
a[idx]["Count"] = count
a[idx]["Population"] = idx
idx += 1

dset[:] = a

if rank == 0:
with h5py.File(output_path, "a") as h5:

n_pop = 1
defs = []
pop_def = (pop_name,0,1000000,0)
defs.append(pop_def)

# create an HDF5 enumerated type for the population label
mapping = { name: idx for name, start, count, idx in defs }
dt = h5py.special_dtype(enum=(np.uint16, mapping))
h5[path_population_labels] = dt

dt = np.dtype([("Start", np.uint64), ("Count", np.uint32),
("Population", h5[path_population_labels].dtype)])
h5[path_population_range] = dt

# create an HDF5 compound type for population ranges
dt = h5[path_population_range].dtype

g = h5_get_group (h5, grp_h5types)

dset = h5_get_dataset(g, grp_populations, maxshape=(n_pop,), dtype=dt)
dset.resize((n_pop,))
a = np.zeros(n_pop, dtype=dt)
idx = 0
for name, start, count, idx in defs:
a[idx]["Start"] = start
a[idx]["Count"] = count
a[idx]["Population"] = idx
idx += 1

dset[:] = a
comm.barrier()

write_cell_attributes(output_path, pop_name, attr_dict, namespace='Test Attributes')
print(list(read_cell_attributes(output_path, pop_name, 'Test Attributes')))

0 comments on commit a9a8060

Please sign in to comment.