def example_FSA_StepNoisy(): ''' step function ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("a noisy Step") PySpectra.setComment("Input for Utils->FSA/SSA") PySpectra.setWsViewport("DINA5") g = utils.createStep(name="step", xMin=-10., xMax=10., nPts=101, lineColor='red', amplitude=3.) g.y += np.random.random_sample((len(g.x), )) * 0.5 PySpectra.display() return
def testImageMB2( self): print "testGraphics.testImageMB2" PySpectra.setWsViewport( 'DINA5S') PySpectra.cls() PySpectra.delete() (xmin, xmax) = (-2., 1) (ymin, ymax) = (-1.5, 1.5) (width, height) = (300, 300) maxiter = 20 # # create the image by supplying the limits # m = PySpectra.Image( name = "MandelbrotSet2", xMin = xmin, xMax = xmax, width = width, yMin = ymin, yMax = ymax, height = height, xLabel = "eh_mot01", yLabel = "eh_mot02") r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) for i in range(width): for j in range(height): res = self.mandelbrot(r1[i] + 1j*r2[j],maxiter) m.setPixelWorld( x = r1[i], y = r2[j], value = res) PySpectra.cls() PySpectra.display() PySpectra.processEventsLoop(1) self.assertEqual( m.xMin, xmin) self.assertEqual( m.xMax, xmax) self.assertEqual( m.yMin, ymin) self.assertEqual( m.yMax, ymax) self.assertEqual( m.height, height) self.assertEqual( m.width, width) # # to understand '+ 1'consider : x [-2, 1], width 100 # if x == 1 -> ix == 100, so we need '+ 1' # self.assertEqual( m.data.shape[0], width) self.assertEqual( m.data.shape[1], height) return
def testImageMB1( self): print "testGraphics.testImageMB1" PySpectra.setWsViewport( 'DINA5S') PySpectra.cls() PySpectra.delete() (xmin, xmax) = (-2., 1) (ymin, ymax) = (-1.5, 1.5) (width, height) = (500, 500) maxiter = 20 r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) n3 = np.empty((width, height)) for i in range(width): for j in range(height): n3[i,j] = self.mandelbrot(r1[i] + 1j*r2[j],maxiter) # # create the image by supplying data # m = PySpectra.Image( name = "MandelbrotSet1", data = n3, xMin = xmin, xMax = xmax, width = width, yMin = ymin, yMax = ymax, height = height, xLabel = "eh_mot01", yLabel = "eh_mot02") PySpectra.display() self.assertEqual( m.xMin, xmin) self.assertEqual( m.xMax, xmax) self.assertEqual( m.yMin, ymin) self.assertEqual( m.yMax, ymax) self.assertEqual( m.height, height) self.assertEqual( m.width, width) # # to understand '+ 1'consider : x [-2, 1], width 100 # if x == 1 -> ix == 100, so we need '+ 1' # self.assertEqual( m.data.shape[0], width) self.assertEqual( m.data.shape[1], height) PySpectra.processEventsLoop( 2)
def example_Gauss2(): ''' 2 gauss plot ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("Two Gauss curves") PySpectra.setComment( "To demonstrate how SSA limits can be defined with VLines") PySpectra.setWsViewport("DINA5") g = PySpectra.Scan(name="gauss", xMin=-10., xMax=10., nPts=101) mu1 = 0. sigma1 = 1. mu2 = 6.5 sigma2 = 1.2 g.y = 1./(sigma1*np.sqrt(2.*np.pi))*np.exp( -(g.y-mu1)**2/(2*sigma1**2)) + \ 2./(sigma2*np.sqrt(2.*np.pi))*np.exp( -(g.y-mu2)**2/(2*sigma2**2)) PySpectra.display() return
def example_Gauss(): ''' gauss plot ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("A simple Gauss curve") PySpectra.setComment("Can be used with SSA, calculating derivative and so") PySpectra.setWsViewport("DINA5") g = utils.createGauss(name="gauss", xMin=-5., xMax=5., nPts=101, lineColor='red', x0=0., sigma=1., amplitude=1.) PySpectra.display() return
def testWsViewport( self): ''' ''' print "testGraphics.testWsViewport" PySpectra.cls() PySpectra.delete() PySpectra.setTitle( "go through the viewports") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True) sinus.y = np.sin( sinus.y) for elm in [ 'DINA4', 'DINA4P', 'DINA4S', 'DINA5', 'DINA5P', 'DINA5S', 'DINA6', 'DINA6P', 'DINA6S']: PySpectra.setWsViewport( elm) PySpectra.display() PySpectra.processEventsLoop( 1) print "testGraphics.testWsViewport, DONE"
def example_ScanningAutoscaleX(): ''' ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("scanning, x-axis is re-scaled") PySpectra.setWsViewport("DINA5") sinus = PySpectra.Scan(name='sinus', xMin=0., xMax=6.0, nPts=101, autoscaleX=True, lineColor='red') for i in range(sinus.nPts): sinus.setX(i, i / 10. + 0.01) sinus.setY(i, math.sin(i / 10.)) PySpectra.display(['sinus']) time.sleep(0.01) return
def example_FSA_GaussVeryNoisy(): ''' gauss plot ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("a very noisy Gauss at 0.12345") PySpectra.setComment("Input for Util->FSA/SSA") PySpectra.setWsViewport("DINA5") g = utils.createGauss(name="gauss", xMin=-5., xMax=5., nPts=101, lineColor='red', x0=0.12345, sigma=1., amplitude=1.) g.y += np.random.random_sample((len(g.x), )) * 0.3 PySpectra.display() return
def example_Lissajous(): ''' plots and updates a Lissajous figure ''' PySpectra.setWsViewport("DINA5S") PySpectra.cls() PySpectra.delete() scan = PySpectra.Scan(name='Lissajous', nPts=1000, xMin=-1., xMax=1.) x = np.linspace(0., 6.5, 1000) y = np.linspace(0., 6.5, 1000) scan.x = np.cos(x) scan.y = np.sin(y) PySpectra.display() for i in range(500): x = x + 0.005 scan.smartUpdateDataAndDisplay(np.cos(x), np.sin(y))
def example_ScanningReverseAutoscaleX(): ''' ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle( "scanning in reverse direction, the x-axis is re-scaled") PySpectra.setWsViewport("DINA5") sinus = PySpectra.Scan(name='sinus', xMin=0., xMax=6.0, nPts=101, autoscaleX=True, lineColor='red') for i in range(sinus.nPts): x = 10. - i / 10. sinus.x[i] = x sinus.y[i] = math.sin(i / 10.) sinus.currentIndex = i PySpectra.display(['sinus']) time.sleep(0.02)
def example_LogPlotWithText(): ''' create 1 scan, y-log scale, one text ''' PySpectra.cls() PySpectra.delete() PySpectra.setWsViewport("DINA5") t1 = PySpectra.Scan(name="t1", xMin=0.01, xMax=10., nPts=101, lineColor='blue', xLabel='Position', yLabel='signal', yLog=True) t1.addText(text="a left/center aligned text, should be in the center", x=0.05, y=0.5, hAlign='left', vAlign='center') PySpectra.display()
def example_ScanningReverse(): ''' ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("scanning in reverse direction, x-axis is fixed") PySpectra.setWsViewport("DINA5") sinus = PySpectra.Scan(name='sinus', xMin=0., xMax=6.0, nPts=101, autoscaleX=False, lineColor='red') sinus.xMax = 10. for i in range(sinus.nPts): x = 10. - i / 10. sinus.setX(i, x) sinus.setY(i, math.sin(i / 10.)) PySpectra.display(['sinus']) time.sleep(0.05) return
def example_Create5Plots(): ''' create 5 scans, different colors, demonstrate overlay feature ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("5 Scans, t5 is overlaid to t3") PySpectra.setComment("Notice that sin has autoscalY == False") PySpectra.setWsViewport("DINA5") t1 = PySpectra.Scan(name="t1", lineColor='blue', yLabel='sin', yMin=-2, yMax=2, autoscaleY=False) t1.y = np.sin(t1.x) t2 = PySpectra.Scan("t2", xLabel='Position', yLabel='cos', symbol='+') t2.y = np.cos(t2.x) t3 = PySpectra.Scan(name="t3", lineColor='green', xLabel='Position', yLabel='tan') t3.y = np.tan(t3.x) t4 = PySpectra.Scan(name="t4", lineColor='NONE', xLabel='Position', yLabel='random', symbol='+', symbolColor='CYAN') t4.y = np.random.random_sample((len(t4.y), )) t5 = PySpectra.Scan(name="t5", lineColor='magenta', xLabel='Position', yLabel='x**2') t5.y = t5.x * t5.x PySpectra.overlay('t5', 't3') PySpectra.display()
def exampleImageMBVia_toPyspLocal(): ''' this examples simulates the toPyspMonitor() interface replace PySpectra.toPyspLocal() with HasyUtils.toPyspMonitor() to connect to pyspMonitor.py ''' PySpectra.setWsViewport('DINA5S') PySpectra.cls() PySpectra.delete() (xmin, xmax) = (-2., -0.5) (ymin, ymax) = (0, 1.5) (width, height) = (10, 10) maxiter = 25 # # do the clean-up before we start # hsh = PySpectra.toPyspLocal( {'command': ['delete', 'setWsViewport DINA5S', 'cls']}) if hsh['result'] != "done": print("error from ['delete', 'setWsViewport DINA5S', 'cls']") return # # create the image # hsh = { 'Image': { 'name': "Mandelbrot", 'xMin': xmin, 'xMax': xmax, 'width': width, 'yMin': ymin, 'yMax': ymax, 'height': height } } hsh = PySpectra.toPyspLocal(hsh) if hsh['result'] != "done": print("error from putData") return # # fill the image, pixel by pixel # r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) for i in range(width): for j in range(height): res = mandelbrot(r1[i] + 1j * r2[j], maxiter) hsh = { 'command': ['setPixelImage Mandelbrot %d %d %g' % (i, j, res)] } hsh = PySpectra.toPyspLocal(hsh) if hsh['result'] != "done": print("error from setPixel") return PySpectra.cls() PySpectra.display() return