Skip to content

Commit

Permalink
bluepysnap away 3
Browse files Browse the repository at this point in the history
  • Loading branch information
katta committed Sep 20, 2024
1 parent 7987923 commit 2a8a987
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/simulation_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Preprocessor

- **filter_neuron**: Boolean. Determines if the neurons connected to astrocytes must be filtered out when generating the mesh.
- **neuron_population_name**: String. Name of the neuron population to use. Typically: "All".
- **astrocyte_population_name**: String. Name of the astrocyte population to use. Typically: "astrocytes".

Connections among simulators
============================
Expand Down
6 changes: 5 additions & 1 deletion multiscale_run/data/config/msr.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@
"neuron_population_name": {
"description": "Name of the neuron population to use. Typically: \"All\".",
"type": "string"
}
},
"astrocyte_population_name": {
"description": "Name of the astrocyte population to use. Typically: \"astrocytes\".",
"type": "string"
}
},
"required": [
"filter_neuron",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"node_sets": {
"filter_neuron": false,
"neuron_population_name": "All"
"neuron_population_name": "All",
"astrocyte_population_name": "astrocytes"
}
},
"connections": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"node_sets": {
"filter_neuron": false,
"neuron_population_name": "All"
"neuron_population_name": "All",
"astrocyte_population_name": "astrocytes"
}
},
"connections": {
Expand Down
3 changes: 2 additions & 1 deletion multiscale_run/data/config/tiny_CI/simulation_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"node_sets": {
"filter_neuron": false,
"neuron_population_name": "All"
"neuron_population_name": "neocortex_neurons",
"astrocyte_population_name": "astrocytes"
}
},
"connections": {
Expand Down
66 changes: 38 additions & 28 deletions multiscale_run/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from pathlib import Path

import gmsh
import libsonata
import numpy as np
import pandas as pd
import trimesh
import libsonata

from . import utils

Expand Down Expand Up @@ -80,14 +81,18 @@ def autogen_node_sets(self):

# Generate the node_sets.json
template = {
"testNGVSSCX_AstroMini": ["testNGVSSCX", "Astrocytes"],
"src_cells": {"population": "All", "node_id": None},
"testNGVSSCX": {"population": "All", "node_id": None},
"Astrocytes": {"population": "astrocytes", "node_id": None},
"All": ["Neurons", "Astrocytes"],
"Neurons": {
"population": self.config.multiscale_run.preprocessor.node_sets.neuron_population_name,
"node_id": None,
},
"Astrocytes": {
"population": self.config.multiscale_run.preprocessor.node_sets.astrocyte_population_name,
"node_id": None,
},
}

template["src_cells"]["node_id"] = self.selected_neurons.tolist()
template["testNGVSSCX"]["node_id"] = self.selected_neurons.tolist()
template["Neurons"]["node_id"] = self.selected_neurons.tolist()
template["Astrocytes"]["node_id"] = self.selected_astrocytes.tolist()

with open(output_filename, "w") as fout:
Expand Down Expand Up @@ -121,18 +126,19 @@ def extract_information_from_circuit(self):
self.config.multiscale_run.preprocessor.node_sets.neuron_population_name
)

circuit_config = libsonata.CircuitConfig.from_file(circuit_path)
circuit_config = libsonata.CircuitConfig.from_file(
str(self.config.config_path.parent / self.config.network)
)
gliovascular = circuit_config.edge_population("gliovascular")
edges_ids = np.arange(gliovascular.size, dtype=np.uint64)

selection = libsonata.Selection(values=edges_ids)
endfoot = gliovascular.get_attribute("endfoot_compartment_length", selection)
targetnode = gliovascular.target_nodes(selection)
# Convert lists to DataFrame
df_combined = pd.DataFrame({
'@target_node': targetnode,
'endfoot_compartment_length': endfoot
})
df_combined = pd.DataFrame(
{"@target_node": targetnode, "endfoot_compartment_length": endfoot}
)

