File: test_syntax.fit

package info (click to toggle)
fityk 1.3.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 3,784 kB
  • sloc: cpp: 34,396; ansic: 4,673; python: 971; makefile: 366; sh: 117; java: 31; ruby: 27; perl: 25; xml: 16
file content (294 lines) | stat: -rw-r--r-- 7,236 bytes parent folder | download | duplicates (2)
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
# Fityk 1.2.1

### syntax testing
### this script doesn't assume location of any other files (ie. no data files
### are read, and produces only file in current directory, which start with
### `tmp_' prefix, eg. tmp_foo.xy


# first set some options useful for testing

set on_error = exit
set autoplot = 0
set pseudo_random_seed = 174924
set verbosity = 1


# ... and then issue as many commands as possible, checking for sytax errors

# predefined data transformations
M=500
x=n/100
M=500; x=n/100; y=sin(x); s=1
Y = Y[n-1] + y[n];S = sqrt(max2(1,y))
Y = (y[n+1]-y[n])/(x[n+1]-x[n]);X = (x[n+1]+x[n])/2
M=M-1;S = sqrt(max2(1,y))
S = s / sum(n > 0 ? (x[n] - x[n-1]) * (y[n-1] + y[n])/2 : 0);
Y = y / sum(n > 0 ? (x[n] - x[n-1]) * (y[n-1] + y[n])/2 : 0)
X = n<M-1?(x[n]+x[n+1])/2:x;Y = y[n]+y[n+1];
S = sqrt(s[n]^2+s[n+1]^2); delete(mod(n,2)==1)
Y=max2(y,0)
delete(not a)
Y=x , X=y , S=sqrt(max2(1,Y))
Y=-y
a=true
X = 4*pi * sin(x/2*pi/180) / 1.54051
X = asin(x/(4*pi)*1.54051) * 2*180/pi
X = x[0] + n * (x[M-1]-x[0]) / (M-1),  Y = y[index(X)], S = s[index(X)], A = a[index(X)]
del @0

@0: title = 'Title X'
@+ = 0
@1: title = TitleY
@1: M = 400
@1: X=n/M*3*pi
@1: Y=sin(x)
@1: plot
sleep 0.3
@0: M = 800
@0: X = 10 + n/M*90
delete @1
Y = 30
Y = y + 3000 * exp(-((x-21.2)/0.3)^2) # Gaussian
Y = y + 2450 / (1 + ((x-41.4)/0.3)^2) #Lorentzian
$height=1901; $center=75.313; $hwhm=0.5; $shape=2.4
Y = y + $height/(1+((x-$center)/$hwhm)^2*(2^(1/$shape)-1))^$shape #Pearson VII
S = sqrt(max2(1, y))
Y = randnormal(y, s)  #noise
@0: plot
sleep 0.3

guess %p = Lorentzian(center=~75)
@0: plot
sleep 0.2
del %p
guess Gaussian
guess %lo = SplitGaussian [38:]
@0: plot
sleep 0.3
guess %lo = LorentzianA [38:44]
%pe = Pearson7(height=~1901, center=~75.313, hwhm=~1/2, shape=2.4)
F += %pe
%ble = copy(%pe)
dele %pe
F += Pearson7(~2000, ~75, ~0.6, ~2)
@0: fit 12
@*: with fitting_method=nelder_mead_simplex fit 10
with fitting_method=genetic_algorithms fit 10
%fun = copy(%_1)
i prop %ble, %lo
$a = %ble.shape
$a = %ble.shape + %lo.hwhm
$b = ~{%ble.shape} + {%lo.hwhm}
$abc = F[0].hwhm + 1
$abc = {F[0].hwhm + 0.1}
$_a = 3
$_a = 4
@0.F[0].hwhm = $abc
F[*].hwhm = $abc
%*.hwhm = $abc
%*.dummy = ~3
F[*].hwhm = ~{F[0].hwhm + 0.1}
%lo_cp = copy(@0.F[1])
del %lo_cp
fit
fit history 0
fit history -1
f undo
f redo
fi undo
fi redo
fit clear_history


info F
info Z
inf compiler
i cov @0
i data
i dataset_count
i errors @0
i filename
i fit
i fit_history
i formula
i functions
i gnuplot_formula
i history [0:0]
i history_summary
i refs $a
i set
i set autoplot
i simplified_formula
i simplified_gnuplot_formula
i state
i title
i types
i variables
i version
i view

p $a, $_11
p %fun(3), %ble(2 + 5*sin(2/3*pi) + %fun(3.3))
i %fun, %ble
i view
i @0.F
i @0.F[0], @0.F[-1]
i @0.Z
@0: i formula
@0: debug df(12*3)
@0: i data
@0: i filename, title
i fit
i fit_history
i set
i errors
@0: i guess
@0: i guess [10:40]
@0: p ((3+5) * (2.1+pi) * exp(5)/cos(ln(3)))^2
i GaussianA, Gaussian, Linear
i SplitGaussian
i formula
p min(y), max(s)
p min(y if 20<x and x<25)
p sum(y-y[0])
p avg(y*y), stddev(y if y > avg(y))
p darea(y-@0.F(x) if 15<x and x<20)
info version, variables
p filename, title

# data expressions
@0: $foo = {y[0]} + 1
$foo = 3 + 1
Y = y / $foo
p 2*(%fun.findx(%fun.Center, %fun.Center+10, %fun.Height/2) - %fun.Center)
p %fun.FWHM
%c = Constant(~0.001)
Z = %c + %fun
Z = 0
Z += %c
X = x + @0.Z(x)
del %c
p %fun(%fun.extremum(10, 50))
@0: p s[index(19.92)]^2, y[index(19.92)]
p %fun.numarea(10, 30, 100)
p F.numarea(-10, 10, 100)


