PYME-extra 1.0.4.post0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. PYMEcs/Acquire/Actions/__init__.py +0 -0
  2. PYMEcs/Acquire/Actions/custom.py +167 -0
  3. PYMEcs/Acquire/Hardware/LPthreadedSimple.py +248 -0
  4. PYMEcs/Acquire/Hardware/LPthreadedSimpleSim.py +246 -0
  5. PYMEcs/Acquire/Hardware/NikonTiFlaskServer.py +45 -0
  6. PYMEcs/Acquire/Hardware/NikonTiFlaskServerT.py +59 -0
  7. PYMEcs/Acquire/Hardware/NikonTiRESTClient.py +73 -0
  8. PYMEcs/Acquire/Hardware/NikonTiSim.py +35 -0
  9. PYMEcs/Acquire/Hardware/__init__.py +0 -0
  10. PYMEcs/Acquire/Hardware/driftTrackGUI.py +329 -0
  11. PYMEcs/Acquire/Hardware/driftTrackGUI_n.py +472 -0
  12. PYMEcs/Acquire/Hardware/driftTracking.py +424 -0
  13. PYMEcs/Acquire/Hardware/driftTracking_n.py +433 -0
  14. PYMEcs/Acquire/Hardware/fakeCamX.py +15 -0
  15. PYMEcs/Acquire/Hardware/offsetPiezoRESTCorrelLog.py +38 -0
  16. PYMEcs/Acquire/__init__.py +0 -0
  17. PYMEcs/Analysis/MBMcollection.py +552 -0
  18. PYMEcs/Analysis/MINFLUX.py +280 -0
  19. PYMEcs/Analysis/MapUtils.py +77 -0
  20. PYMEcs/Analysis/NPC.py +1176 -0
  21. PYMEcs/Analysis/Paraflux.py +218 -0
  22. PYMEcs/Analysis/Simpler.py +81 -0
  23. PYMEcs/Analysis/Sofi.py +140 -0
  24. PYMEcs/Analysis/__init__.py +0 -0
  25. PYMEcs/Analysis/decSofi.py +211 -0
  26. PYMEcs/Analysis/eventProperties.py +50 -0
  27. PYMEcs/Analysis/fitDarkTimes.py +569 -0
  28. PYMEcs/Analysis/objectVolumes.py +20 -0
  29. PYMEcs/Analysis/offlineTracker.py +130 -0
  30. PYMEcs/Analysis/stackTracker.py +180 -0
  31. PYMEcs/Analysis/timeSeries.py +63 -0
  32. PYMEcs/Analysis/trackFiducials.py +186 -0
  33. PYMEcs/Analysis/zerocross.py +91 -0
  34. PYMEcs/IO/MINFLUX.py +851 -0
  35. PYMEcs/IO/NPC.py +117 -0
  36. PYMEcs/IO/__init__.py +0 -0
  37. PYMEcs/IO/darkTimes.py +19 -0
  38. PYMEcs/IO/picasso.py +219 -0
  39. PYMEcs/IO/tabular.py +11 -0
  40. PYMEcs/__init__.py +0 -0
  41. PYMEcs/experimental/CalcZfactor.py +51 -0
  42. PYMEcs/experimental/FRC.py +338 -0
  43. PYMEcs/experimental/ImageJROItools.py +49 -0
  44. PYMEcs/experimental/MINFLUX.py +1537 -0
  45. PYMEcs/experimental/NPCcalcLM.py +560 -0
  46. PYMEcs/experimental/Simpler.py +369 -0
  47. PYMEcs/experimental/Sofi.py +78 -0
  48. PYMEcs/experimental/__init__.py +0 -0
  49. PYMEcs/experimental/binEventProperty.py +187 -0
  50. PYMEcs/experimental/chaining.py +23 -0
  51. PYMEcs/experimental/clusterTrack.py +179 -0
  52. PYMEcs/experimental/combine_maps.py +104 -0
  53. PYMEcs/experimental/eventProcessing.py +93 -0
  54. PYMEcs/experimental/fiducials.py +323 -0
  55. PYMEcs/experimental/fiducialsNew.py +402 -0
  56. PYMEcs/experimental/mapTools.py +271 -0
  57. PYMEcs/experimental/meas2DplotDh5view.py +107 -0
  58. PYMEcs/experimental/mortensen.py +131 -0
  59. PYMEcs/experimental/ncsDenoise.py +158 -0
  60. PYMEcs/experimental/onTimes.py +295 -0
  61. PYMEcs/experimental/procPoints.py +77 -0
  62. PYMEcs/experimental/pyme2caml.py +73 -0
  63. PYMEcs/experimental/qPAINT.py +965 -0
  64. PYMEcs/experimental/randMap.py +188 -0
  65. PYMEcs/experimental/regExtraCmaps.py +11 -0
  66. PYMEcs/experimental/selectROIfilterTable.py +72 -0
  67. PYMEcs/experimental/showErrs.py +51 -0
  68. PYMEcs/experimental/showErrsDh5view.py +58 -0
  69. PYMEcs/experimental/showShiftMap.py +56 -0
  70. PYMEcs/experimental/snrEvents.py +188 -0
  71. PYMEcs/experimental/specLabeling.py +51 -0
  72. PYMEcs/experimental/splitRender.py +246 -0
  73. PYMEcs/experimental/testChannelByName.py +36 -0
  74. PYMEcs/experimental/timedSpecies.py +28 -0
  75. PYMEcs/experimental/utils.py +31 -0
  76. PYMEcs/misc/ExtraCmaps.py +177 -0
  77. PYMEcs/misc/__init__.py +0 -0
  78. PYMEcs/misc/configUtils.py +169 -0
  79. PYMEcs/misc/guiMsgBoxes.py +27 -0
  80. PYMEcs/misc/mapUtils.py +230 -0
  81. PYMEcs/misc/matplotlib.py +136 -0
  82. PYMEcs/misc/rectsFromSVG.py +182 -0
  83. PYMEcs/misc/shellutils.py +1110 -0
  84. PYMEcs/misc/utils.py +205 -0
  85. PYMEcs/misc/versionCheck.py +20 -0
  86. PYMEcs/misc/zcInfo.py +90 -0
  87. PYMEcs/pyme_warnings.py +4 -0
  88. PYMEcs/recipes/__init__.py +0 -0
  89. PYMEcs/recipes/base.py +75 -0
  90. PYMEcs/recipes/localisations.py +2380 -0
  91. PYMEcs/recipes/manipulate_yaml.py +83 -0
  92. PYMEcs/recipes/output.py +177 -0
  93. PYMEcs/recipes/processing.py +247 -0
  94. PYMEcs/recipes/simpler.py +290 -0
  95. PYMEcs/version.py +2 -0
  96. pyme_extra-1.0.4.post0.dist-info/METADATA +114 -0
  97. pyme_extra-1.0.4.post0.dist-info/RECORD +101 -0
  98. pyme_extra-1.0.4.post0.dist-info/WHEEL +5 -0
  99. pyme_extra-1.0.4.post0.dist-info/entry_points.txt +3 -0
  100. pyme_extra-1.0.4.post0.dist-info/licenses/LICENSE +674 -0
  101. pyme_extra-1.0.4.post0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,472 @@