filtered_df = df_combined[df_combined.endfoot_compartment_length > 0]
selected_astrocytes = filtered_df["@target_node"].unique()
Expand All @@ -145,64 +151,68 @@ def extract_information_from_circuit(self):
# Get the neuroglial edge population
neuroglial = circuit_config.edge_population("neuroglial")
# Create a selection of all edges
all_edges = libsonata.Selection(np.arange(neuroglial.size, dtype=np.uint16))
all_edges = libsonata.Selection(np.arange(neuroglial.size, dtype=np.uint16))
# Get source and target nodes
source_nodes = neuroglial.source_nodes(all_edges)
target_nodes = neuroglial.target_nodes(all_edges)

# Create a mask for selected astrocytes
astrocyte_mask = np.isin(source_nodes, selected_astrocytes)

# Get unique target nodes (neurons) connected to selected astrocytes
selected_neurons = np.unique(target_nodes[astrocyte_mask])

# Create a selection for the selected neurons
neuron_selection = libsonata.Selection(selected_neurons)

# Get the node population
node_population = circuit_config.node_population(pop_name)

# Get attributes for selected neurons
attributes = sorted(node_population.attribute_names)
neuro_df = {'node_ids': neuron_selection.flatten()}
neuro_df = {"node_ids": neuron_selection.flatten()}
for attr in attributes:
neuro_df[attr] = node_population.get_attribute(attr, neuron_selection)

# Get dynamics attributes for selected neurons
dynamics_attributes = sorted(node_population.dynamics_attribute_names)
for attr in dynamics_attributes:
neuro_df[f"@dynamics:{attr}"] = node_population.get_dynamics_attribute(attr, neuron_selection)

neuro_df[f"@dynamics:{attr}"] = node_population.get_dynamics_attribute(
attr, neuron_selection
)

# Convert to pandas DataFrame if needed
neuro_df = pd.DataFrame(neuro_df)

else:
node_ids_population = circuit_config.node_population(pop_name)
selected_neurons = np.arange(node_ids_population.size, dtype=np.uint16)
sorted_attr_names = sorted(node_ids_population.attribute_names)
sorted_dynamic_attr_names = sorted(node_ids_population.dynamics_attribute_names)
# Combine sorted_attr_names and sorted_dynamic_attr_names
all_sorted_attr_names = sorted_attr_names + [f"@dynamics:{attr}" for attr in sorted_dynamic_attr_names]
sorted_dynamic_attr_names = sorted(
node_ids_population.dynamics_attribute_names
)

node_selection = libsonata.Selection(values=selected_neurons)
node_ids = node_selection.flatten()
data = {'node_ids': node_ids}
data = {"node_ids": node_ids}

# Add regular attributes
for attr in sorted_attr_names:
data[attr] = node_ids_population.get_attribute(attr, node_selection)

# Add dynamics attributes
for attr in sorted_dynamic_attr_names:
data[f"@dynamics:{attr}"] = node_ids_population.get_dynamics_attribute(attr, node_selection)
data[f"@dynamics:{attr}"] = node_ids_population.get_dynamics_attribute(
attr, node_selection
)

# Create the DataFrame
neuro_df = pd.DataFrame(data)

logging.info(f"There are {selected_neurons.size} selected neurons")

neuro_df = neuro_df.rename(columns={"population": "population_name"})
neuro_df= neuro_df.reset_index(drop=False)
neuro_df = neuro_df.reset_index(drop=False)

self.neuro_df = neuro_df
self.selected_neurons = selected_neurons
Expand Down
1 change: 1 addition & 0 deletions multiscale_run/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def initialize(self):
bf_m=self.managers["bloodflow"],
)
self.prep.check_mesh()
exit()
self.managers["steps"] = steps_manager.MsrStepsManager(config=self.conf)
self.managers["steps"].init_sim()
self.conn_m.connect_neurodamus2steps()
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ classifiers = [
]
dependencies = [
"astrovascpy>=0.1.5",
"bluepysnap>=2",
"diffeqpy>=1.1",
"gmsh>=4.2",
"jinja2>=3",
Expand Down

0 comments on commit 2a8a987

Please sign in to comment.