Skip to content

Commit f67458e

Browse files
committed
provide non-zero, non-crazy initial values for pre-peak peak models
1 parent c102ea6 commit f67458e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

larch/wxxas/prepeak_panel.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,12 @@ def addModel(self, event=None, model=None, prefix=None, isbkg=False, opts=None):
11301130
self.models_other.SetSelection(0)
11311131

11321132
mod_abbrev = get_model_abbrev(model)
1133+
1134+
opts = self.read_form()
1135+
dgroup = self.controller.get_group()
1136+
has_data = getattr(dgroup, 'yplot', None) is not None
1137+
is_peakmodel = model in ModelChoices['peaks']
1138+
11331139
if prefix is None:
11341140
curmodels = ["%s%i_" % (mod_abbrev, i+1) for i in range(1+len(self.fit_components))]
11351141
for comp in self.fit_components:
@@ -1205,9 +1211,12 @@ def SLabel(label, size=(80, -1), **kws):
12051211
SLabel(" Min", size=(60, -1)),
12061212
SLabel(" Max", size=(60, -1)), SLabel(" Expression")))
12071213

1214+
if has_data:
1215+
xdata = getattr(dgroup, 'xplot', np.arange(2))
1216+
ydata = getattr(dgroup, 'yplot', np.arange(2))
1217+
12081218
parwids = {}
12091219
parnames = sorted(minst.param_names)
1210-
12111220
for a in minst._func_allargs:
12121221
pname = "%s%s" % (prefix, a)
12131222
if (pname not in parnames and
@@ -1218,14 +1227,27 @@ def SLabel(label, size=(80, -1), **kws):
12181227
for pname in parnames:
12191228
sname = pname[len(prefix):]
12201229
hints = minst.param_hints.get(sname, {})
1230+
value = 0.0
1231+
if is_peakmodel and 'sigma' in pname:
1232+
value = 1.0
1233+
if has_data:
1234+
value = max(0.5, 0.1*(opts['ehi'] - opts['elo']))
1235+
elif is_peakmodel and 'center' in pname:
1236+
value = 1.0
1237+
if has_data:
1238+
value = int((opts['ehi'] + opts['elo'])/2.0)
1239+
elif is_peakmodel and 'ampl' in pname:
1240+
value = 1.0
1241+
if has_data:
1242+
value = ydata.ptp()
1243+
if 'value' in hints:
1244+
value = hints['value']
12211245

1222-
par = Parameter(name=pname, value=0, vary=True)
1246+
par = Parameter(name=pname, value=value, vary=True)
12231247
if 'min' in hints:
12241248
par.min = hints['min']
12251249
if 'max' in hints:
12261250
par.max = hints['max']
1227-
if 'value' in hints:
1228-
par.value = hints['value']
12291251
if 'expr' in hints:
12301252
par.expr = hints['expr']
12311253

0 commit comments

Comments
 (0)