-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
59 lines (46 loc) · 1.71 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
# @Author: Theo Lemaire
# @Email: theo.lemaire@epfl.ch
# @Date: 2018-10-01 20:45:29
# @Last Modified by: Theo Lemaire
# @Last Modified time: 2020-04-29 13:48:58
''' Utilities used across notebooks. '''
import os
import matplotlib
from PySONIC.utils import si_format
from root import dataroot
# Matplotlib parameters
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
matplotlib.rcParams['font.family'] = 'arial'
def subdirectory(name):
''' Return (and create if needed) a data sub-directory. '''
if dataroot is None:
raise ValueError('You must specify the data root directory')
if not os.path.isdir(dataroot):
raise ValueError('You must create the data root directory prior to running the code')
subdir = os.path.join(dataroot, name)
if not os.path.isdir(subdir):
os.mkdir(subdir)
return subdir
def codes(a, pneuron, Fdrive, PRF, tstim):
''' Return codes dictionary for a combination of parameters. '''
return [
pneuron.name,
f'{si_format(a, space="")}m',
f'{si_format(Fdrive, space="")}Hz',
f'PRF{si_format(PRF, space="")}Hz',
f'{si_format(tstim, space="")}s'
]
def saveFigsAsPDF(figs, figindex):
''' Save figures as PDFs with a specific figure index. '''
figdir = subdirectory('figs')
figbase = f'fig{figindex:02}'
for fname, fig in figs.items():
fig.savefig(os.path.join(figdir, f'{figbase}{fname}.pdf'), transparent=True)
def subthr(x):
''' Sub-threshold acoustic pressure (Pa). '''
return x - 5e3
def suprathr(x):
''' Supra-threshold acoustic pressure (Pa). '''
return x + 20e3