/
helpers.py
58 lines (43 loc) · 1.16 KB
/
helpers.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
"""
Helper functions for lineshape fitting.
"""
# bound functions
def delta(v, d):
"""
Limits of v +/- d for array v and d.
"""
return zip(v - d, v + d)
def limit(vmin, vmax, npeaks):
"""
Fixed limits, vmin to vmax for all peaks.
"""
return [(vmin, vmax)] * npeaks
def scale_params(rec, prefix, first, last):
"""
scale lineshape parameters in rec with name prefixX with X from from
first to last (inclusive)
"""
return [rec[prefix + str(z)] for z in range(first, last + 1)]
def no_limits(nparams, npeaks):
"""
No limits on nparameters for npeaks.
"""
return [[(None, None)] * npeaks] * nparams
def no_limits_amp(npeaks):
"""
No amplitude limits for npeaks
"""
return [(None, None)] * npeaks
# misc
def super_zip(l):
"""
Zip a list after zipping each element.
Useful for lineshape parameter and bounds.
"""
return zip(*[zip(*i) for i in l])
def scale_columns(prefix, first, last):
"""
Create a list of scale parameter column names with name prefixX with X
from first to last (inclusive)
"""
return [prefix + str(i) for i in range(first, last + 1)]