def example_Create56x3Plots(): ''' create 56x3 plots ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("56 x 3 Scans") PySpectra.setComment("Display many Scans") PySpectra.setWsViewport("DINA4") for i in range(56): t = PySpectra.Scan(name="t%d_a" % i, lineColor='blue', nPts=200, yLabel='rand') t.y = np.random.random_sample((len(t.x), )) * 1000. t = PySpectra.Scan(name="t%d_b" % i, lineColor='red', nPts=200, yLabel='rand', overlay="t%d_a" % i) t.y = np.random.random_sample((len(t.x), )) * 1000. t = PySpectra.Scan(name="t%d_c" % i, lineColor='green', nPts=200, yLabel='rand', overlay="t%d_a" % i) t.y = np.random.random_sample((len(t.x), )) * 1000. PySpectra.display() return
def testClose( self): ''' ''' print "testMplGraphics.testClose" PySpectra.mtpltlb.graphics.cls() PySpectra.delete() PySpectra.setTitle( "check x-axis doty") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True) sinus.y = np.sin( sinus.y) PySpectra.mtpltlb.graphics.display() PySpectra.mtpltlb.graphics.processEventsLoop( 1) PySpectra.mtpltlb.graphics.close() PySpectra.mtpltlb.graphics.cls() PySpectra.delete() PySpectra.setTitle( "check x-axis doty") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True) sinus.y = np.sin( sinus.y) PySpectra.mtpltlb.graphics.display() PySpectra.mtpltlb.graphics.processEventsLoop( 1) print "testMplGraphics.testClose, DONE"
def example_OverlayDoty(): ''' create 2 overlaid scans ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("2 Overlay scans, x-axis tick labels show date") PySpectra.setWsViewport("DINA5") t1 = PySpectra.Scan(name="t1", xMin=0, xMax=10, nPts=101, lineColor='blue', xLabel='Position', yLabel='sin', doty=True) t1.y = np.sin(t1.x) t2 = PySpectra.Scan("t2", xLabel='Position', yLabel='cos', xMin=0, xMax=10, nPts=101, lineColor='green', doty=True) t2.y = np.cos(t2.x) t2.overlay = "t1" PySpectra.display()
def testGrid( self): ''' using showGridX, showGridY ''' print "testMplGraphics.testGrid" PySpectra.mtpltlb.graphics.cls() PySpectra.delete() PySpectra.setTitle( "check grids") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., showGridX = True, xMax = 6.0, nPts = 101, lineColor = 'red') cos = PySpectra.Scan( name = 'cos', xMin = 0., showGridY = True, xMax = 6.0, nPts = 101, lineColor = 'red') tan = PySpectra.Scan( name = 'tan', xMin = 0., showGridY = True, showGridX = True, xMax = 6.0, nPts = 101, lineColor = 'red') sinus.y = np.sin( sinus.y) cos.y = np.cos( cos.y) tan.y = np.tan( tan.y) PySpectra.mtpltlb.graphics.display() PySpectra.mtpltlb.graphics.display() #PySpectra.show() PySpectra.mtpltlb.graphics.processEventsLoop( 1) print "testMplGraphics.testGrid, DONE"
def example_GaussManyOverlay(): ''' gauss plot ''' PySpectra.cls() PySpectra.delete() PySpectra.setWsViewport("DINA5") g = PySpectra.Scan(name="gauss", xMin=-10., xMax=10., nPts=101) #mu = 0. #sigma = 1. #g.y = 1/(sigma*np.sqrt(2.*np.pi))*np.exp( -(g.y-mu)**2/(2*sigma**2)) 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)) g.autoscaleX = False g.autoscaleY = False g.xMax = 11 g.xMin = -4 g.yMin = 0 g.yMax = 2 for i in range(1, 50): # don't want i == 0 gqe = PySpectra.Scan(name="gauss%d" % i, xMin=-5., xMax=5., nPts=101) gqe.x = g.x + 0.02 * i gqe.y = g.y + 0.02 * i PySpectra.overlay("gauss%d" % i, "gauss") gqe.useTargetWindow = True PySpectra.display() return
def testScanningTwoPlots( self): ''' using setX and setY ''' print "testMplGraphics.testScanningTwoPlots" PySpectra.mtpltlb.graphics.cls() PySpectra.delete() PySpectra.setTitle( "two plots, x-axis not re-scaled") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, autoscaleX = False, lineColor = 'red') cosinus = PySpectra.Scan( name = 'cosinus', xMin = 0., xMax = 6.0, nPts = 101, autoscaleX = False, lineColor = 'blue') for i in range( sinus.nPts): sinus.setX( i, i/10.) sinus.setY( i, math.sin( i/10.)) cosinus.setX( i, i/10.) cosinus.setY( i, math.cos( i/10.)) PySpectra.mtpltlb.graphics.display( ['sinus', 'cosinus']) time.sleep( 0.01) print "testMplGraphics.testScanningTwoPlots, DONE"
def test_doty(self): print "testPySpectra.test_doty" PySpectra.cls() PySpectra.delete() PySpectra.setTitle("2 plots, the seconds has doty as the x-axis") scan1 = PySpectra.Scan(name="notdotyscan", xMin=10., xMax=30.0, nPts=101, dType=np.float64, lineColor='red', lineStyle='solidLine') self.assertEqual(scan1.doty, False) scan2 = PySpectra.Scan(name="dotyscan", xMin=10., xMax=30.0, nPts=101, dType=np.float64, doty=True, lineColor='red', lineStyle='solidLine') self.assertEqual(scan2.doty, True) PySpectra.display() PySpectra.processEventsLoop(1) print "testPySpectra.test_doty DONE"
def testFastDisplay_v1( self): ''' version 1: set the scan data and call display ''' print "testMplGraphics.testDisplay_v1" PySpectra.mtpltlb.graphics.cls() PySpectra.delete() scan1 = PySpectra.Scan( name = 't1', nPts = 100, yMin = -1., yMax = 1.) scan2 = PySpectra.Scan( name = 't2', nPts = 100, yMin = -1., yMax = 1.) PySpectra.mtpltlb.graphics.display() data = np.random.normal(size=(10,100)) x = np.linspace( 0., 10., 100) ptr = 0 scan1.x = x scan2.x = x startTime = time.time() for i in range( 20): PySpectra.mtpltlb.graphics.cls() scan1.y = data[ptr%10] scan2.y = data[ptr%10] PySpectra.mtpltlb.graphics.display() ptr += 1 PySpectra.mtpltlb.graphics.processEvents() diffTime = time.time() - startTime self.assertLess( diffTime, 11.) print "testMplGraphics.testDisplay_v1, DONE"
def testDisplayTwo( self): print "testMplGraphics.testDisplayTwo" PySpectra.mtpltlb.graphics.cls() PySpectra.delete() sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, dType = np.float64, lineWidth = 5., lineColor = 'red', lineStyle = 'dashed') sinus.y = np.sin( sinus.y) cosinus = PySpectra.Scan( name = "cosinus", xMin = 0., xMax = 6.0, nPts = 101, dType = np.float64, lineWidth = 3., lineColor = 'blue', lineStyle = 'dotted') cosinus.y = np.cos( cosinus.y) PySpectra.mtpltlb.graphics.display() #PySpectra.show() PySpectra.mtpltlb.graphics.processEventsLoop( 1) print "testMplGraphics.testDisplayTwo, DONE"
def testFastDisplay_v2( self): ''' version 2: directly use the plotDataItem.setData() function ''' print "testGraphics.testDisplay_v2" PySpectra.cls() PySpectra.delete() scan1 = PySpectra.Scan( name = 't1', nPts = 1000, yMin = -1., yMax = 1.) scan2 = PySpectra.Scan( name = 't2', nPts = 1000, yMin = -1., yMax = 1.) data = np.random.normal(size=(10,1000)) x = np.linspace( 0., 10., 1000) ptr = 0 scan1.x = x scan2.x = x scan1.y = data[0] scan2.y = data[0] PySpectra.display() startTime = time.time() for i in range( 200): scan1.plotDataItem.setData(x, data[ptr%10]) scan2.plotDataItem.setData(x, data[ptr%10]) ptr += 1 PySpectra.processEvents() diffTime = time.time() - startTime self.assertLess( diffTime, 7.) self.assertGreater( diffTime, 1.5) print "testGraphics.testDisplay_v2, DONE"
def testClose( self): ''' ''' print "testGraphics.testClose" PySpectra.cls() PySpectra.delete() PySpectra.setTitle( "testing close()") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True) sinus.y = np.sin( sinus.y) PySpectra.display() PySpectra.processEventsLoop( 1) PySpectra.close() PySpectra.cls() PySpectra.delete() PySpectra.setTitle( "testing close(), again") sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True) sinus.y = np.sin( sinus.y) PySpectra.display() PySpectra.processEventsLoop( 1) print "testGraphics.testClose, DONE"
def example_PlotsWithTextContainer(): ''' create 3 scans and a text container ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("here could be a title") PySpectra.setComment("this is a comment") PySpectra.setWsViewport("DINA5") textScan = PySpectra.Scan(name="textContainer", textOnly=True) textScan.addText(text="some information", x=0., y=0.95, color='blue') textScan.addText(text="and more infos", x=0., y=0.85, color='blue') t1 = PySpectra.Scan("t1", lineColor='blue', xLabel='Position', yLabel='sin') t1.y = np.sin(t1.x) t2 = PySpectra.Scan("t2", xLabel='Position', yLabel='cos', symbol='o', symbolColor='red', symbolSize=5) t2.y = np.cos(t2.x) t3 = PySpectra.Scan("t3", xLabel='Position', yLabel='tan', symbol='+', lineColor='cyan', symbolColor='green', symbolSize=5) t3.y = np.tan(t3.x) PySpectra.display()
def example_ScanningMesh(): ''' ''' PySpectra.cls() PySpectra.delete() (xmin, xmax) = (-2., 1) (ymin, ymax) = (-1.5, 1.5) (width, height) = (20, 20) maxiter = 20 r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) n3 = np.zeros((width, height)) m = PySpectra.Image(name="MandelbrotSet", colorMap='Greys', estimatedMax=20, xMin=xmin, xMax=xmax, width=width, yMin=ymin, yMax=ymax, height=height) PySpectra.setTitle("Simulate a mesh scan") PySpectra.setWsViewport("DINA5") sinus = PySpectra.Scan(name='sinus', xMin=0., xMax=6.0, nPts=width * height, autoscaleX=False, lineColor='red') cosinus = PySpectra.Scan(name='cosinus', xMin=0., xMax=6.0, nPts=width * height, autoscaleX=False, lineColor='red') PySpectra.display() (iI, jI) = (0, 0) for i in range(sinus.nPts): x = float(i) * 6.28 / float(sinus.nPts) sinus.setX(i, x) cosinus.setX(i, x) sinus.setY(i, math.sin(x)) cosinus.setY(i, math.cos(x)) res = mandelbrot(r1[iI] + 1j * r2[jI], maxiter) m.data[iI][jI] = res iI += 1 if iI == width: iI = 0 jI += 1 PySpectra.display() PySpectra.cls() PySpectra.display() return
def testMisc(self): print "testPySpectra.testMisc" PySpectra.cls() PySpectra.delete() t1 = PySpectra.Scan(name="t1", xMin=0., xMax=5., nPts=101, color='red', at="(1,2,1)") t2 = PySpectra.Scan(name="t2", xMin=0., xMax=5., nPts=101, at=(1, 2, 2)) PySpectra.display() lst = PySpectra.getDisplayList() self.assertEqual(t1.getTotalCounts(), 252.5) self.assertTrue(len(lst) == 2) self.assertTrue(PySpectra.info() == 2) self.assertTrue(PySpectra.getIndex('t1') == 0) self.assertEqual(t1.at[0], 1) self.assertEqual(t1.at[1], 2) self.assertEqual(t1.at[2], 1) self.assertEqual(t2.at[0], 1) self.assertEqual(t2.at[1], 2) self.assertEqual(t2.at[2], 2) self.assertEqual(t1.lineColor, 'red') with self.assertRaises(ValueError) as context: t1.getX(102) #print repr( context.exception) self.assertTrue('GQE.Scan.getX: t1, index 102 out of range [0, 101]' in context.exception) with self.assertRaises(ValueError) as context: t1.getX(-1) #print repr( context.exception) self.assertTrue('GQE.Scan.getX: t1, index -1 < 0' in context.exception) with self.assertRaises(ValueError) as context: t1.getY(102) #print repr( context.exception) self.assertTrue('GQE.Scan.getY: t1, index 102 out of range [0, 101]' in context.exception) with self.assertRaises(ValueError) as context: t1.getY(-1) #print repr( context.exception) self.assertTrue('GQE.Scan.getY: t1, index -1 < 0' in context.exception) return
def testGetIndex(self): print "testPySpectra.testGetIndex" PySpectra.delete() # # left-right # x1 = np.linspace(0., 10., 11) y1 = np.linspace(0., 10., 11) scan1 = PySpectra.Scan('t1', x=x1, y=y1) self.assertEqual(scan1.getIndex(4.2), 4) self.assertEqual(scan1.getIndex(4.8), 5) with self.assertRaises(ValueError) as context: i = scan1.getIndex(-1) #print repr( context.exception) self.assertTrue( "GQE.getIndex(L2R): x -1 < x[0] 0" in context.exception) with self.assertRaises(ValueError) as context: i = scan1.getIndex(11) #print repr( context.exception) self.assertTrue("GQE.getIndex(L2R): x 11 > x[currentIndex] 10" in context.exception) # # reverse the x-axis # x2 = x1[::-1] scan2 = PySpectra.Scan('t2', x=x2, y=y1) self.assertEqual(scan2.getIndex(4.2), 6) self.assertEqual(scan2.getIndex(4.8), 5) with self.assertRaises(ValueError) as context: i = scan2.getIndex(-1) #print repr( context.exception) self.assertTrue( "GQE.getIndex(R2L): x -1 < x[currentIndex] 0" in context.exception) with self.assertRaises(ValueError) as context: i = scan2.getIndex(11) print repr(context.exception) self.assertTrue( "GQE.getIndex(R2L): x 11 > x[0] 10" in context.exception) return
def testOverlay( self): print "testMplGraphics.testOverlay" PySpectra.mtpltlb.graphics.cls() PySpectra.delete() sinus = PySpectra.Scan( name = 'sinus', xMin = 0., xMax = 6.0, nPts = 101, dType = np.float64, lineWidth = 5., lineColor = 'red', lineStyle = 'dashed') sinus.y = np.sin( sinus.y) tan = PySpectra.Scan( name = 'tangens', xMin = 0., xMax = 6.0, nPts = 101, dType = np.float64, lineWidth = 2., lineColor = 'green', lineStyle = 'dashed') tan.y = np.tan( tan.y) # # cosinus has to be plotted in the same viewport as sinus # cosinus = PySpectra.Scan( name = "cosinus", xMin = 0., xMax = 6.0, nPts = 101, dType = np.float64, lineWidth = 3., lineColor = 'blue', overlay = "sinus", lineStyle = 'dotted') self.assertEqual( cosinus.overlay, 'sinus') cosinus.y = np.cos( cosinus.y) # # cossquare has to be plotted in the same viewport as tangens # cossquare = PySpectra.Scan( name = "cossquare", xMin = 0., xMax = 6.0, nPts = 101, dType = np.float64, yMin = -5, yMax = 5., lineWidth = 1., overlay = 'tangens', lineColor = 'blue', lineStyle = 'dotted') self.assertEqual( cossquare.overlay, 'tangens') cossquare.y = np.cos( tan.x) * np.cos( tan.x) PySpectra.mtpltlb.graphics.display() #PySpectra.show() PySpectra.mtpltlb.graphics.processEventsLoop( 1) print "testMplGraphics.testOverlay, DONE"
def main(): t1 = pysp.Scan( name = "t1", color = 'blue', yLabel = 'sin') t1.y = np.sin( t1.x) t1.currentIndex = 10 t2 = pysp.Scan( name = "t2", color = 'blue', yLabel = 'rand') t2.y = np.random.random_sample( (len( t2.x), )) for i in range( 10, len( t1.x)): t1.currentIndex = i pysp.display() t2.y = np.random.random_sample( (len( t2.x), )) t2.lastIndex = 0 pysp.processEventsLoop()
def test_ssa(self): ''' overlay 2 scans ''' PySpectra.cls() PySpectra.delete() g = PySpectra.Scan(name="gauss", xMin=-5., xMax=5., nPts=101, lineColor='red') mu = 0. sigma = 1. g.y = 1 / (sigma * np.sqrt(2. * np.pi)) * np.exp(-(g.y - mu)**2 / (2. * sigma**2)) hsh = HasyUtils.ssa(g.x, g.y) self.assertEqual(hsh['status'], 1) self.assertEqual(hsh['midpoint'], 0.) self.assertAlmostEqual(hsh['l_back'], 2.521e-5) self.assertAlmostEqual(hsh['r_back'], 2.521e-5) self.assertAlmostEqual(hsh['integral'], 0.9997473505) self.assertEqual(hsh['reason'], 0) self.assertEqual(hsh['peak_x'], 0) self.assertAlmostEqual(hsh['peak_y'], 0.3989170740) self.assertAlmostEqual(hsh['cms'], 1.2989313e-16) self.assertAlmostEqual(hsh['fwhm'], 2.35522977) self.assertAlmostEqual(hsh['back_int'], 0.0002520637) print repr(hsh)
def testTextOnlyScan(self): print("testPySpectra.testTextOnlyScan") PySpectra.cls() PySpectra.delete() PySpectra.setTitle("test textOnly Scans") g = PySpectra.Scan(name="textContainer", textOnly=True) g.addText(name="testText", text="some text to be displayed") self.assertEqual(len(g.textList), 1) txt = g.textList[0] self.assertEqual(txt.name, "testText") self.assertEqual(txt.hAlign, "left") self.assertEqual(txt.vAlign, "top") self.assertEqual(txt.color, "black") self.assertEqual(txt.x, 0.5) self.assertEqual(txt.y, 0.5) self.assertEqual(txt.NDC, True) g.display() PySpectra.processEventsLoop(1) return
def test_createScanByLimit(self): print "testPySpectra.test_createScanByLimit" PySpectra.cls() PySpectra.delete() PySpectra.setTitle("create scan by limits") scan = PySpectra.Scan(name="test1", xMin=0., xMax=1.0, nPts=101, dType=np.float64, at=(2, 2, 3), lineColor='red', lineStyle='solidLine') self.assertEqual(scan.xMin, 0.) self.assertEqual(scan.xMax, 1.) self.assertEqual(scan.nPts, 101) self.assertEqual(scan.dType, np.float64) self.assertEqual(len(scan.x), 101) self.assertEqual(scan.x.dtype, np.float64) self.assertEqual(len(scan.y), 101) self.assertEqual(scan.y.dtype, np.float64) self.assertEqual(scan.lineColor, 'red') PySpectra.display() PySpectra.processEventsLoop(1) print "testPySpectra.test_createScanByLimit DONE"
def testFillData(self): print "testPySpectra.testFillData" PySpectra.cls() PySpectra.delete() PySpectra.setTitle("scan.setY()") scan = PySpectra.Scan(name='t1', xLabel="up to 200 pts", nPts=201, yMin=-10., yMax=10.) self.assertEqual(scan.currentIndex, 200) #scan.y = np.tan( scan.x) startTime = time.time() for i in range(len(scan.y)): scan.setY(i, math.tan(float(i) / 10)) PySpectra.display() diffTime = time.time() - startTime self.assertLess(diffTime, 12) PySpectra.display() PySpectra.processEventsLoop(1) print "testPySpectra.testFillData, DONE"
def testSetLimits(self): print "testPySpectra.testSetLimits" PySpectra.cls() PySpectra.delete() PySpectra.setTitle("test setLimits") scan = PySpectra.Scan( name='t1', xMin=0, xMax=10, nPts=11, ) self.assertEqual(scan.xMin, 0.) self.assertEqual(scan.xMax, 10.) self.assertEqual(scan.yMin, 0.) self.assertEqual(scan.yMax, 10.) scan.xMin = -1. scan.xMax = -1. scan.yMin = -1. scan.yMax = -1. scan.setLimits() self.assertEqual(scan.xMin, 0.) self.assertEqual(scan.xMax, 10.) self.assertEqual(scan.yMin, 0.) self.assertEqual(scan.yMax, 10.5)
def testYToMinusY( self): print "testCalc.testYToMinusY" PySpectra.cls() PySpectra.delete() scan = PySpectra.Scan( name = "t1", xMin = 2., xMax = 10.0, nPts = 201) scan.y = np.sin( scan.y) with self.assertRaises( ValueError) as context: calc.yToMinusY( name = None) #print("testSetXY: %s" % repr( context.exception)) self.assertTrue( "calc.yToMinusY: name not specified" in context.exception) with self.assertRaises( ValueError) as context: calc.yToMinusY( name = "notExist") #print("testSetXY: %s" % repr( context.exception)) self.assertTrue( "calc.yToMinusY: failed to find notExist" in context.exception) scanMY = calc.yToMinusY( name = scan.name, nameNew = "t1_y2MinusY") self.assertEqual( len( scan.y), len( scanMY.y)) self.assertEqual( len( scan.x), len( scanMY.x)) for i in range( len( scan.y)): self.assertEqual( scan.y[i], - scanMY.y[i]) self.assertEqual( scan.x[i], scanMY.x[i]) PySpectra.display() #PySpectra.show() PySpectra.processEventsLoop( 1) print "testCalc.testYToMinusY, DONE"
def example_GaussAndSinusOverlay(): ''' overlay 2 scans ''' PySpectra.cls() PySpectra.delete() PySpectra.setTitle("2 Overlay Scans") PySpectra.setWsViewport("DINA5") g = utils.createGauss(name="gauss", xMin=-5., xMax=5., nPts=101, lineColor='red', x0=0., sigma=1., amplitude=1.) t1 = PySpectra.Scan(name="sinus", lineColor='blue', xMin=-5, xMax=5., yMin=-1.5, yMax=1.5, yLabel='sin') t1.y = np.sin(t1.x) PySpectra.overlay("sinus", "gauss") PySpectra.display()
def testAntiDerivative( self): print "testCalc.testAntiDerivative" PySpectra.cls() PySpectra.delete() scan = PySpectra.Scan( name = "t1", xMin = 0., xMax = 10.0, nPts = 201) scan.y = np.sin( scan.y) with self.assertRaises( ValueError) as context: calc.antiderivative( name = None) #print("testSetXY: %s" % repr( context.exception)) self.assertTrue( "calc.antiderivative: name not specified" in context.exception) with self.assertRaises( ValueError) as context: calc.derivative( name = "notExist") self.assertTrue( "calc.derivative: failed to find notExist" in context.exception) calc.antiderivative( name = scan.name, nameNew = "t1_ad") PySpectra.display() #PySpectra.show() PySpectra.processEventsLoop( 1) print "testCalc.testAntiDerivative, DONE"
def example_CreatePDF(): ''' create a pdf file ''' printer = os.getenv("PRINTER") if printer is None: print( "examplecreatePDF: environment variable PRINTER not defined, returning" ) return PySpectra.cls() PySpectra.delete() PySpectra.setTitle("Create PDF file and send it to the printer") PySpectra.setWsViewport("DINA5") scan = PySpectra.Scan(name='PDF Output', nPts=100, xMin=-1., xMax=1., xLabel='Position', yLabel="Counts") scan.y = np.sin(scan.x) PySpectra.setWsViewport("DINA4") PySpectra.display() PySpectra.createPDF(flagPrint=True) return
def testLissajous( self): ''' ''' print "testMplGrphics.testLissayous" PySpectra.mtpltlb.graphics.cls() PySpectra.mtpltlb.graphics.setWsViewport( "dinA6s") 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.mtpltlb.graphics.display() startTime = time.time() for i in range( 150): x = x + 0.005 scan.plotDataItem.setData(np.cos( x), np.sin( y)) PySpectra.mtpltlb.graphics.processEvents() diffTime = time.time() - startTime self.assertLess( diffTime, 6.) print "testMplGrphics.testLissajous, DONE"
def sl1(line): ''' create 1 scan ''' PySpectra.cls() PySpectra.delete() t1 = PySpectra.Scan( name = "t1", color = 'blue', yLabel = 'sin') t1.y = np.sin( t1.x)
def sl2(line): ''' scan list 1, creates some scans, fill them with data ''' PySpectra.cls() PySpectra.delete() t1 = PySpectra.Scan( name = "t1", color = 'blue', yLabel = 'sin') t1.y = np.sin( t1.x) t2 = PySpectra.Scan( "t2", yLabel = 'cos') t2.y = np.cos( t2.x) t3 = PySpectra.Scan( name = "t3", color = 'green', yLabel = 'tan') t3.y = np.tan( t3.x) t4 = PySpectra.Scan( name = "t4", color = 'cyan', yLabel = 'random') t4.y = np.random.random_sample( (len( t4.y), )) t5 = PySpectra.Scan( name = "t5", color = 'magenta', yLabel = 'x**2') t5.y = t5.x * t5.x PySpectra.overlay( 't5', 't3')
def test_titleAndComment(self): PySpectra.cls() PySpectra.delete() PySpectra.setTitle("a_title") self.assertEqual(PySpectra.getTitle(), "a_title") PySpectra.delete() self.assertEqual(PySpectra.getTitle(), None) PySpectra.setTitle("a_title") PySpectra.setTitle(None) self.assertEqual(PySpectra.getTitle(), None) PySpectra.delete() PySpectra.setComment("a_comment") self.assertEqual(PySpectra.getComment(), "a_comment") PySpectra.delete() self.assertEqual(PySpectra.getComment(), None) PySpectra.setComment("a_comment") PySpectra.setComment(None) self.assertEqual(PySpectra.getComment(), None) PySpectra.delete() PySpectra.setTitle("there must be this title") PySpectra.setComment("and there must be this comment") PySpectra.Scan("t1") PySpectra.display() PySpectra.show() PySpectra.processEventsLoop(1) PySpectra.cls() PySpectra.delete() PySpectra.setTitle("there is only a title, no comment") PySpectra.Scan("t1") PySpectra.display() PySpectra.processEventsLoop(1) PySpectra.cls() PySpectra.delete() PySpectra.setComment("there is only a comment") PySpectra.Scan("t1") PySpectra.display() PySpectra.processEventsLoop(1) print "testPySpectra.test_titleAndComment DONE"