Skip to content
Snippets Groups Projects
Commit 09c0d4e3 authored by didihou's avatar didihou Committed by Administrator
Browse files

removed the print cell of python version

parent 49e27bbf
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:0bc96f39-b94f-40d5-be5c-a0d9ebdf8180 tags: %% Cell type:code id:0bc96f39-b94f-40d5-be5c-a0d9ebdf8180 tags:
``` python ``` python
import numpy as np import numpy as np
import os import os
import sys import sys
import json import json
sys.path.append('./figures/MAM2EBRAINS') sys.path.append('./figures/MAM2EBRAINS')
from multiarea_model import MultiAreaModel from multiarea_model import MultiAreaModel
from multiarea_model import Analysis from multiarea_model import Analysis
from M2E_compute_pop_rates import compute_pop_rates from M2E_compute_pop_rates import compute_pop_rates
base_path = os.path.abspath(".") base_path = os.path.abspath(".")
data_path = os.path.abspath("simulations") data_path = os.path.abspath("simulations")
``` ```
%% Cell type:code id:7d8e36f4-8918-456f-8324-c4fefd141848 tags:
``` python
import sys
print("Python version:", sys.version)
```
%% Cell type:code id:c907631c-4611-469a-941c-ddb31ef753c8 tags: %% Cell type:code id:c907631c-4611-469a-941c-ddb31ef753c8 tags:
``` python ``` python
# Set the threshold of matching rate of mean firing rate of all populations # Set the threshold of matching rate of mean firing rate of all populations
# if smaller than this value, raise error so that the test won't pass and something is wrong and needs to be checked manually # if smaller than this value, raise error so that the test won't pass and something is wrong and needs to be checked manually
match_rate_threshold = 0.95 match_rate_threshold = 0.95
``` ```
%% Cell type:code id:97fbab67-7282-4800-a6d4-78bb3a36640a tags: %% Cell type:code id:97fbab67-7282-4800-a6d4-78bb3a36640a tags:
``` python ``` python
""" """
Down-scaled model. Down-scaled model.
Neurons and indegrees are both scaled down to 10 %. Neurons and indegrees are both scaled down to 10 %.
Can usually be simulated on a local machine. Can usually be simulated on a local machine.
Warning: This will not yield reasonable dynamical results from the Warning: This will not yield reasonable dynamical results from the
network and is only meant to demonstrate the simulation workflow. network and is only meant to demonstrate the simulation workflow.
""" """
d = {} d = {}
conn_params = {'replace_non_simulated_areas': 'het_poisson_stat', conn_params = {'replace_non_simulated_areas': 'het_poisson_stat',
'cc_weights_factor': 1.9, # run model in Ground State 'cc_weights_factor': 1.9, # run model in Ground State
'cc_weights_I_factor': 2.0} 'cc_weights_I_factor': 2.0}
network_params = {'N_scaling': 0.006, network_params = {'N_scaling': 0.006,
'K_scaling': 0.006, 'K_scaling': 0.006,
'fullscale_rates': os.path.join(base_path, 'tests/fullscale_rates.json')} 'fullscale_rates': os.path.join(base_path, 'tests/fullscale_rates.json')}
sim_params = {'t_sim': 2000., sim_params = {'t_sim': 2000.,
'num_processes': 1, 'num_processes': 1,
'local_num_threads': 1} 'local_num_threads': 1}
M = MultiAreaModel(network_params, simulation=True, M = MultiAreaModel(network_params, simulation=True,
sim_spec=sim_params, sim_spec=sim_params,
theory=True) theory=True)
M.simulation.simulate() M.simulation.simulate()
``` ```
%% Cell type:code id:6730fe7b-e8bf-4aff-9497-bc614f44febd tags: %% Cell type:code id:6730fe7b-e8bf-4aff-9497-bc614f44febd tags:
``` python ``` python
# Create an instance of Analysis to load data # Create an instance of Analysis to load data
A = Analysis(M, M.simulation, data_list=['spikes'], load_areas=None) A = Analysis(M, M.simulation, data_list=['spikes'], load_areas=None)
``` ```
%% Cell type:code id:1c907303-d2ad-4f17-83df-8b0e21749a1d tags: %% Cell type:code id:1c907303-d2ad-4f17-83df-8b0e21749a1d tags:
``` python ``` python
# Create pop_rates, load stationary firing rates, and calculate mean firing rate for all populations # Create pop_rates, load stationary firing rates, and calculate mean firing rate for all populations
label = M.simulation.label label = M.simulation.label
complete_area_list = ['V1', 'V2', 'VP', 'V3', 'V3A', 'MT', 'V4t', 'V4', 'VOT', 'MSTd', complete_area_list = ['V1', 'V2', 'VP', 'V3', 'V3A', 'MT', 'V4t', 'V4', 'VOT', 'MSTd',
'PIP', 'PO', 'DP', 'MIP', 'MDP', 'VIP', 'LIP', 'PITv', 'PITd', 'PIP', 'PO', 'DP', 'MIP', 'MDP', 'VIP', 'LIP', 'PITv', 'PITd',
'MSTl', 'CITv', 'CITd', 'FEF', 'TF', 'AITv', 'FST', '7a', 'STPp', 'MSTl', 'CITv', 'CITd', 'FEF', 'TF', 'AITv', 'FST', '7a', 'STPp',
'STPa', '46', 'AITd', 'TH'] 'STPa', '46', 'AITd', 'TH']
area_list = complete_area_list area_list = complete_area_list
compute_pop_rates(M, data_path, label) # Compute pop_rates compute_pop_rates(M, data_path, label) # Compute pop_rates
fn = os.path.join(data_path, label, 'Analysis', 'pop_rates.json') # Load stationary firing rates fn = os.path.join(data_path, label, 'Analysis', 'pop_rates.json') # Load stationary firing rates
with open(fn, 'r') as f: with open(fn, 'r') as f:
pop_rates = json.load(f) pop_rates = json.load(f)
# Process spike data and calculate mean firing rate for all populations, save them in a dict # Process spike data and calculate mean firing rate for all populations, save them in a dict
rates = np.zeros((len(area_list), 8)) rates = np.zeros((len(area_list), 8))
for i, area in enumerate(area_list): for i, area in enumerate(area_list):
for j, pop in enumerate(M.structure[area][::-1]): for j, pop in enumerate(M.structure[area][::-1]):
rate = pop_rates[area][pop] rate = pop_rates[area][pop]
if rate == 0.0: if rate == 0.0:
rate = 1e-5 rate = 1e-5
if area == 'TH' and j > 3: # To account for missing layer 4 in TH if area == 'TH' and j > 3: # To account for missing layer 4 in TH
rates[i][j + 2] = rate rates[i][j + 2] = rate
else: else:
rates[i][j] = rate rates[i][j] = rate
rates = np.transpose(rates) rates = np.transpose(rates)
rates = np.array(rates) rates = np.array(rates)
``` ```
%% Cell type:code id:34d46019-38f2-4b5d-af09-575906b1d4d2 tags: %% Cell type:code id:34d46019-38f2-4b5d-af09-575906b1d4d2 tags:
``` python ``` python
# Compare the calculated mean firing rate with the reference values saved in M2E_reference_MFRs.json and calculate the percentage of matching # Compare the calculated mean firing rate with the reference values saved in M2E_reference_MFRs.json and calculate the percentage of matching
# Load the array # Load the array
pop_rates_ref = np.load('M2E_pop_rates_ref.npy') pop_rates_ref = np.load('M2E_pop_rates_ref.npy')
# Count the percentage of cells that values match (the same) # Count the percentage of cells that values match (the same)
comparison_result = pop_rates_ref == rates comparison_result = pop_rates_ref == rates
# print(comparison_result) # print(comparison_result)
same_cells = np.sum(comparison_result) same_cells = np.sum(comparison_result)
# print(same_cells) # print(same_cells)
total_cells = np.prod(pop_rates_ref.shape) total_cells = np.prod(pop_rates_ref.shape)
# print(total_cells) # print(total_cells)
match_rate = same_cells / total_cells match_rate = same_cells / total_cells
# print(match_rate) # print(match_rate)
# Judge if the matching rate is lower than threshold set and raise error if yes # Judge if the matching rate is lower than threshold set and raise error if yes
if match_rate < match_rate_threshold: if match_rate < match_rate_threshold:
raise TestError("Mismatch of mean firing rates over populations between the latest simulation and saved reference values, there may be problems of recent updates of dependencies, please take a check!") raise TestError("Mismatch of mean firing rates over populations between the latest simulation and saved reference values, there may be problems of recent updates of dependencies, please take a check!")
``` ```
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment