dbbs-lab / bsb-core

The Brain Scaffold Builder
https://bsb.readthedocs.io
GNU General Public License v3.0
21 stars 16 forks source link

How to add a new connection type on an existing .hdf5 file #211

Closed silviafeltrin closed 3 years ago

silviafeltrin commented 3 years ago

Good morning, I have some issues in addiing a new connection type on an existing .hdf5 file containing only the results of the placement. I used the function from_hdf5 to run the new connection from the existing .hdf5 file, but how to save the new connection on the .hdf5? I tried to write 'scaffold.compile_output() ' but it gave me error:

image

Here you can find the source code, the .hdf5 file and the .json file used: https://polimi365-my.sharepoint.com/:f:/g/personal/10527301_polimi_it/Em-cUGZJdiNKgdQKWRhBQJwBntpgXf5Ukh-o0vLD5Y8Jig?e=pQr0Xx

Helveg commented 3 years ago

Currently there are no public APIs in v3.6 to perform the seperate write operations you're looking for. Instead the scaffold object needs to be tricked into believing there`s only 1 placement/connectivity set in the entire network and it will write just that.

So a bit of a hacky workaround. Instead of compile_output try this:

# Storing a single connection type
with h5py.File(filename_h5, "a") as f:
  cells_group = f["cells"]
  # Name of the type
  tag = "mossy_to_glomerulus"
  # Remove the other conn types from the scaffold so no other write operations are attempted
  scaffold.cell_connections_by_tag = {tag: scaffold.cell_connections_by_tag[tag]}
  # Remove any previous data if it exists
  if f"connections/{tag}" in cells_group:
    del cells_group[f"connections/{tag}"]
  if f"connection_compartments/{tag}" in cells_group:
    del cells_group[f"connection_compartments/{tag}"]
  if f"connection_morphologies/{tag}" in cells_group:
    del cells_group[f"connection_morphologies/{tag}"]
  # Perform the single-type write operation
  scaffold.output_formatter.store_cell_connections(cells_group)
silviafeltrin commented 3 years ago

Ok, thanks, I tried, but still there are some errors:

image

Helveg commented 3 years ago

Ah sorry, there were some typos in my previous post, try copy pasting the previous code again.

silviafeltrin commented 3 years ago

Ok thank you!

Helveg commented 3 years ago

Does it work now?

silviafeltrin commented 3 years ago

yes