diff --git a/humam.yml b/humam.yml index 5990b6e..8b3ab96 100644 --- a/humam.yml +++ b/humam.yml @@ -12,10 +12,11 @@ dependencies: - seaborn - python - pandas - - bioconda::snakemake - - anaconda::networkx - - anaconda::scipy + - scipy - ipykernel + - pip - pip: - nnmt - dicthash + - networkx + - snakemake \ No newline at end of file diff --git a/humam_tutorial.ipynb b/humam_tutorial.ipynb index f5a09de..9c79afd 100644 --- a/humam_tutorial.ipynb +++ b/humam_tutorial.ipynb @@ -289,21 +289,27 @@ "else:\n", "\t# Create NeuroNumbers class\n", "\t# This class calculates the number of neurons in the network\n", - "\tNN = NeuronNumbers(\n", + "\tNeuronNumberClass = NeuronNumbers(\n", "\t\tsurface_area=net_params['surface_area'],\n", "\t\t**net_params['cytoarchitecture_params']\n", "\t)\n", "\t# Create SynapseNumbers class\n", "\t# This class calculates the number of synapses in the network\n", - "\tSN = SynapseNumbers(\n", - "\t\tNN=NN,\n", + "\tSynapseNumberClass = SynapseNumbers(\n", + "\t\tNN=NeuronNumberClass,\n", "\t\t**net_params['predictive_connectomic_params']\n", "\t)\n", "\n", + "\t# Get the number of neurons and synapses in the full-scale network for further reference\n", + "\tfullscale_NN_SN = {\n", + "\t\t'NN': NeuronNumberClass.getNeuronNumbers(),\n", + "\t\t'SN': SynapseNumberClass.getSynapseNumbers()\n", + "\t}\n", + "\n", "\t# Create Network\n", "\t# This class prepares the network for simulation, including the initialization of the neurons and synapses\n", "\t# and the creation of the connectivity matrix. The scaling factors are applied here.\n", - "\thumam = Network(NN, SN, net_params)\n", + "\thumam = Network(NeuronNumberClass, SynapseNumberClass, net_params)\n", "\t# Extract the network dictionary\n", "\thumam.dump(outpath)\n", "\t# Get the network hash for further reference\n", @@ -390,8 +396,10 @@ "outputs": [], "source": [ "from figure_connectivity_matrices import plot_connectivity_matrices\n", - "# plot_connectivity_matrices(net_dict, SN, NN)\n", - "plot_connectivity_matrices(net_dict)" + "try:\n", + "\tplot_connectivity_matrices(net_dict, fullscale_NN_SN)\n", + "except NameError:\n", + "\tplot_connectivity_matrices(net_dict)" ] }, { @@ -697,7 +705,7 @@ ], "metadata": { "kernelspec": { - "display_name": "humam_nest3", + "display_name": "humam-nest3", "language": "python", "name": "python3" }, diff --git a/src/data_preprocessing/connectivity.py b/src/data_preprocessing/connectivity.py index 0ff6ebd..1cd380a 100644 --- a/src/data_preprocessing/connectivity.py +++ b/src/data_preprocessing/connectivity.py @@ -218,7 +218,7 @@ def tmp(val, SLN_FF, SLN_FB): return 'lat' else: return 'FF' - d = self.SLN.applymap(lambda x: tmp(x, SLN_FF, SLN_FB)) + d = self.SLN.map(lambda x: tmp(x, SLN_FF, SLN_FB)) return d def populationSpecificSynapseNumbers(self, SLN_FF, SLN_FB, Z_i, lmbda): @@ -253,11 +253,11 @@ def populationSpecificSynapseNumbers(self, SLN_FF, SLN_FB, Z_i, lmbda): index=multiindex ) X = pd.Series( - data=0, + data=0., index=multiindex_noarea ) Y = pd.Series( - data=0, + data=0., index=self.layer_list_plus1 ) @@ -382,7 +382,7 @@ def populationSpecificSynapseNumbers(self, SLN_FF, SLN_FB, Z_i, lmbda): ) # Create Y vector from eq. (3) Schmidt et al. SuppMat - Y *= 0 + Y *= 0. relThickTargetPattern = ( thickTarget.loc[P_t] / thickTarget.loc[P_t].sum() ) diff --git a/src/figure_connectivity_matrices.py b/src/figure_connectivity_matrices.py index 9c4e1bd..22e6fac 100644 --- a/src/figure_connectivity_matrices.py +++ b/src/figure_connectivity_matrices.py @@ -17,7 +17,7 @@ def calculate_indegrees(synapses, neurons): Group the subpopulations together by summing the indegrees for each area. """ indegrees = synapses.div(neurons, axis=0) - grouped_indegrees = indegrees.groupby(level=0, axis=0).sum().groupby(level=0, axis=1).sum() + grouped_indegrees = indegrees.groupby(level=0).sum().T.groupby(level=0).sum().T return grouped_indegrees def plot_matrix(ax, matrix, title, areas_short_names): @@ -34,18 +34,17 @@ def plot_matrix(ax, matrix, title, areas_short_names): ax.set_yticks(np.arange(0.5, len(areas_short_names), 1)) ax.set_yticklabels(areas_short_names) -def plot_connectivity_matrices(net_params_downscaled, SN=None, NN=None, save_path=None): +def plot_connectivity_matrices(net_params_downscaled, net_params_fullscale=None, save_path=None): """ Plots the connectivity matrices for both downscaled and full-scale networks. Parameters: net_params_downscaled (dict): Dictionary containing the downscaled network parameters, including synapses and neuron numbers. - SN (object or None): An object that provides the method getSynapseNumbers() to retrieve the synapse numbers for the full-scale network. - NN (object or None): An object that provides the method getNeuronNumbers() to retrieve the neuron numbers for the full-scale network. + net_params_fullscale (dict or None): Dictionary containing the full-scale network parameters, including synapses and neuron numbers. save_path (str or None): File path to save the figure. If None, the figure will not be saved. Returns: None: This function does not return any value. It displays the connectivity matrices using matplotlib. """ - if SN is None or NN is None: + if net_params_fullscale is None: # Only plot the downscaled connectivity matrix fig, ax = plt.subplots(figsize=(6, 5)) @@ -78,8 +77,8 @@ def plot_connectivity_matrices(net_params_downscaled, SN=None, NN=None, save_pat plot_matrix(axs[0], grouped_indegrees_downscaled, 'Downscaled Connectivity Matrix', areas_short_names) # Get the number of synapses and neurons for the full-scale network - full_scale_synapses = SN.getSynapseNumbers() - full_scale_neurons = NN.getNeuronNumbers() + full_scale_synapses = net_params_fullscale['SN'] + full_scale_neurons = net_params_fullscale['NN'] # Calculate the indegrees for the full-scale version grouped_indegrees_full_scale = calculate_indegrees(full_scale_synapses, full_scale_neurons)