utils

helpers

Here are some simple Numpy functions or torch functions that help to achieve simulation or assimilation.

utils.helpers.load_if_exist(func, *args, **kwargs)[source]

Load npy if exist else generate it by func.

utils.helpers.np_move_avg(a, n=10, mode='valid')[source]

Calculate the moving average of the signal

Parameters:
  • a (ndarray) – 1-dim or 2-dim ndarray, like (time_dim, variable_dim)

  • n (int) – window lenght

  • mode (str) – the options in np.convolve.

utils.helpers.str2bool(v)[source]
utils.helpers.torch_2_numpy(u, is_cuda=True)[source]

Convert torch.Tensor to numpy.ndarray in cpu memory.

pretty_print

utils.pretty_print.pretty_print(content: str)[source]

pretty print something inside a box.

Parameters:

content (str) – the information to print.

Examples

>>> pretty_print("Initialization")
utils.pretty_print.table_print(content: dict, n_rows=None)[source]

display something inside a table.

Parameters:
  • content (dict) – key-value represent the variable name and variable value.

  • n_rows (int) –

  • n_columns (int) –

sample

utils.sample.sample(aal_region, neurons_per_population_base, populations_id, specified_info=None, num_sample_voxel_per_region=1, num_neurons_per_voxel=300)[source]

sample neurons from the simulation object according requirement.

In simulation object simulation, it’s required to set neuron sample before simulation.run.

Parameters:
  • aal_region (ndarrau) – indicate the brain regions label of each voxel.

  • neurons_per_population_base (ndarray) – The accumulated number of neurons for each population , corresponding to the population_id.

  • populations_id (ndarray) – The population id. Due to the routing algorithm, the population id may be disordered and repeated. The population id of neurons distributed between consecutive cards may be duplicated, because the neurons of this population may not be completely divided into one card.

  • num_sample_voxel_per_region (int, default=1) – the sample number of voxels in each region.

  • num_neurons_per_voxel (int, default=300) – the sample number of neurons in each voxel .

  • specified_info (ndarray) – according the specified_info info , we can randomly sample neurons which are from given voxel id.

Returns:

  • ndarray which contain sample information

  • —————-|——————

  • 0 th column | neuron id

  • 1 th column | voxel id

  • 2 th column | population id

  • 3 th column | region id

  • —————-|——————

utils.sample.specified_sample_column(aal_region, neurons_per_population_base, specified_info=None, num_sample_voxel_per_region=1, num_neurons_per_voxel=300)[source]

more convenient version to sample neurons for simulation object.

neurons_per_population_base is read from population_base.npy which is generated during generation of connection table.

Parameters:
  • aal_region (ndarrau) – indicate the brain regions label of each voxel.

  • neurons_per_population_base (ndarray) – The accumulated number of neurons for each population , corresponding to the population_id. corresponding to [0, 1, 2, 3, 4,… 227029]

  • num_sample_voxel_per_region (int, default=1) – the sample number of voxels in each region.

  • num_neurons_per_voxel (int, default=300) – the sample number of neurons in each voxel .

  • specified_info (ndarray) – according the specified_info info , we can randomly sample neurons which are from given voxel id.

Returns:

  • ndarray which contain sample information

  • —————-|——————

  • 0 th column | neuron id

  • 1 th column | voxel id

  • 2 th column | population id

  • 3 th column | region id

  • —————-|——————

utils.sample.specified_sample_voxel(aal_region, neurons_per_population_base, specified_info=None, num_sample_voxel_per_region=1, num_neurons_per_voxel=300)[source]