Skip to content

Commit 23b6220

Browse files
committed
refactor converter defintions
1 parent 366fd45 commit 23b6220

File tree

1 file changed

+65
-67
lines changed

1 file changed

+65
-67
lines changed

specparam/convert/definitions.py

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
###################################################################################################
1515
## APERIODIC PARAMETER CONVERTERS
1616

17-
# Null converter for aperiodic parameters
17+
## AP - Null converter
1818
ap_null = AperiodicParamConverter(
1919
parameter=None,
2020
name='ap_null',
@@ -26,7 +26,7 @@
2626
###################################################################################################
2727
## PERIODIC PARAMETER CONVERTERS
2828

29-
# Null converter for periodic parameters
29+
## PE - Null converter
3030
pe_null = PeriodicParamConverter(
3131
parameter=None,
3232
name='pe_null',
@@ -35,89 +35,87 @@
3535
model.results.params.periodic._fit[peak_ind, model.modes.periodic.params.indices[param]]
3636
)
3737

38+
## PE - PW
39+
40+
pw_log_sub = PeriodicParamConverter(
41+
parameter='pw',
42+
name='log_sub',
43+
description='Convert peak height to be the log subtraction '\
44+
'of full model and aperiodic component.',
45+
function=lambda param, model, peak_ind : \
46+
compute_peak_height(model, peak_ind, 'log', 'subtract'),
47+
)
48+
49+
pw_log_div = PeriodicParamConverter(
50+
parameter='pw',
51+
name='log_div',
52+
description='Convert peak height to be the log division '\
53+
'of full model and aperiodic component.',
54+
function=lambda param, model, peak_ind : \
55+
compute_peak_height(model, peak_ind, 'log', 'divide'),
56+
)
57+
58+
pw_lin_sub = PeriodicParamConverter(
59+
parameter='pw',
60+
name='lin_sub',
61+
description='Convert peak height to be the linear subtraction '\
62+
'of full model and aperiodic component.',
63+
function=lambda param, model, peak_ind : \
64+
compute_peak_height(model, peak_ind, 'linear', 'subtract'),
65+
)
66+
67+
pw_lin_div = PeriodicParamConverter(
68+
parameter='pw',
69+
name='lin_div',
70+
description='Convert peak height to be the linear division '\
71+
'of full model and aperiodic component.',
72+
function=lambda param, model, peak_ind : \
73+
compute_peak_height(model, peak_ind, 'linear', 'divide'),
74+
)
75+
76+
## PE - BW
77+
78+
bw_full_width = PeriodicParamConverter(
79+
parameter='bw',
80+
name='full_width',
81+
description='Convert peak bandwidth to be the full, '\
82+
'two-sided bandwidth of the peak.',
83+
function=lambda param, model, peak_ind : \
84+
2 * model.results.params.periodic._fit[\
85+
peak_ind, model.modes.periodic.params.indices['bw']]
86+
)
87+
3888
###################################################################################################
39-
## PRE-DEFINED CONVERTERS
89+
## COLLECT ALL CONVERTERS
4090

91+
# Null converters: extract the fit parameter, with no conversion applied
92+
NULL_CONVERTERS = {
93+
'aperiodic' : ap_null,
94+
'periodic' : pe_null,
95+
}
96+
97+
# Collect converters by component & by paramter
4198
CONVERTERS = {
4299

43100
'aperiodic' : {
44-
45101
'offset' : {},
46-
47102
'exponent' : {},
48-
49103
},
50104

51105
'periodic' : {
52-
53106
'cf' : {},
54-
55107
'pw' : {
56-
57-
'log_sub' : PeriodicParamConverter(
58-
parameter='pw',
59-
name='log_sub',
60-
description='Convert peak height to be the log subtraction '\
61-
'of full model and aperiodic component.',
62-
function=lambda param, model, peak_ind : \
63-
compute_peak_height(model, peak_ind, 'log', 'subtract'),
64-
),
65-
66-
'log_div' : PeriodicParamConverter(
67-
parameter='pw',
68-
name='log_div',
69-
description='Convert peak height to be the log division '\
70-
'of full model and aperiodic component.',
71-
function=lambda param, model, peak_ind : \
72-
compute_peak_height(model, peak_ind, 'log', 'divide'),
73-
),
74-
75-
'lin_sub' : PeriodicParamConverter(
76-
parameter='pw',
77-
name='lin_sub',
78-
description='Convert peak height to be the linear subtraction '\
79-
'of full model and aperiodic component.',
80-
function=lambda param, model, peak_ind : \
81-
compute_peak_height(model, peak_ind, 'linear', 'subtract'),
82-
83-
),
84-
85-
'lin_div' : PeriodicParamConverter(
86-
parameter='pw',
87-
name='lin_div',
88-
description='Convert peak height to be the linear division '\
89-
'of full model and aperiodic component.',
90-
function=lambda param, model, peak_ind : \
91-
compute_peak_height(model, peak_ind, 'linear', 'divide'),
92-
),
93-
108+
'log_sub' : pw_log_sub,
109+
'log_div' : pw_log_div,
110+
'lin_sub' : pw_lin_sub,
111+
'lin_div' : pw_lin_div,
94112
},
95-
96113
'bw' : {
97-
98-
'full_width' : PeriodicParamConverter(
99-
parameter='bw',
100-
name='full_width',
101-
description='Convert peak bandwidth to be the full, '\
102-
'two-sided bandwidth of the peak.',
103-
function=lambda param, model, peak_ind : \
104-
2 * model.results.params.periodic._fit[\
105-
peak_ind, model.modes.periodic.params.indices['bw']]
106-
),
107-
114+
'full_width' : bw_full_width,
108115
},
109116
}
110117
}
111118

112-
###################################################################################################
113-
## COLLECT ALL CONVERTERS
114-
115-
# Null converters: extract the fit parameter, with no conversion applied
116-
NULL_CONVERTERS = {
117-
'aperiodic' : ap_null,
118-
'periodic' : pe_null,
119-
}
120-
121119
###################################################################################################
122120
## SELECTOR & CHECKER FUNCTIONS
123121

0 commit comments

Comments
 (0)