Skip to content

Commit

Permalink
Update humam.yml and humam_tutorial.ipynb for improved dependency man…
Browse files Browse the repository at this point in the history
…agement and code clarity; update connectivity.py and figure_connectivity_matrices.py
  • Loading branch information
shimoura committed Nov 7, 2024
1 parent e3ae0eb commit c09194e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
7 changes: 4 additions & 3 deletions humam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ dependencies:
- seaborn
- python
- pandas
- bioconda::snakemake
- anaconda::networkx
- anaconda::scipy
- scipy
- ipykernel
- pip
- pip:
- nnmt
- dicthash
- networkx
- snakemake
22 changes: 15 additions & 7 deletions humam_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -697,7 +705,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "humam_nest3",
"display_name": "humam-nest3",
"language": "python",
"name": "python3"
},
Expand Down
8 changes: 4 additions & 4 deletions src/data_preprocessing/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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()
)
Expand Down
13 changes: 6 additions & 7 deletions src/figure_connectivity_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c09194e

Please sign in to comment.