1# script that generates a generic curve with some noise and smooth it 2# smoothing is not documented in the SciDAVis manual 3 4import random 5 6global f1 7def f1(x): 8 a1 = 5.0 9 a2 = -10.0 10 a3 = 10.0 11 b1 = 2.0 12 return ((a1+a2*x+a3*x**2-b1/x**3)/1000.0) 13 14dp=0.5 #noise's stddev 15 16# set seed to ensure replicability 17random.seed(1) 18 19t1Name="generic-curve" 20t1=newTable(t1Name,2,51) 21for i in range(1,t1.numRows()+1): 22 xx=float(i) 23 t1.setCell(1,i,xx) 24 t1.setCell(2,i,f1(xx)+random.uniform(0,dp)) 25g1=plot(t1,'2',1) #plotting the curve 26 27g1.confirmClose(False) 28t1.confirmClose(False) 29 30l1=g1.activeLayer() 31curve1=t1Name+"_2" 32 33smth1=SmoothFilter(l1,curve1) 34smth1.setMethod(1) # method=1 - Savitzky-Golay 35smth1.setSmoothPoints(2,2) # left and right points 36smth1.setPolynomOrder(3) 37smth1.run() 38 39smth2=SmoothFilter(l1,curve1) 40smth2.setMethod(2) # method=2 - FFT 41smth2.setSmoothPoints(3) 42smth2.setColor("blue") 43smth2.run() 44 45smth3=SmoothFilter(l1,curve1) 46smth3.setMethod(3) # method=3 - Moving Window Average 47smth3.setSmoothPoints(3) 48smth3.setColor("green") 49smth3.run() 50 51g1.exportImage("smoothing.png") 52app.exit() 53