|
| 1 | +from snAPI.Main import * |
| 2 | +import matplotlib |
| 3 | + |
| 4 | +matplotlib.use("TkAgg", force=True) |
| 5 | +from matplotlib import pyplot as plt |
| 6 | + |
| 7 | +if __name__ == "__main__": |
| 8 | + |
| 9 | + sn = snAPI() |
| 10 | + sn.getDevice("1000509") |
| 11 | + sn.initDevice(MeasMode.T2) |
| 12 | + |
| 13 | + sn.loadIniConfig(r"config\HH500.ini") |
| 14 | + |
| 15 | + history_size = 1 |
| 16 | + sn.setLogLevel(LogLevel.DataFile, True) |
| 17 | + sn.timeTrace.setNumBins(10000) |
| 18 | + sn.timeTrace.setHistorySize(history_size) |
| 19 | + |
| 20 | + |
| 21 | + # set Marker (1..4) |
| 22 | + sn.device.setMarkerEdges(1, 0, 0, 0) |
| 23 | + sn.device.setMarkerEnable(1, 1, 1, 0) |
| 24 | + |
| 25 | + # set Image Tag |
| 26 | + sn.setMeasurementSubMode(subMode=MeasSubMode.Image) |
| 27 | + # Marker (1) in TTTR stream defining a line start |
| 28 | + sn.addIntTag("ImgHdr_LineStart", 1) |
| 29 | + # Marker (2) in TTTR stream defining a line start |
| 30 | + sn.addIntTag("ImgHdr_LineStop", 2) |
| 31 | + # Marker (3) in TTTR stream defining a frame change |
| 32 | + sn.addIntTag("ImgHdr_Frame", 3) |
| 33 | + |
| 34 | + # Dimension of the measurement: 1 = Point; 2 = Line; 3 = Image; 4 = Stack |
| 35 | + sn.addIntTag("ImgHdr_Dimensions", 3) |
| 36 | + |
| 37 | + # Identifies the scanner hardware: |
| 38 | + # (1 = PI E-710; 3 = LSM; 5 = PI Line WBS; 6 = PI E-725; 7 = PI E-727; 8 = MCL; 9 = FLIMBee; 10 = ScanBox) |
| 39 | + #sn.addIntTag("ImgHdr_Ident", 3) |
| 40 | + |
| 41 | + # Scan direction, defining the configuration of fast and slowscan axis |
| 42 | + # First Axis = Fast Scan axis, Second Axis = SlowAxis |
| 43 | + # PI_SCANMODE_XY(0) = X-Y Scan (default) |
| 44 | + # PI_SCANMODE_XZ(1) = X-Z Scan |
| 45 | + # PI_SCANMODE_YZ(2) = Y-Z Scan |
| 46 | + #sn.addIntTag("ImgHdr_ScanDirection", 0) |
| 47 | + |
| 48 | + # Scan pattern: |
| 49 | + # TRUE identifies bidirectional scanning |
| 50 | + # 1st line forward scan |
| 51 | + # 2nd line backward scan |
| 52 | + # 3rd line forward |
| 53 | + # 4th line backward; ...) |
| 54 | + # FALSE identifies monodirectional scanning (all lines forward - default) |
| 55 | + #sn.addBoolTag("ImgHdr_BiDirect", False) |
| 56 | + |
| 57 | + # If > 0, the image was recorded using a sinuidal instead of a linear movement |
| 58 | + # Value represents percentage of the sinus wave used for the measurement (0-100%) |
| 59 | + # (default: 0) |
| 60 | + #sn.addIntTag("ImgHdr_SinCorrection", 0) |
| 61 | + |
| 62 | + # [ms] |
| 63 | + # Integration time per pixel for image measurements |
| 64 | + sn.addIntTag("ImgHdr_TimePerPixel", 20) |
| 65 | + |
| 66 | + # [µm] |
| 67 | + # X, Y, Z Position of measurement (interpretation depends on ImgHdr_Dimensions |
| 68 | + # for point measurements: the coordinate of measurement |
| 69 | + # for line: the start point |
| 70 | + # for images: the offset of the upper left edge of the image) |
| 71 | + sn.addFloatTag("ImgHdr_X0", 0.0) |
| 72 | + sn.addFloatTag("ImgHdr_Y0", 0.0) |
| 73 | + sn.addFloatTag("ImgHdr_Z0", 0.0) |
| 74 | + |
| 75 | + # Number of pixels in the fast scan direction (for image measurements) |
| 76 | + sn.addIntTag("ImgHdr_PixX", 256) |
| 77 | + # Number of pixels in the slow scan direction (for image measurements) |
| 78 | + sn.addIntTag("ImgHdr_PixY", 256) |
| 79 | + # [µm]; Resolution of a single pixel (line and image measurements) |
| 80 | + sn.addFloatTag("ImgHdr_PixResol", 1.0) |
| 81 | + |
| 82 | + #sn.addIntTag("TestInt", 9223372036854775807, 123) |
| 83 | + #sn.addFloatArrayTag("TestFloatArray", [1.1, 2.3, 3.3, 4.4]) |
| 84 | + #sn.addByteArrayTag("TestIntArray", [0,1,2,3,4,0,0,0]) |
| 85 | + |
| 86 | + # set the file name |
| 87 | + sn.setPTUFilePath("out.ptu") |
| 88 | + |
| 89 | + sn.timeTrace.measure(int(history_size * 1e3), waitFinished=False, savePTU=True) |
| 90 | + ft = 0 |
| 91 | + while True: |
| 92 | + finished = sn.timeTrace.isFinished() |
| 93 | + #if finished: |
| 94 | + # sn.timeTrace.t0.value = 0 |
| 95 | + counts, times = sn.timeTrace.getData() |
| 96 | + plt.clf() |
| 97 | + |
| 98 | + plt.plot(times, counts[0], linewidth=2.0, label="sync") |
| 99 | + for c in range(1, 1 + sn.deviceConfig["NumChans"]): |
| 100 | + plt.plot(times, counts[c], linewidth=2.0, label=f"chan{c}") |
| 101 | + plt.grid() |
| 102 | + plt.xlabel("Time [s]") |
| 103 | + plt.ylabel("Counts[Cts/s]") |
| 104 | + plt.yscale('log', base=10, nonpositive='clip') |
| 105 | + plt.legend() |
| 106 | + plt.title("TimeTrace") |
| 107 | + plt.pause(0.1) |
| 108 | + |
| 109 | + if finished: |
| 110 | + ft+=1 |
| 111 | + if ft > 10: |
| 112 | + break |
| 113 | + |
| 114 | + plt.show(block=True) |
| 115 | + plt.close() |
0 commit comments