plot
pl [30:40.2][-1:]
plo [:50]
@*: plo []
@0: plo [:50]

@+ = @0
@+ = 0
@2 = @0 + @1
@2 = @0 - @1
@2 = @0 - 0.291834*@1
@2 = @0 and @1
del @2
@+ = avg_same_x(@0 and @1)
@2 = @2 - shirley_bg(@2)
delete @2
@1.F = copy(@0.F)
@1.Z = copy(@0.Z)
with epsilon=0.1 @1 = sum_same_x(@1)


#test variable rhs syntax parsing
$t1 = 3
$t2 = -$t1
$t3 = $t1+(-$t2^2)
$t4=sin($t1)^2+(-cos($t1))^2
$t5=voigt($t4, ~3)

define Bleh(area, center, fwhm, shape) = GaussianA(area*(1-shape), center, fwhm) + LorentzianA(area*shape, center, fwhm+0.2)
%bleh = Bleh(~123., 30, ~4, ~0.5)
del %bleh
undefine Bleh
define Bleh(a) = Linear(0, a)
%bleh = Bleh(~{pi})
inf Bleh, %bleh
del %bleh

#definitions from the manual
define MyGaussian(height, center, hwhm) = height*exp(-ln(2)*((x-center)/hwhm)^2)
define SplitL(height, center, hwhm1=fwhm*0.5, hwhm2=fwhm*0.5) =  x < center ? Lorentzian(height, center, hwhm1) : Lorentzian(height, center, hwhm2)
define ReadShockley(sigma0=1, a=1) = sigma0 * t * (a - ln(t)) where t=x*pi/180
define FullGBE(k, alpha) = k * alpha * eta * (eta / tanh(eta) - ln (2*sinh(eta))) where eta = 2*pi/alpha * sin(theta/2), theta=x*pi/180
define MyLorentzian(height, center, hwhm) = height/(1+((x-center)/hwhm)^2)
define MyCubic(a0=height,a1=0, a2=0, a3=0) = a0 + a1*x + a2*x^2 + a3*x^3
define SuBeArTiDi(c, s, v0, dv) = c*(s/x)^3*exp(-(((s/x)-v0)/dv)^2)/x
define GaussianArea(area, center, hwhm) = Gaussian(area/hwhm/sqrt(pi/ln(2)), center, hwhm)
define GLSum(height, center, hwhm, shape) = Gaussian(height*(1-shape), center, hwhm) + Lorentzian(height*shape, center, hwhm)
define SplitG(height, center, hwhm1=fwhm*0.5, hwhm2=fwhm*0.5) = x < center ? Lorentzian(height, center, hwhm1) : Lorentzian(height, center, hwhm2)
undefine GaussianArea


# commands from script are not stored in commands[], so it can be empty
# we only use empty ranges, to avoid errors
info history[0:] >tmp_foo.fit
info history[:0] >>tmp_foo.fit
set logfile='tmp_log.fit'
set log_full=1, logfile='tmp_log.fit'
set logfile=''
exec 'tmp_log.fit' # it's an empty file (with some comments)

@0: print all: x, y
@*: print all: x, y, s > 'tmp_foo2.xy'
@0: print all: x, y, a > 'tmp_foo3.xy'
@0: print all: x, y, s, @0.F(x), (y-@0.F(x))/s, a > 'tmp_foo4.xy'
@0: print all: x, y, s, F(x), (y-F(x))/s, a >> tmp_foo4.xy
@0: info peaks > tmp_foo5.xy
@0: info peaks_err > tmp_foo6.xy
@0: info formula > tmp_foo7.xy
@0: info simplified_gnuplot_formula > tmp_foo8.xy
@*: info peaks > tmp_foo9.xy
i history >> tmp_foo9.xy
i models >> tmp_foo9.xy
info state > tmp_dump.fit

delete file 'tmp_foo.fit', file 'tmp_foo2.xy', file 'tmp_foo3.xy'
delete file 'tmp_foo4.xy', file 'tmp_foo5.xy', file 'tmp_foo6.xy'
delete file 'tmp_foo7.xy', file 'tmp_foo8.xy', file 'tmp_foo9.xy'
delete file tmp_dump.fit
delete file tmp_log.fit

lua print("current date and time:\t\t" .. os.date())
= "again: \t" .. os.date()
= "again:", os.date()
exec= "info version"
= F:get_info('version'):lower(), _VERSION
lua F:out((F:get_info("F[0]")))

# settings
set function_cutoff = 0
set fitting_method = levenberg_marquardt
set height_correction = 1
set lm_lambda_down_factor = 10
set lm_lambda_start = 0.001
set lm_lambda_up_factor = 10
set lm_max_lambda = 1e+15
set lm_stop_rel_change = 0.0001
set max_wssr_evaluations = 1000
set nm_convergence = 0.0001
set nm_distribution = bound
set nm_move_all = 0
set nm_move_factor = 1
set domain_percent = 30
set width_correction = 1
set epsilon = 1e-12
set default_sigma=one
set default_sigma=sqrt
set verbosity = 1
set numeric_format = '%.2f'
set on_error = nothing
set cwd = '/tmp' # it can cause error, paths are not cross-platform
set cwd = 'C:\'  # it can cause error, paths are not cross-platform
info set cwd

set on_error = stop
reset
#quit