1
+ #!/usr/bin/python
2
+
3
+ ##################
4
+ # <filename>.py
5
+ #
6
+ # Copyright David Baddeley, 2012
7
+ # d.baddeley@auckland.ac.nz
8
+ #
9
+ # This file may NOT be distributed without express permision from David Baddeley
10
+ #
11
+ ##################
12
+ import wx
13
+
14
+ import numpy as np
15
+ from PYME.contrib.wxPlotPanel import PlotPanel
16
+ from PYME.IO import MetaDataHandler
17
+ from PYME.DSView import dsviewer as dsviewer
18
+ import PYME.IO.image as im
19
+ from PYMEcs.pyme_warnings import warn
20
+
21
+ import os
22
+
23
+ import logging
24
+ logger = logging.getLogger(__name__)
25
+
26
+ class TrackerPlotPanel(PlotPanel):
27
+ def __init__(self, parent, driftTracker, *args, **kwargs):
28
+ self.dt = driftTracker
29
+ PlotPanel.__init__(self, parent, *args, **kwargs)
30
+
31
+ # add 5th suplot
32
+ # replace 4th plot with offset and
33
+ # new 5th subplot for z-pos (how calculated, z-nominal + dz?, remove offset)
34
+ def draw(self):
35
+ if self.IsShownOnScreen():
36
+ if not hasattr( self, 'subplotxy' ):
37
+ self.subplotxy = self.figure.add_subplot( 411 )
38
+ self.subplotz = self.figure.add_subplot( 412 )
39
+ self.subploto = self.figure.add_subplot( 413 )
40
+ self.subplotc = self.figure.add_subplot(414)
41
+ # hopefully this sets it always for this fig, see
42
+ # https://matplotlib.org/stable/tutorials/intermediate/tight_layout_guide.html
43
+ self.figure.set_tight_layout(True)
44
+
45
+ try:
46
+ t, dx_nm, dy_nm, dz_nm, corr, corrmax, poffset_nm, pos_um = np.array(self.dt.get_history(1000)).T
47
+ except ValueError:
48
+ do_plot = False
49
+ else:
50
+ do_plot = True
51
+
52
+ if do_plot:
53
+ # note: we now assume that all history values that are distances are provided in nm
54
+ # this SHOULD match the conventions in driftTracking.py
55
+
56
+ # a few reused variables
57
+ tolnm = 1e3*self.dt.get_focus_tolerance()
58
+ tdelta = t - self.dt.historyStartTime
59
+ trange = [tdelta.min(), tdelta.max()]
60
+
61
+ self.subplotxy.cla()
62
+ self.subplotxy.plot(tdelta, dx_nm, 'r')
63
+ self.subplotxy.plot(tdelta, dy_nm, 'g')
64
+ self.subplotxy.set_ylabel('dx/dy (r/g) [nm]')
65
+ self.subplotxy.set_xlim(*trange)
66
+
67
+ self.subplotz.cla()
68
+ self.subplotz.plot(tdelta, dz_nm, 'b')
69
+ self.subplotz.plot([tdelta[0],tdelta[-1]],[tolnm,tolnm], 'g--')
70
+ self.subplotz.plot([tdelta[0],tdelta[-1]],[-tolnm,-tolnm], 'g--')
71
+ self.subplotz.set_ylabel('dz [nm]')
72
+ self.subplotz.set_xlim(*trange)
73
+
74
+ self.subploto.cla()
75
+ self.subploto.plot(tdelta, poffset_nm, 'm')
76
+ self.subploto.set_ylabel('offs [nm]')
77
+ self.subploto.set_xlim(*trange)
78
+
79
+ self.subplotc.cla()
80
+ self.subplotc.plot(tdelta, corr/corrmax, 'r')
81
+ self.subplotc.set_ylabel('C/C_m')
82
+ self.subplotc.set_xlim(*trange)
83
+ self.subplotc.set_xlabel('Time (s)')
84
+
85
+ self.canvas.draw()
86
+
87
+
88
+ resx = []
89
+ resy = []
90
+ resz = []
91
+
92
+ class CalculateZfactorDialog(wx.Dialog):
93
+ def __init__(self):
94
+ self.Zfactorfilename = ''
95
+ wx.Dialog.__init__(self, None, -1, 'Calculate Z-factor')
96
+ sizer1 = wx.BoxSizer(wx.VERTICAL)
97
+
98
+ pan = wx.Panel(self, -1)
99
+ vsizermain = wx.BoxSizer(wx.VERTICAL)
100
+ vsizer = wx.BoxSizer(wx.VERTICAL)
101
+
102
+ hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
103
+ hsizer2.Add(wx.StaticText(pan, -1, ' Record a Z-stack with 101 slices & 50 nm step. Use the Z-stack to calculate the Z-factor'), 0, wx.ALL, 2)
104
+ vsizer.Add(hsizer2)
105
+
106
+ hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
107
+ self.bSelect = wx.Button(pan, -1, 'Select')
108
+ self.bSelect.Bind(wx.EVT_BUTTON, self.OnSelect)
109
+ hsizer2.Add(self.bSelect, 0, wx.ALL, 2)
110
+ self.bPlot = wx.Button(pan, -1, 'Plot')
111
+ self.bPlot.Bind(wx.EVT_BUTTON, self.OnPlot)
112
+ hsizer2.Add(self.bPlot, 0, wx.ALL, 2)
113
+ vsizer.Add(hsizer2)
114
+
115
+ self.textZstackFilename = wx.StaticText(pan, -1, 'Z-stack file: no file selected')
116
+ vsizer.Add(self.textZstackFilename, 0, wx.ALL, 2)
117
+
118
+ vsizermain.Add(vsizer, 0, 0, 0)
119
+
120
+ self.plotPan = ZFactorPlotPanel(pan, size=(1200,600))
121
+ vsizermain.Add(self.plotPan, 1, wx.EXPAND, 0)
122
+
123
+ pan.SetSizerAndFit(vsizermain)
124
+ sizer1.Add(pan, 1,wx.EXPAND, 0)
125
+ self.SetSizerAndFit(sizer1)
126
+
127
+ def OnSelect(self, event):
128
+ dlg = wx.FileDialog(self, message="Open a Z-stack Image...", defaultDir=os.getcwd(),
129
+ defaultFile="", style=wx.FD_OPEN)
130
+
131
+ if dlg.ShowModal() == wx.ID_OK:
132
+ self.Zfactorfilename = dlg.GetPath()
133
+
134
+ dlg.Destroy()
135
+ self.textZstackFilename.SetLabel('Z-stack file: '+self.Zfactorfilename)
136
+
137
+
138
+ def OnPlot(self, event):
139
+ import PYMEcs.Analysis.offlineTracker as otrack
140
+
141
+ ds = im.ImageStack(filename=self.Zfactorfilename)
142
+ dataset = ds.data[:,:,:].squeeze()
143
+ refim0 = dataset[:,:,10:91:4]
144
+ calImages0, calFTs0, dz0, dzn0, mask0, X0, Y0 = otrack.genRef(refim0,normalised=False)
145
+
146
+ del resx[:]
147
+ del resy[:]
148
+ del resz[:] # empty all these three lists every time before a new plot
149
+
150
+ for i in range(dataset.shape[2]):
151
+ image = dataset[:,:,i]
152
+ driftx, drifty, driftz, cm, d = otrack.compare(calImages0, calFTs0, dz0, dzn0, 10, image, mask0, X0, Y0, deltaZ=0.2)
153
+ resx.append(driftx)
154
+ resy.append(drifty)
155
+ resz.append(driftz)
156
+
157
+ self.plotPan.draw()
158
+ self.plotPan.Refresh()
159
+
160
+
161
+ class ZFactorPlotPanel(PlotPanel):
162
+
163
+ def draw(self):
164
+ dznm = 1e3*np.array(resz)
165
+ dxnm = 110*np.array(resx)
166
+ dynm = 110*np.array(resy)
167
+ t = np.arange(dznm.shape[0])
168
+
169
+ dzexp = dznm[50-4:50+5]
170
+ dztheo = np.arange(-200,201,50)
171
+ x = np.arange(-150,151,50)
172
+ y = dznm[50-3:50+4]
173
+ m, b = np.polyfit(x,y,1)
174
+ Zfactor = 1.0/m
175
+
176
+ if not hasattr( self, 'subplot' ):
177
+ self.subplot1 = self.figure.add_subplot( 121 )
178
+ self.subplot2 = self.figure.add_subplot( 122 )
179
+
180
+ self.subplot1.cla()
181
+
182
+ self.subplot1.scatter(t,-dznm,s=5)
183
+ self.subplot1.plot(-dznm, label='z')
184
+ self.subplot1.plot(-dxnm, label='x')
185
+ self.subplot1.plot(-dynm, label='y')
186
+
187
+ self.subplot1.grid()
188
+ self.subplot1.legend()
189
+
190
+ self.subplot2.cla()
191
+
192
+ self.subplot2.plot(dztheo,dzexp,'-o')
193
+ self.subplot2.plot(dztheo,1.0/Zfactor*dztheo,'--')
194
+ font = {'family': 'serif',
195
+ 'color': 'darkred',
196
+ 'weight': 'normal',
197
+ 'size': 16,
198
+ }
199
+ self.subplot2.text(-50, 100, 'Z-factor = %3.1f' % Zfactor, fontdict=font)
200
+ self.subplot2.grid()
201
+
202
+ self.canvas.draw()
203
+
204
+ from PYME.DSView import overlays
205
+ import weakref
206
+ class DriftROIOverlay(overlays.Overlay):
207
+ def __init__(self, driftTracker):
208
+ self.dt = driftTracker
209
+
210
+ def __call__(self, view, dc):
211
+ if self.dt.sub_roi is not None:
212
+ dc.SetPen(wx.Pen(colour=wx.CYAN, width=1))
213
+ dc.SetBrush(wx.TRANSPARENT_BRUSH)
214
+ x0, x1, y0, y1 = self.dt.sub_roi
215
+ x0c, y0c = view.pixel_to_screen_coordinates(x0, y0)
216
+ x1c, y1c = view.pixel_to_screen_coordinates(x1, y1)
217
+ sX, sY = x1c-x0c, y1c-y0c
218
+ dc.DrawRectangle(int(x0c), int(y0c), int(sX), int(sY))
219
+ dc.SetPen(wx.NullPen)
220
+ else:
221
+ dc.SetBackground(wx.TRANSPARENT_BRUSH)
222
+ dc.Clear()
223
+
224
+ from PYME.recipes.traits import HasTraits, Float, Enum, CStr, Bool, Int, List
225
+ class DriftTrackConfig(HasTraits):
226
+ zfocusTolerance_nm = Float(50.0,label='ZFocus tolerance in nm',
227
+ desc="when moving outside of the focus tolerance the z piezo will counteract")
228
+ deltaZ_nm = Float(200,desc='spacing between the planes during recording of the calibration stack in nm',
229
+ label='Z plane spacing in nm')
230
+ stackHalfSize = Int(35,label='Stack Half Size',
231
+ desc='number of planes either side of the focal plane that are recorded for calibration')
232
+ minDelay = Int(10,label='minimum delay in frames',
233
+ desc='minimum delay time in frames between corrections')
234
+ zFactor = Float(1.0,label='z correction factor',
235
+ desc='z correction factor to match physical movement to sensed z movement')
236
+ plotInterval = Int(10,label='plot interval in frames',
237
+ desc='interval at which the plots are updated, in units of frames')
238
+
239
+ from PYMEcs.Acquire.Hardware.driftTracking_n import State
240
+ class DriftTrackingControl(wx.Panel):
241
+ def __init__(self, main_frame, driftTracker, winid=-1, showPlots=True):
242
+ ''' This class provides a GUI for controlling the drift tracking system.
243
+
244
+ It should be initialised with a reference to the PYMEAcquire main frame, which will stand in as a parent while other GUI items are
245
+ created. Note that the actual parent will be reassigned once the GUI tool panel is created using a Reparent() call.
246
+ '''
247
+ wx.Panel.__init__(self, main_frame, winid)
248
+
249
+ main_frame.AddMenuItem('DriftTracking', "Change config parameters", self.OnDriftTrackConfig)
250
+ main_frame.AddMenuItem('DriftTracking', "Save history", self.OnBSaveHist)
251
+ main_frame.AddMenuItem('DriftTracking', "Save calibration stack", self.OnBSaveCalib)
252
+ main_frame.AddMenuItem('DriftTracking', "Calculate z factor", self.OnBCalculateZfactor)
253
+
254
+ self.dt = driftTracker
255
+ self.dtconfig = DriftTrackConfig(zfocusTolerance_nm=1e3*self.dt.focusTolerance,
256
+ deltaZ_nm=1e3*self.dt.deltaZ,
257
+ stackHalfSize=self.dt.stackHalfSize)
258
+ self.plotInterval = 10
259
+ self.showPlots = showPlots
260
+
261
+ # keep a reference to the main frame. Do this as a weakref to avoid circular references.
262
+ # we need this to be able to access the view to get the current selection and to add overlays.
263
+ self._main_frame = weakref.proxy(main_frame)
264
+ self._view_overlay = None # dummy reference to the overlay so we only create it once
265
+
266
+ sizer_1 = wx.BoxSizer(wx.VERTICAL)
267
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
268
+
269
+ self.cbTrack = wx.CheckBox(self, -1, 'Track')
270
+ hsizer.Add(self.cbTrack, 0, wx.ALL, 2)
271
+ self.cbTrack.Bind(wx.EVT_CHECKBOX, self.OnCBTrack)
272
+ self.cbLock = wx.CheckBox(self, -1, 'Lock')
273
+ self.cbLock.Bind(wx.EVT_CHECKBOX, self.OnCBLock)
274
+ hsizer.Add(self.cbLock, 0, wx.ALL, 2)
275
+ self.cbLockActive = wx.CheckBox(self, -1, 'Lock Active')
276
+ self.cbLockActive.Enable(False)
277
+ hsizer.Add(self.cbLockActive, 0, wx.ALL, 2)
278
+ sizer_1.Add(hsizer, 0, wx.EXPAND, 0)
279
+
280
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
281
+ self.bSetPostion = wx.Button(self, -1, 'Set focus to current')
282
+ hsizer.Add(self.bSetPostion, 0, wx.ALL, 2)
283
+ self.bSetPostion.Bind(wx.EVT_BUTTON, self.OnBSetPostion)
284
+ sizer_1.Add(hsizer, 0, wx.EXPAND, 0)
285
+
286
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
287
+ self.tbSubROI = wx.ToggleButton(self, -1, 'Restrict to sub-ROI')
288
+ hsizer.Add(self.tbSubROI, 0, wx.ALL, 2)
289
+ self.tbSubROI.Bind(wx.EVT_TOGGLEBUTTON, self.OnTBToggleSubROI)
290
+ sizer_1.Add(hsizer, 0, wx.EXPAND, 0)
291
+
292
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
293
+ hsizer.Add(wx.StaticText(self, -1, "Calibration:"), 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 2)
294
+ self.gCalib = wx.Gauge(self, -1, 11)
295
+ hsizer.Add(self.gCalib, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 2)
296
+ self.stCalibState = wx.StaticText(self, -1, "UNCALIBRATED")
297
+ hsizer.Add(self.stCalibState, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 2) # second arg 0 or 1?
298
+ sizer_1.Add(hsizer, 0, wx.EXPAND, 0)
299
+
300
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
301
+ self.stConfig = wx.StaticText(self, -1,
302
+ 'tol: %d nm, delZ: %.0f nm, stHsz: %d' %
303
+ (self.dtconfig.zfocusTolerance_nm,
304
+ self.dtconfig.deltaZ_nm,
305
+ self.dtconfig.stackHalfSize), size=[400,-1])
306
+ cfont = self.stConfig.GetFont()
307
+ font = wx.Font(cfont.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
308
+ self.stConfig.SetFont(font)
309
+ hsizer.Add(self.stConfig, 0, wx.ALL, 2)
310
+ sizer_1.Add(hsizer,0, wx.EXPAND, 0)
311
+
312
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
313
+ self.stError = wx.StaticText(self, -1, 'Error:\n\n', size=[200,-1])
314
+ cfont = self.stError.GetFont()
315
+ font = wx.Font(cfont.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
316
+ self.stError.SetFont(font)
317
+ hsizer.Add(self.stError, 0, wx.ALL, 2)
318
+ sizer_1.Add(hsizer,0, wx.EXPAND, 0)
319
+
320
+ if self.showPlots:
321
+ self.trackPlot = TrackerPlotPanel(self, self.dt, size=[300, 500])
322
+
323
+ #hsizer.Add(self.stError, 0, wx.ALL, 2)
324
+ sizer_1.Add(self.trackPlot,0, wx.EXPAND, 0)
325
+
326
+ self.SetAutoLayout(1)
327
+ self.SetSizer(sizer_1)
328
+ sizer_1.Fit(self)
329
+ sizer_1.SetSizeHints(self)
330
+ self.Layout()
331
+ # end wxGlade
332
+
333
+ def OnCBTrack(self, event):
334
+ #print self.cbTrack.GetValue()
335
+ if self.cbTrack.GetValue():
336
+ self.dt.register()
337
+ else:
338
+ self.dt.deregister()
339
+
340
+ def OnBSetPostion(self, event):
341
+ self.dt.reCalibrate()
342
+
343
+ def OnTBToggleSubROI(self, event):
344
+ self.toggle_subroi(self.tbSubROI.GetValue())
345
+
346
+ def toggle_subroi(self, new_state=True):
347
+ ''' Turn sub-ROI tracking on or off, using the current selection in the live image display'''
348
+ if new_state:
349
+ x0, x1, y0, y1, _, _ = self._main_frame.view.do.sorted_selection
350
+ self.dt.set_subroi((x0, x1, y0, y1))
351
+ else:
352
+ self.dt.set_subroi(None)
353
+
354
+ if self._view_overlay is None:
355
+ self._view_overlay = self._main_frame.view.add_overlay(DriftROIOverlay(self.dt), 'Drift tracking Sub-ROI')
356
+
357
+ def OnBSaveCalib(self, event):
358
+ if not hasattr(self.dt, 'state') or (self.dt.state != State.CALIBRATED):
359
+ warn("not in a calibrated state (state is %s), cannot save" % self.dt.state)
360
+ else:
361
+ self.showCalImages()
362
+
363
+ def showCalImages(self):
364
+ import numpy as np
365
+ import time
366
+ ds2 = self.dt.refImages
367
+
368
+ #metadata handling
369
+ mdh = MetaDataHandler.NestedClassMDHandler()
370
+ mdh.setEntry('StartTime', time.time())
371
+ mdh.setEntry('AcquisitionType', 'Stack')
372
+
373
+ #loop over all providers of metadata
374
+ for mdgen in MetaDataHandler.provideStartMetadata:
375
+ mdgen(mdh)
376
+ mdh.setEntry('CalibrationPositions',self.dt.calPositions)
377
+
378
+ im = dsviewer.ImageStack(data = ds2, mdh = mdh, titleStub='Unsaved Image')
379
+ if not im.mode == 'graph':
380
+ im.mode = 'lite'
381
+
382
+ #print im.mode
383
+ dvf = dsviewer.DSViewFrame(im, mode= im.mode, size=(500, 500))
384
+ dvf.SetSize((500,500))
385
+ dvf.Show()
386
+
387
+ def OnBSaveHist(self, event):
388
+ if not hasattr(self.dt, 'history') or (len(self.dt.history) <= 0):
389
+ warn("no history that could be saved")
390
+ else:
391
+ dlg = wx.FileDialog(self, message="Save file as...",
392
+ defaultFile='history.txt',
393
+ wildcard='txt File (*.txt)|*.txt',
394
+ style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
395
+
396
+ if dlg.ShowModal() == wx.ID_OK:
397
+ historyfn = dlg.GetPath()
398
+ np.savetxt(historyfn, self.dt.history, header=' '.join(self.dt.historyColNames))
399
+ dlg = wx.MessageDialog(self._main_frame, "history saved", "Info", wx.OK | wx.ICON_INFORMATION)
400
+ dlg.ShowModal()
401
+ dlg.Destroy()
402
+
403
+
404
+ def OnDriftTrackConfig(self, event):
405
+ if not self.dtconfig.configure_traits(kind='modal'):
406
+ return
407
+ dtc = self.dtconfig
408
+ self.dt.set_focus_tolerance(1e-3*dtc.zfocusTolerance_nm)
409
+ self.dt.set_delta_Z(1e-3*dtc.deltaZ_nm)
410
+ self.dt.set_stack_halfsize(dtc.stackHalfSize)
411
+ self.dt.minDelay = dtc.minDelay
412
+ self.dt.Zfactor = dtc.zFactor
413
+ self.plotInterval = dtc.plotInterval
414
+
415
+ self.stConfig.SetLabel('tol: %d nm, delZ: %.0f nm, stHsz: %d' %
416
+ (dtc.zfocusTolerance_nm,
417
+ dtc.deltaZ_nm,
418
+ dtc.stackHalfSize))
419
+
420
+ def OnBSetTolerance(self, event):
421
+ self.dt.set_focus_tolerance(float(self.tTolerance.GetValue())/1e3)
422
+
423
+ def OnBSetdeltaZ(self, event):
424
+ self.dt.set_delta_Z(float(self.tdeltaZ.GetValue())/1e3)
425
+
426
+ def OnBSetHalfsize(self, event):
427
+ self.dt.set_stack_halfsize(int(self.tHalfsize.GetValue()))
428
+
429
+ def OnBSetZfactor(self, event):
430
+ self.dt.Zfactor = float(self.tZfactor.GetValue())
431
+
432
+ def OnBCalculateZfactor(self, event):
433
+ dlg = CalculateZfactorDialog()
434
+ ret = dlg.ShowModal()
435
+ dlg.Destroy()
436
+
437
+ def OnBSetMinDelay(self, event):
438
+ self.dt.minDelay = int(self.tMinDelay.GetValue())
439
+
440
+ def OnBSetPlotInterval(self, event):
441
+ self.plotInterval = int(self.tPlotInterval.GetValue())
442
+
443
+ def OnCBLock(self, event):
444
+ self.dt.set_focus_lock(self.cbLock.GetValue())
445
+
446
+ def refresh(self):
447
+ try:
448
+ calibState, NCalibFrames, calibCurFrame = self.dt.get_calibration_progress()
449
+ self.gCalib.SetRange(int(NCalibFrames)) # needs to be int?
450
+ self.gCalib.SetValue(int(calibCurFrame)) # needs to be int?
451
+ self.stCalibState.SetLabel(calibState.name)
452
+
453
+ try:
454
+ t, dx_nm, dy_nm, dz_nm, corr, corrmax, poffset_nm, pos_um = self.dt.get_history(1)[-1]
455
+ self.stError.SetLabel(("Error: x = %s nm y = %s nm z = %s nm\n" +
456
+ "offs = %s nm c/cm = %4.2f") %
457
+ ("{:>+3.2f}".format(dx_nm), "{:>+3.2f}".format(dy_nm),
458
+ "{:>+3.1f}".format(dz_nm), "{:>+6.1f}".format(poffset_nm),
459
+ corr/corrmax))
460
+
461
+ except IndexError:
462
+ pass
463
+
464
+ self.cbLock.SetValue(self.dt.get_focus_lock())
465
+ self.cbTrack.SetValue(self.dt.is_tracking())
466
+ self.cbLockActive.SetValue(self.dt.lockActive)
467
+
468
+ if (len(self.dt.get_history(0)) > 0) and (len(self.dt.get_history(0)) % self.plotInterval == 0) and self.showPlots:
469
+ self.trackPlot.draw()
470
+ except (AttributeError, IndexError):
471
+ logger.exception('error in refresh')
472
+ pass