System Functions
clear_dir(path)
#
Deletes all files and subdirectories in the specified folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the folder to clear. |
required |
Source code in src/CompNeuroPy/system_functions.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
create_dir(path, print_info=False, clear=False)
#
Creates a directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the directory to create. |
required |
print_info |
bool
|
Whether to print information about the directory creation. Default: False. |
False
|
clear |
bool
|
Whether to clear the directory if it already exists. Default: False. |
False
|
Source code in src/CompNeuroPy/system_functions.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
save_variables(variable_list, name_list, path='./')
#
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_list |
list
|
variables to save |
required |
name_list |
list
|
names of the save files of the variables |
required |
path |
str or list
|
save path for all variables, or save path for each variable of the variable_list. Default: "./" |
'./'
|
Examples:
import numpy as np
from CompNeuroPy import save_variables, load_variables
### create variables
var1 = np.random.rand(10)
var2 = np.random.rand(10)
### save variables
save_variables([var1, var2], ["var1_file", "var2_file"], "my_variables_folder")
### load variables
loaded_variables = load_variables(["var1", "var2"], "my_variables_folder")
### use loaded variables
print(loaded_variables["var1_file"])
print(loaded_variables["var2_file"])
Source code in src/CompNeuroPy/system_functions.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
load_variables(name_list, path='./')
#
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_list |
list
|
names of the save files of the variables |
required |
path |
str or list
|
save path for all variables, or save path for each variable of the variable_list. Default: "./" |
'./'
|
Returns:
Name | Type | Description |
---|---|---|
variable_dict |
dict
|
dictionary with the loaded variables, keys are the names of the files, values are the loaded variables |
Examples:
import numpy as np
from CompNeuroPy import save_variables, load_variables
### create variables
var1 = np.random.rand(10)
var2 = np.random.rand(10)
### save variables
save_variables([var1, var2], ["var1_file", "var2_file"], "my_variables_folder")
### load variables
loaded_variables = load_variables(["var1", "var2"], "my_variables_folder")
### use loaded variables
print(loaded_variables["var1_file"])
print(loaded_variables["var2_file"])
Source code in src/CompNeuroPy/system_functions.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
timing_decorator(threshold=0.1)
#
Decorator to measure the execution time of a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
threshold |
float
|
Threshold in seconds. If the execution time of the function is larger than this threshold, the execution time is printed. Default: 0.1. |
0.1
|
Source code in src/CompNeuroPy/system_functions.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
run_script_parallel(script_path, n_jobs, args_list=[''], n_total=1)
#
Run a script in parallel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script_path |
str
|
Path to the script to run. |
required |
n_jobs |
int
|
Number of parallel jobs. |
required |
args_list |
list
|
List of lists containing the arguments (string values) of each run to pass to the script. Length of the list is the number of total runs. If a list of strings is passed these arguments are passed to the script and it is run n_total times. Default: [""], i.e. no arguments are passed to the script. |
['']
|
n_total |
int
|
Number of total runs, only used if args_list is not a list of lists. Default: 1. |
1
|
Source code in src/CompNeuroPy/system_functions.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
create_data_raw_folder(folder_name, **kwargs)
#
Create a folder for raw data of some kind of experiments/study etc. All data raw should be created by RUNNING A SINGLE PYTHON script. This data should be stored in the folder created here. If the created raw data depends on some parameters, these parameters should also be stored. They should be global in the corresponding python script to be able to easily set them again (replicate the data raw creation process). Best practice for the python script: define global parameters at the beginning, then call this function. This function stores the following information in a file called "data_raw_meta" in the created folder: - the name of the python script which created the data raw - the global variables of the python script given as kwargs - the conda environment - the pip requirements - the git log of ANNarchy and CompNeuroPy if they are installed locally
Warning
Only works in a conda environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_name |
str
|
Name of the folder to create. |
required |
**kwargs |
Any
|
Global variables of the caller script. |
{}
|
Examples:
from CompNeuroPy import create_data_raw_folder
### define global variables
var1 = 1
var2 = "test"
var3 = [1, 2, 3]
### call the function
create_data_raw_folder(
"my_data_raw_folder",
var1=var1,
var2=var2,
var3=var3,
)
Source code in src/CompNeuroPy/system_functions.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|