Repository navigation
Expand file tree
/
Copy pathfitwindow.pro
More file actions
294 lines (274 loc) · 12.9 KB
/
Copy pathfitwindow.pro
File metadata and controls
294 lines (274 loc) · 12.9 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
133
134
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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
251
252
253
254
255
256
257
258
259
260
261
262
263
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
; *******************************************************************
; Multfit efficient processing of 2D diffraction images
; Copyright (C) 2000-2014 S. Merkel, Universite Lille 1
; http://merkel.zoneo.net/Multifit/
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
;
; *******************************************************************
; ********************************* PLOTITFUNCTION ***************
PRO fitit_event, ev
WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
; resize event?
if (ev.id eq ev.top) then begin
; resize the plot
widget_control, stash.draw, draw_xsize=ev.x, draw_ysize=ev.y
endif
END
PRO fitit, stash
common rawdata, nalpha, ntheta, alpha, twotheta, data
common fitit, def, base, draw
common fitoptions, basescale, smallDetection, nLoop, startSmall, endSmall, ignoreratio
; Get list of spectra to fit
tofit = WIDGET_INFO(stash.listID, /LIST_SELECT)
if (tofit(0) eq -1) then begin
tmp = DIALOG_MESSAGE('Select at least one spectrum!', /ERROR)
return
endif
; Parsing fit options
WIDGET_CONTROL, stash.npeaksVa, GET_VALUE=npeaks
ntofit = fix(npeaks[0])
WIDGET_CONTROL, stash.restrictregionVa, GET_VALUE=restricregion
basescale = float(restricregion[0])
WIDGET_CONTROL, stash.smallPeakVa, GET_VALUE=smallpeak
smallDetection = float(smallpeak[0])
WIDGET_CONTROL, stash.loopsVa, GET_VALUE=nnloops
nLoop = fix(nnloops[0])
WIDGET_CONTROL, stash.loopsSStartVa, GET_VALUE=nnloops
startSmall = fix(nnloops[0])
WIDGET_CONTROL, stash.loopsSEndVa, GET_VALUE=nnloops
endSmall = fix(nnloops[0])
if (WIDGET_INFO(stash.gauss, /BUTTON_SET) eq 1) then begin
profile = 0
endif else if (WIDGET_INFO(stash.voigt, /BUTTON_SET) eq 1) then begin
profile = 1
endif else begin
profile = 2
endelse
if (WIDGET_INFO(stash.halfwidthBut, /BUTTON_SET) eq 1) then halfwidth = 1 else halfwidth = 0
; Parsing interrupt options
if (WIDGET_INFO(stash.negIntensity, /BUTTON_SET) eq 1) then stopNegIntensity = 1 else stopNegIntensity = 0
if (WIDGET_INFO(stash.tooWide, /BUTTON_SET) eq 1) then stopTooWide = 1 else stopTooWide = 0
if (WIDGET_INFO(stash.intensityChge, /BUTTON_SET) eq 1) then stopIntensityChge = 1 else stopIntensityChge = 0
if (WIDGET_INFO(stash.badData, /BUTTON_SET) eq 1) then testBadData = 1 else testBadData = 0
; Parsing options regarding 2 theta restrictions
twothetarestriction = 0
minTwoTheta = min(twotheta)
maxTwoTheta = max(twotheta)
if ((WIDGET_INFO(stash.twothetarestriction, /BUTTON_SET) eq 1)) then begin
twothetarestriction = 1
WIDGET_CONTROL, stash.minTwoThetaVa, GET_VALUE=value
minTwoTheta = float(value[0])
WIDGET_CONTROL, stash.maxTwoThetaVa, GET_VALUE=value
maxTwoTheta = float(value[0])
endif
; create plot window if necessary
if (def ne 1) then begin
base = WIDGET_BASE(Title='Fits',/TLB_SIZE_EVENTS, GROUP_LEADER=stash.base)
draw = WIDGET_DRAW(base, RETAIN=2, XSIZE=600, YSIZE=700)
stashnew = {base:base, draw:draw, stash:stash}
WIDGET_CONTROL, base, SET_UVALUE=stashnew
WIDGET_CONTROL, base, /REALIZE
XMANAGER, 'fitit', base
def = 1
endif
if (WIDGET_INFO(draw, /VALID_ID) ne 1) then begin
base = WIDGET_BASE(Title='Fits',/TLB_SIZE_EVENTS, GROUP_LEADER=stash.base)
draw = WIDGET_DRAW(base, RETAIN=2, XSIZE=600, YSIZE=700)
stashnew = {base:base, draw:draw, stash:stash}
WIDGET_CONTROL, base, SET_UVALUE=stashnew
WIDGET_CONTROL, base, /REALIZE
XMANAGER, 'fitit', base
def = 1
endif
WIDGET_CONTROL, draw, GET_VALUE = index
WSET, index
; Call fitting routine
fitnpeaks, ntofit, tofit, profile, halfwidth, stopNegIntensity, stopTooWide, stopIntensityChge, testBadData, twothetarestriction, minTwoTheta, maxTwoTheta, /AUTOMATIC, /AUTOCHECK, /SIDEBG
END
; ****************************************** MAIN FIT WINDOW GUI ***************
; Resize fit window,
; in fact, only resize the bottom-left part of the option window, the rest is done automatically
; just need to force the size of the list at the end
PRO resizefitwindow, base, stash
widget_control, base, TLB_GET_SIZE=size
; resizing top in x
; widget_control, stash.titleLa, xsize=size[0]
; Resizing middle of the window in y, leave space for top and bottom
tmpsize = widget_info(stash.titleLa, /GEOMETRY)
tmpsize2 = widget_info(stash.butBase, /GEOMETRY)
ysize = size[1]-(tmpsize2.SCR_YSIZE + (2*tmpsize2.MARGIN))-(tmpsize.SCR_YSIZE + (2*tmpsize.MARGIN))
; print, "Y size for middlde container becomes", ysize
; widget_control, stash.listBase, ysize=ysize
; Resizing the right part of middle container in x
tmpsize = widget_info(stash.listBase, /GEOMETRY)
xsize = size[0]-(tmpsize.SCR_XSIZE + (2*tmpsize.MARGIN))
tmpsize = widget_info(stash.dataBase, /GEOMETRY)
xsize -= (tmpsize.SCR_XSIZE + (2*tmpsize.MARGIN))
; widget_control, stash.allOptions, xsize=xsize, ysize=ysize
tmpsize = widget_info(stash.optTricks, /GEOMETRY)
ysize2 = ysize-(tmpsize.SCR_YSIZE + (2*tmpsize.MARGIN))
tmpsize = widget_info(stash.optBase, /GEOMETRY)
ysize2 -= (tmpsize.SCR_YSIZE + (2*tmpsize.MARGIN))
widget_control, stash.interrupt, xsize=xsize, ysize=ysize2, UPDATE=0
; resizing button bar in x
; widget_control, stash.butBase, xsize=size[0]
; Resizing list height
tmpsize = widget_info(stash.listBase, /GEOMETRY)
tmpsize2 = widget_info(stash.listID, /GEOMETRY)
ysize = ysize-2*tmpsize2.MARGIN-2*tmpsize.YPAD
widget_control, stash.listID, SCR_YSIZE=ysize, /UPDATE
end
; Process events generated in the window
PRO fitWindow_event, ev
WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
CASE ev.id OF
;stash.base: resizefitwindow, stash.base, stash
else: begin
CASE uval OF
'FIT': fitit, stash
'EXIT': WIDGET_CONTROL, ev.TOP, /DESTROY
else:
ENDCASE
ENDCASE
endcase
END
; Create fit window
PRO fitWindow, parent
common datainfo, filenames, alphastart, alphaend, intervalle, date
common rawdata, nalpha, ntheta, alpha, twotheta, data
common fitit, def, base, draw
common fonts, titlefont, boldfont, mainfont, avFontHeight
; force creation of a new plot window
def = 0
; base GUI
base = WIDGET_BASE(Title='Multipeak fit window',/COLUMN, GROUP_LEADER=parent, /TLB_SIZE_EVENTS)
titleLa = WIDGET_LABEL(base, VALUE='Multipeak fitting functions', font=titlefont)
; top container
top = WIDGET_BASE(base,/ROW)
; display default parameters
dataBase = WIDGET_BASE(top,/COLUMN, FRAME=1)
alphaminLabel = 'Min azimuth: ' + STRTRIM(STRING(alphastart,/PRINT),1)
alphaminLa = WIDGET_LABEL(dataBase, VALUE=alphaminLabel, /ALIGN_LEFT)
alphamaxLabel = 'Max azimuth: ' + STRTRIM(STRING(alphaend,/PRINT),1)
alphamaxLa = WIDGET_LABEL(dataBase, VALUE=alphamaxLabel, /ALIGN_LEFT)
intervalLabel = 'Interval: ' + STRTRIM(STRING(intervalle,/PRINT),1)
intervalLa = WIDGET_LABEL(dataBase, VALUE=intervalLabel, /ALIGN_LEFT)
; list of delta values
listBase = WIDGET_BASE(top,/COLUMN, FRAME=1)
alphaText = strarr(nalpha)
alphaU = intarr(nalpha)
for i=0, nalpha[0]-1 do begin
alphaText(i) = 'Az = ' + STRTRIM(STRING(alpha(i),/PRINT))
alphaU(i) = i
endfor
listID = Widget_List(listBase, VALUE=alphaText, UVALUE='LISTDELTA', /MULTIPLE)
; *************** Fit options
allOptions = WIDGET_BASE(top,/COLUMN,XPAD=0,YPAD=0)
; *************** Options de base
optBase = WIDGET_BASE(allOptions,/COLUMN, FRAME=1)
; number of peaks
npeaksBase = WIDGET_BASE(optBase,/ROW)
npeaksCh = Widget_Base(npeaksBase, /NonExclusive)
npeaksLa = Widget_Label(npeaksBase, Value='Number of peaks')
npeaksVa = WIDGET_TEXT(npeaksBase, VALUE='1',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; peak profile
profileLa = WIDGET_LABEL(optBase, VALUE='Peak profile', /ALIGN_LEFT)
peakprofile = Widget_Base(optBase, Column=1, /Exclusive)
gauss = Widget_Button(peakprofile, Value='Gauss', UVALUE='PROFILE')
voigt = Widget_Button(peakprofile, Value='Pseudo-Voigt', UVALUE='PROFILE')
lorentz = Widget_Button(peakprofile, Value='Lorentz', UVALUE='PROFILE')
Widget_Control, voigt, Set_Button=1
; Save half-width
halfwidthBase = Widget_Base(optBase, /NonExclusive)
halfwidthBut = Widget_Button(halfwidthBase, Value='Save half-width', UVALUE='H-WIDTH')
Widget_Control, halfwidthBut, Set_Button=1
; *************** optimisation
; Ad-hoc parameters
optTricks = WIDGET_BASE(allOptions,/COLUMN, FRAME=1)
adhocLa = Widget_Label(optTricks, Value='Options that control the quality of the fit')
; scaling for base
restrictregionBase = WIDGET_BASE(optTricks,/ROW)
restrictregionLa = Widget_Label(restrictregionBase, Value='Base restriction factor')
restrictregionVa = WIDGET_TEXT(restrictregionBase, VALUE='5.0',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; what is a small peak?
; smallPeakBase = WIDGET_BASE(optTricks,/ROW)
smallPeakLa = Widget_Label(restrictregionBase, Value='Small peak detection factor')
smallPeakVa = WIDGET_TEXT(restrictregionBase, VALUE='10.0',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; loops
loopsBase = WIDGET_BASE(optTricks,/ROW)
loopsLa = Widget_Label(loopsBase , Value='Number of loops')
loopsVa = WIDGET_TEXT(loopsBase , VALUE='10',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; loopsSmallBase = WIDGET_BASE(optTricks,/ROW)
loopsSmallLa = Widget_Label(loopsBase, Value='Fit small peaks between loop')
loopsSStartVa = WIDGET_TEXT(loopsBase, VALUE='3',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
loopsSmallLa2 = Widget_Label(loopsBase, Value='and')
loopsSEndVa = WIDGET_TEXT(loopsBase, VALUE='7',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; *************** Restrict 2theta range
restricrange = WIDGET_BASE(allOptions,/COLUMN, FRAME=1)
interruptBase = Widget_Base(restricrange, /NonExclusive,/ROW)
twothetarestriction = Widget_Button(interruptBase, Value='Fixed two theta range', UVALUE='')
Widget_Control, twothetarestriction, Set_Button=0
rangeBase = WIDGET_BASE(restricrange,/ROW)
la = Widget_Label(rangeBase, Value='Min 2theta')
minTwoThetaVa = WIDGET_TEXT(rangeBase, VALUE='10',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
la = Widget_Label(rangeBase , Value='Max 2theta')
maxTwoThetaVa = WIDGET_TEXT(rangeBase, VALUE='20',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; *************** Stop
interrupt2 = WIDGET_BASE(allOptions,/ROW, FRAME=1)
interrupt = WIDGET_BASE(interrupt2,/COLUMN)
adhocLa = Widget_Label(interrupt, Value='Interrupt automatic fitting when')
interruptBase = Widget_Base(interrupt, /NonExclusive)
negIntensity = Widget_Button(interruptBase, Value='Negative intensity peak', UVALUE='')
Widget_Control, negIntensity, Set_Button=1
tooWide = Widget_Button(interruptBase, Value='Large change in half-width', UVALUE='')
Widget_Control, tooWide, Set_Button=1
intensityChge = Widget_Button(interruptBase, Value='Large change in intensity', UVALUE='')
Widget_Control, intensityChge, Set_Button=1
interrupt3 = WIDGET_BASE(interrupt2,/COLUMN)
adhocLa = Widget_Label(interrupt3, Value='Test for')
interruptBase2 = Widget_Base(interrupt3, /NonExclusive)
badData = Widget_Button(interruptBase2, Value='Bad data', UVALUE='')
Widget_Control, badData, Set_Button=1
; *************** ACTION BUTTONS
butBase = WIDGET_BASE(base,/ROW, /ALIGN_CENTER)
plotBut = WIDGET_BUTTON(butBase, VALUE='Fit', UVALUE='FIT',xsize=80)
closeBut = WIDGET_BUTTON(butBase, VALUE='Close', UVALUE='EXIT',xsize=80)
; Create an anonymous structure to hold widget IDs
stash = {base:base, titleLa:titleLa, top:top, butBase:butBase, dataBase: dataBase, listBase:listBase, allOptions:allOptions, optBase:optBase, optTricks: optTricks, interrupt:interrupt, $
listID: listID, npeaksVa:npeaksVa, $
gauss:gauss, voigt:voigt, lorentz:lorentz, halfwidthBut:halfwidthBut,$
restrictregionVa: restrictregionVa, smallPeakVa:smallPeakVa, loopsVa:loopsVa, $
loopsSStartVa:loopsSStartVa, loopsSEndVa:loopsSEndVa, $
negIntensity:negIntensity, tooWide:tooWide, intensityChge:intensityChge, $
badData: badData, $
twothetarestriction:twothetarestriction, minTwoThetaVa:minTwoThetaVa, maxTwoThetaVa:maxTwoThetaVa}
WIDGET_CONTROL, base, SET_UVALUE=stash
WIDGET_CONTROL, base, /REALIZE
; forcing a resize event
; resizefitwindow, base, stash
;
; Resizing list height
widget_control, base, TLB_GET_SIZE=size
tmpsize = widget_info(stash.titleLa, /GEOMETRY)
tmpsize2 = widget_info(stash.butBase, /GEOMETRY)
ysize = size[1]-(tmpsize2.SCR_YSIZE + (2*tmpsize2.MARGIN))-(tmpsize.SCR_YSIZE + (2*tmpsize.MARGIN))
tmpsize = widget_info(stash.listBase, /GEOMETRY)
tmpsize2 = widget_info(stash.listID, /GEOMETRY)
ysize = ysize-2*tmpsize2.MARGIN-2*tmpsize.YPAD
widget_control, stash.listID, SCR_YSIZE=ysize, /UPDATE
XMANAGER, 'fitWindow', base
END