From e3ae0eb999855a2d62d3e99d87e840fb4a8a2beb Mon Sep 17 00:00:00 2001 From: shimoura Date: Wed, 6 Nov 2024 19:10:41 +0100 Subject: [PATCH] Update humam_tutorial.ipynb to enhance output path handling, add network and simulation hash checks, and adjust neuron plotting parameters for improved functionality. --- humam_tutorial.ipynb | 94 +++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/humam_tutorial.ipynb b/humam_tutorial.ipynb index d5cec11..f5a09de 100644 --- a/humam_tutorial.ipynb +++ b/humam_tutorial.ipynb @@ -218,6 +218,7 @@ "outputs": [], "source": [ "# Get path to the output directory\n", + "net_params['outpath'] = os.path.join(os.getcwd(), 'out', 'downscaled')\n", "outpath = net_params['outpath']\n", "\n", "# Get base path\n", @@ -243,7 +244,7 @@ "# Set plotting parameters\n", "ana_params['plotRasterArea']['low'] = 1600 # Lower bound of the area to plot the raster plot\n", "ana_params['plotRasterArea']['high'] = 2000 # Upper bound of the area to plot the raster plot\n", - "ana_params['plotRasterArea']['fraction'] = 0.5 # Fraction of neurons to plot in the raster plot" + "ana_params['plotRasterArea']['fraction'] = 1.0 # Fraction of neurons to plot in the raster plot" ] }, { @@ -281,27 +282,40 @@ "metadata": {}, "outputs": [], "source": [ - "# Create NeuroNumbers class\n", - "# This class calculates the number of neurons in the network\n", - "NN = NeuronNumbers(\n", - " surface_area=net_params['surface_area'],\n", - " **net_params['cytoarchitecture_params']\n", - ")\n", - "# Create SynapseNumbers class\n", - "# This class calculates the number of synapses in the network\n", - "SN = SynapseNumbers(\n", - " NN=NN,\n", - " **net_params['predictive_connectomic_params']\n", - ")\n", + "# Check if the network has already been created\n", + "if os.path.exists(os.path.join(outpath, 'network_hash.txt')):\n", + "\twith open(os.path.join(outpath, 'network_hash.txt'), 'r') as f:\n", + "\t\tnet_hash = f.read()\n", + "else:\n", + "\t# Create NeuroNumbers class\n", + "\t# This class calculates the number of neurons in the network\n", + "\tNN = 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", + "\t\t**net_params['predictive_connectomic_params']\n", + "\t)\n", "\n", - "# Create Network\n", - "# This class prepares the network for simulation, including the initialization of the neurons and synapses\n", - "# and the creation of the connectivity matrix. The scaling factors are applied here.\n", - "humam = Network(NN, SN, net_params)\n", - "# Extract the network dictionary\n", - "humam.dump(outpath)\n", - "# Get the network hash for further reference\n", - "net_hash = humam.getHash()" + "\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", + "\t# Extract the network dictionary\n", + "\thumam.dump(outpath)\n", + "\t# Get the network hash for further reference\n", + "\tnet_hash = humam.getHash()\n", + "\n", + "\t# Save network hash to a file\n", + "\twith open(os.path.join(outpath, 'network_hash.txt'), 'w') as f:\n", + "\t\tf.write(net_hash)\n", + "\n", + "# Load the network dictionary\n", + "net_folder = os.path.join(outpath, net_hash)\n", + "net_dict = networkDictFromDump(net_folder)" ] }, { @@ -328,7 +342,7 @@ "outputs": [], "source": [ "from figure_theory import meanfield_rate\n", - "theo_rates = meanfield_rate(net_hash)" + "theo_rates = meanfield_rate(outpath, net_hash)" ] }, { @@ -376,7 +390,8 @@ "outputs": [], "source": [ "from figure_connectivity_matrices import plot_connectivity_matrices\n", - "plot_connectivity_matrices(humam.net, SN, NN)" + "# plot_connectivity_matrices(net_dict, SN, NN)\n", + "plot_connectivity_matrices(net_dict)" ] }, { @@ -404,22 +419,27 @@ "metadata": {}, "outputs": [], "source": [ - "# Read network dict\n", - "net_folder = os.path.join(outpath, net_hash)\n", - "net_dict = networkDictFromDump(net_folder)\n", + "# Check if the simulation has already run\n", + "if os.path.exists(os.path.join(outpath, net_hash, 'sim_hash.txt')):\n", + "\twith open(os.path.join(outpath, net_hash, 'sim_hash.txt'), 'r') as f:\n", + "\t\tsim_hash = f.read()\n", + "else:\n", + "\t# Create Simulation class\n", + "\tsim = Simulation(sim_params, net_dict)\n", + "\t# Extract the simulation dictionary\n", + "\tsim.dump(net_folder)\n", + "\t# Get the simulation hash\n", + "\tsim_hash = sim.getHash()\n", "\n", - "# Create Simulation class\n", - "sim = Simulation(sim_params, net_dict)\n", - "# Extract the simulation dictionary\n", - "sim.dump(net_folder)\n", - "# Get the simulation hash\n", - "sim_hash = sim.getHash()\n", + "\t# Set output directory according to hashes\n", + "\t# and run the simulation\n", + "\tdata_path = os.path.join(outpath, net_hash, sim_hash)\n", + "\tsim.setup(data_path, num_threads)\n", + "\tsim.simulate()\n", "\n", - "# Set output directory according to hashes\n", - "# and run the simulation\n", - "data_path = os.path.join(outpath, net_hash, sim_hash)\n", - "sim.setup(data_path, num_threads)\n", - "sim.simulate()" + "\t# Save simulation hash to a file\n", + "\twith open(os.path.join(outpath, net_hash, 'sim_hash.txt'), 'w') as f:\n", + "\t\tf.write(sim_hash)" ] }, {