From 2a8a98727d2de695edac5cf8e71587bbed21318d Mon Sep 17 00:00:00 2001 From: katta Date: Fri, 20 Sep 2024 15:21:52 +0200 Subject: [PATCH] bluepysnap away 3 --- docs/simulation_config.rst | 1 + multiscale_run/data/config/msr.schema.json | 6 +- .../rat_sscxS1HL_V10/simulation_config.json | 3 +- .../rat_sscxS1HL_V6/simulation_config.json | 3 +- .../config/tiny_CI/simulation_config.json | 3 +- multiscale_run/preprocessor.py | 66 +++++++++++-------- multiscale_run/simulation.py | 1 + pyproject.toml | 1 - 8 files changed, 51 insertions(+), 33 deletions(-) diff --git a/docs/simulation_config.rst b/docs/simulation_config.rst index 3ca91a3..4ecaafe 100644 --- a/docs/simulation_config.rst +++ b/docs/simulation_config.rst @@ -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 ============================ diff --git a/multiscale_run/data/config/msr.schema.json b/multiscale_run/data/config/msr.schema.json index 7e040eb..36f6acd 100644 --- a/multiscale_run/data/config/msr.schema.json +++ b/multiscale_run/data/config/msr.schema.json @@ -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", diff --git a/multiscale_run/data/config/rat_sscxS1HL_V10/simulation_config.json b/multiscale_run/data/config/rat_sscxS1HL_V10/simulation_config.json index 3b3bada..c0f3a07 100644 --- a/multiscale_run/data/config/rat_sscxS1HL_V10/simulation_config.json +++ b/multiscale_run/data/config/rat_sscxS1HL_V10/simulation_config.json @@ -19,7 +19,8 @@ }, "node_sets": { "filter_neuron": false, - "neuron_population_name": "All" + "neuron_population_name": "All", + "astrocyte_population_name": "astrocytes" } }, "connections": { diff --git a/multiscale_run/data/config/rat_sscxS1HL_V6/simulation_config.json b/multiscale_run/data/config/rat_sscxS1HL_V6/simulation_config.json index 1ea65b4..0464d42 100644 --- a/multiscale_run/data/config/rat_sscxS1HL_V6/simulation_config.json +++ b/multiscale_run/data/config/rat_sscxS1HL_V6/simulation_config.json @@ -19,7 +19,8 @@ }, "node_sets": { "filter_neuron": false, - "neuron_population_name": "All" + "neuron_population_name": "All", + "astrocyte_population_name": "astrocytes" } }, "connections": { diff --git a/multiscale_run/data/config/tiny_CI/simulation_config.json b/multiscale_run/data/config/tiny_CI/simulation_config.json index 38c8732..4d65f5e 100644 --- a/multiscale_run/data/config/tiny_CI/simulation_config.json +++ b/multiscale_run/data/config/tiny_CI/simulation_config.json @@ -19,7 +19,8 @@ }, "node_sets": { "filter_neuron": false, - "neuron_population_name": "All" + "neuron_population_name": "neocortex_neurons", + "astrocyte_population_name": "astrocytes" } }, "connections": { diff --git a/multiscale_run/preprocessor.py b/multiscale_run/preprocessor.py index eacff37..3c34ae3 100644 --- a/multiscale_run/preprocessor.py +++ b/multiscale_run/preprocessor.py @@ -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 @@ -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: @@ -121,7 +126,9 @@ 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) @@ -129,10 +136,9 @@ def extract_information_from_circuit(self): 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() @@ -145,34 +151,36 @@ 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) @@ -180,13 +188,13 @@ def extract_information_from_circuit(self): 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: @@ -194,7 +202,9 @@ def extract_information_from_circuit(self): # 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) @@ -202,7 +212,7 @@ def extract_information_from_circuit(self): 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 diff --git a/multiscale_run/simulation.py b/multiscale_run/simulation.py index 887e9fa..8db1537 100644 --- a/multiscale_run/simulation.py +++ b/multiscale_run/simulation.py @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 42a102b..ce2ceff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,6 @@ classifiers = [ ] dependencies = [ "astrovascpy>=0.1.5", - "bluepysnap>=2", "diffeqpy>=1.1", "gmsh>=4.2", "jinja2>=3",