microeye 2.3.2__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.
- microEye/__init__.py +47 -0
- microEye/_version.py +2 -0
- microEye/analysis/__init__.py +1 -0
- microEye/analysis/checklist_dialog.py +143 -0
- microEye/analysis/cmosMaps.py +228 -0
- microEye/analysis/filters/__init__.py +9 -0
- microEye/analysis/filters/base.py +21 -0
- microEye/analysis/filters/spatial.py +338 -0
- microEye/analysis/filters/temporal.py +76 -0
- microEye/analysis/fitting/__init__.py +0 -0
- microEye/analysis/fitting/fit.py +680 -0
- microEye/analysis/fitting/nena.py +375 -0
- microEye/analysis/fitting/phasor_fit.py +90 -0
- microEye/analysis/fitting/processing.py +317 -0
- microEye/analysis/fitting/psf/__init__.py +6 -0
- microEye/analysis/fitting/psf/extract.py +1129 -0
- microEye/analysis/fitting/psf/rubost_mean.py +150 -0
- microEye/analysis/fitting/psf/spline.py +167 -0
- microEye/analysis/fitting/psf/stats/__init__.py +12 -0
- microEye/analysis/fitting/psf/stats/core.py +295 -0
- microEye/analysis/fitting/psf/stats/curve_fit.py +708 -0
- microEye/analysis/fitting/psf/stats/io.py +104 -0
- microEye/analysis/fitting/psf/stats/slope_fit.py +171 -0
- microEye/analysis/fitting/psf/temp.py +147 -0
- microEye/analysis/fitting/psf/test.py +47 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUfunctions.py +657 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUmleFit_LM.py +1336 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUsplineLib.py +270 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/__init__.py +1 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUfunctions.py +609 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_EMCCD.py +1396 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_sCMOS.py +1426 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUsplineLib.py +231 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/__init__.py +2 -0
- microEye/analysis/fitting/pyfit3Dcspline/__init__.py +10 -0
- microEye/analysis/fitting/pyfit3Dcspline/constants.py +27 -0
- microEye/analysis/fitting/pyfit3Dcspline/mainfunctions.py +903 -0
- microEye/analysis/fitting/results.py +917 -0
- microEye/analysis/fitting/results_stats.py +251 -0
- microEye/analysis/fitting/tardis.py +209 -0
- microEye/analysis/multi_viewer.py +568 -0
- microEye/analysis/processing/__init__.py +1 -0
- microEye/analysis/processing/frc.py +120 -0
- microEye/analysis/rendering/__init__.py +3 -0
- microEye/analysis/rendering/base.py +452 -0
- microEye/analysis/rendering/cloud.py +215 -0
- microEye/analysis/rendering/core.py +47 -0
- microEye/analysis/rendering/volumetric.py +198 -0
- microEye/analysis/tools/__init__.py +0 -0
- microEye/analysis/tools/kymograms.py +1079 -0
- microEye/analysis/tools/roi_selectors.py +556 -0
- microEye/analysis/utils/__init__.py +3 -0
- microEye/analysis/utils/coordinates.py +18 -0
- microEye/analysis/utils/images.py +68 -0
- microEye/analysis/utils/windows.py +19 -0
- microEye/analysis/viewer/__init__.py +3 -0
- microEye/analysis/viewer/image_options_widget.py +615 -0
- microEye/analysis/viewer/images.py +1225 -0
- microEye/analysis/viewer/layers_widget.py +415 -0
- microEye/analysis/viewer/localizations.py +1304 -0
- microEye/analysis/viewer/psf.py +1003 -0
- microEye/analysis/viewer/volume.py +456 -0
- microEye/hardware/__init__.py +3 -0
- microEye/hardware/cams/__init__.py +29 -0
- microEye/hardware/cams/camera_calibration.py +99 -0
- microEye/hardware/cams/camera_list.py +528 -0
- microEye/hardware/cams/camera_options.py +694 -0
- microEye/hardware/cams/camera_panel.py +941 -0
- microEye/hardware/cams/dummy/__init__.py +1 -0
- microEye/hardware/cams/dummy/dummy_panel.py +759 -0
- microEye/hardware/cams/jobs.py +497 -0
- microEye/hardware/cams/line_profiler.py +99 -0
- microEye/hardware/cams/linescan/IR_Cam.py +474 -0
- microEye/hardware/cams/linescan/__init__.py +1 -0
- microEye/hardware/cams/micam.py +524 -0
- microEye/hardware/cams/pco/__init__.py +58 -0
- microEye/hardware/cams/pco/enums.py +382 -0
- microEye/hardware/cams/pco/pco_cam.py +761 -0
- microEye/hardware/cams/pco/pco_panel.py +477 -0
- microEye/hardware/cams/shortcuts.py +312 -0
- microEye/hardware/cams/thorlabs/__init__.py +1 -0
- microEye/hardware/cams/thorlabs/thorlabs.py +1508 -0
- microEye/hardware/cams/thorlabs/thorlabs_panel.py +850 -0
- microEye/hardware/cams/ueye/__init__.py +1 -0
- microEye/hardware/cams/ueye/ueye_camera.py +1023 -0
- microEye/hardware/cams/ueye/ueye_panel.py +861 -0
- microEye/hardware/cams/vimba/__init__.py +1 -0
- microEye/hardware/cams/vimba/vimba_cam.py +1000 -0
- microEye/hardware/cams/vimba/vimba_panel.py +813 -0
- microEye/hardware/device.py +60 -0
- microEye/hardware/lasers/__init__.py +13 -0
- microEye/hardware/lasers/io_matchbox.py +791 -0
- microEye/hardware/lasers/io_params.py +85 -0
- microEye/hardware/lasers/io_single_laser.py +742 -0
- microEye/hardware/lasers/laser_relay.py +594 -0
- microEye/hardware/mieye/__init__.py +1 -0
- microEye/hardware/mieye/acquisition_manager.py +467 -0
- microEye/hardware/mieye/devices_manager.py +533 -0
- microEye/hardware/mieye/miEye.py +659 -0
- microEye/hardware/misc/__init__.py +0 -0
- microEye/hardware/misc/acquisition_view.py +71 -0
- microEye/hardware/misc/reglo.py +761 -0
- microEye/hardware/misc/temp.py +188 -0
- microEye/hardware/port_config.py +59 -0
- microEye/hardware/protocols/__init__.py +2 -0
- microEye/hardware/protocols/actions.py +402 -0
- microEye/hardware/protocols/actions_items.py +703 -0
- microEye/hardware/protocols/designer.py +244 -0
- microEye/hardware/protocols/scene_manager.py +191 -0
- microEye/hardware/protocols/serialization.py +97 -0
- microEye/hardware/pycromanager/__init__.py +16 -0
- microEye/hardware/pycromanager/core.py +1433 -0
- microEye/hardware/pycromanager/devices.py +461 -0
- microEye/hardware/pycromanager/enums.py +107 -0
- microEye/hardware/pycromanager/headless.py +153 -0
- microEye/hardware/pycromanager/utils.py +34 -0
- microEye/hardware/pycromanager/widgets/__init__.py +5 -0
- microEye/hardware/pycromanager/widgets/bridges.py +407 -0
- microEye/hardware/pycromanager/widgets/headless_manager.py +258 -0
- microEye/hardware/pycromanager/widgets/headless_options.py +224 -0
- microEye/hardware/pycromanager/widgets/pycro_panel.py +455 -0
- microEye/hardware/stages/__init__.py +18 -0
- microEye/hardware/stages/elliptec/__init__.py +5 -0
- microEye/hardware/stages/elliptec/baseDevice.py +314 -0
- microEye/hardware/stages/elliptec/device.py +384 -0
- microEye/hardware/stages/elliptec/deviceID.py +212 -0
- microEye/hardware/stages/elliptec/devicePort.py +379 -0
- microEye/hardware/stages/elliptec/deviceStatus.py +65 -0
- microEye/hardware/stages/elliptec/devicesView.py +706 -0
- microEye/hardware/stages/elliptec/ellDevices.py +134 -0
- microEye/hardware/stages/elliptec/messageUpdater.py +34 -0
- microEye/hardware/stages/elliptec/motorInfo.py +153 -0
- microEye/hardware/stages/elliptec/stage.py +62 -0
- microEye/hardware/stages/elliptec/test.py +139 -0
- microEye/hardware/stages/kinesis/__init__.py +1 -0
- microEye/hardware/stages/kinesis/kdc101/__init__.py +1 -0
- microEye/hardware/stages/kinesis/kdc101/enums.py +1002 -0
- microEye/hardware/stages/kinesis/kdc101/factory.py +171 -0
- microEye/hardware/stages/kinesis/kdc101/kdc101.py +718 -0
- microEye/hardware/stages/kinesis/kinesis.py +776 -0
- microEye/hardware/stages/piezo_concept.py +607 -0
- microEye/hardware/stages/stabilizer.py +785 -0
- microEye/hardware/stages/stage.py +89 -0
- microEye/hardware/widgets/__init__.py +10 -0
- microEye/hardware/widgets/controller.py +246 -0
- microEye/hardware/widgets/devices.py +133 -0
- microEye/hardware/widgets/focusWidget.py +264 -0
- microEye/hardware/widgets/qlist_slider.py +113 -0
- microEye/hardware/widgets/scan_acquisition.py +424 -0
- microEye/icons/1024.png +0 -0
- microEye/icons/128.png +0 -0
- microEye/icons/16.png +0 -0
- microEye/icons/24.png +0 -0
- microEye/icons/256.png +0 -0
- microEye/icons/32.png +0 -0
- microEye/icons/48.png +0 -0
- microEye/icons/512.png +0 -0
- microEye/icons/64.png +0 -0
- microEye/icons/__init__.py +0 -0
- microEye/icons/close.svg +88 -0
- microEye/icons/mieye.png +0 -0
- microEye/icons/min.svg +83 -0
- microEye/icons/viewer.png +0 -0
- microEye/launcher.py +42 -0
- microEye/qt.py +181 -0
- microEye/utils/__init__.py +2 -0
- microEye/utils/enum_encoder.py +10 -0
- microEye/utils/expandable_groupbox.py +93 -0
- microEye/utils/gui_helper.py +457 -0
- microEye/utils/hid/__init__.py +8 -0
- microEye/utils/hid/controller.py +153 -0
- microEye/utils/hid/device.py +63 -0
- microEye/utils/hid/enums.py +140 -0
- microEye/utils/hid/utils.py +58 -0
- microEye/utils/labelled_slider.py +134 -0
- microEye/utils/metadata.py +599 -0
- microEye/utils/metadata_tree.py +718 -0
- microEye/utils/micro_launcher.py +245 -0
- microEye/utils/parameter_tree.py +325 -0
- microEye/utils/pyscripting.py +444 -0
- microEye/utils/retry_exec.py +35 -0
- microEye/utils/start_gui.py +112 -0
- microEye/utils/thread_worker.py +115 -0
- microEye/utils/uImage.py +1512 -0
- microeye-2.3.2.dist-info/METADATA +401 -0
- microeye-2.3.2.dist-info/RECORD +190 -0
- microeye-2.3.2.dist-info/WHEEL +5 -0
- microeye-2.3.2.dist-info/entry_points.txt +2 -0
- microeye-2.3.2.dist-info/licenses/LICENSE +674 -0
- microeye-2.3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
import numba as nb
|
|
5
|
+
import numpy as np
|
|
6
|
+
import pyqtgraph as pg
|
|
7
|
+
from skimage.registration import phase_cross_correlation
|
|
8
|
+
from sklearn.neighbors import NearestNeighbors
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@nb.njit(
|
|
12
|
+
nb.types.Tuple((nb.int64, nb.int64[:], nb.int64[:], nb.float64[:]))(
|
|
13
|
+
nb.float64[:, :],
|
|
14
|
+
nb.float64[:, :],
|
|
15
|
+
nb.int64[:],
|
|
16
|
+
nb.int64[:],
|
|
17
|
+
nb.float64[:],
|
|
18
|
+
nb.int64,
|
|
19
|
+
nb.float64,
|
|
20
|
+
nb.float64,
|
|
21
|
+
nb.int64,
|
|
22
|
+
),
|
|
23
|
+
parallel=True,
|
|
24
|
+
cache=True,
|
|
25
|
+
)
|
|
26
|
+
def nn_trajectories(
|
|
27
|
+
currentFrame: np.ndarray,
|
|
28
|
+
nextFrame: np.ndarray,
|
|
29
|
+
c_trackID: np.ndarray,
|
|
30
|
+
n_trackID: np.ndarray,
|
|
31
|
+
nn_dist: np.ndarray,
|
|
32
|
+
counter: int = 0,
|
|
33
|
+
minDistance: float = 0,
|
|
34
|
+
maxDistance: float = 30,
|
|
35
|
+
neighbors=1,
|
|
36
|
+
):
|
|
37
|
+
currentIDs = None
|
|
38
|
+
|
|
39
|
+
if len(currentFrame) > 0 and len(nextFrame) > 0:
|
|
40
|
+
with nb.objmode(foundnn='float64[:,:]', dist_mask='boolean[:]'):
|
|
41
|
+
nNeighbors = NearestNeighbors(
|
|
42
|
+
n_neighbors=max(1, min(neighbors, nextFrame.shape[0]))
|
|
43
|
+
)
|
|
44
|
+
nNeighbors.fit(nextFrame[:, 1:])
|
|
45
|
+
foundnn = nNeighbors.kneighbors(currentFrame[:, 1:])
|
|
46
|
+
foundnn = np.asarray(foundnn, dtype=np.float64)
|
|
47
|
+
# print(foundnn.shape)
|
|
48
|
+
|
|
49
|
+
dist_mask = np.logical_and(
|
|
50
|
+
foundnn[0, ...] >= minDistance, foundnn[0, ...] <= maxDistance
|
|
51
|
+
)
|
|
52
|
+
# print(dist_mask.shape)
|
|
53
|
+
arg = np.argmax(dist_mask, axis=1)
|
|
54
|
+
dist_mask = dist_mask[np.arange(len(arg)), arg]
|
|
55
|
+
foundnn = foundnn[:, np.arange(len(arg)), arg]
|
|
56
|
+
# print(dist_mask.shape)
|
|
57
|
+
|
|
58
|
+
currentIDs = np.where(dist_mask)[0].astype(np.int64)
|
|
59
|
+
|
|
60
|
+
neighbourIDs = foundnn[1][dist_mask].astype(np.int64)
|
|
61
|
+
distance = foundnn[0]
|
|
62
|
+
|
|
63
|
+
if np.isnan(distance).any():
|
|
64
|
+
print('Nan!\n\n')
|
|
65
|
+
|
|
66
|
+
for idx in range(len(currentIDs)):
|
|
67
|
+
if n_trackID[neighbourIDs[idx]] == 0:
|
|
68
|
+
if c_trackID[currentIDs[idx]] == 0:
|
|
69
|
+
counter += 1
|
|
70
|
+
c_trackID[currentIDs[idx]] = counter
|
|
71
|
+
n_trackID[neighbourIDs[idx]] = counter
|
|
72
|
+
else:
|
|
73
|
+
n_trackID[neighbourIDs[idx]] = c_trackID[currentIDs[idx]]
|
|
74
|
+
|
|
75
|
+
nn_dist[neighbourIDs[idx]] = distance[currentIDs[idx]]
|
|
76
|
+
|
|
77
|
+
# counter += 0 if currentIDs is None else len(currentIDs)
|
|
78
|
+
|
|
79
|
+
return counter, c_trackID, n_trackID, nn_dist
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# @nb.njit(parallel=True)
|
|
83
|
+
def tardis_data(
|
|
84
|
+
frames: np.ndarray,
|
|
85
|
+
locX: np.ndarray,
|
|
86
|
+
locY: np.ndarray,
|
|
87
|
+
locZ: np.ndarray = None,
|
|
88
|
+
dts=None,
|
|
89
|
+
range=1500,
|
|
90
|
+
bins=1500,
|
|
91
|
+
):
|
|
92
|
+
if dts is None:
|
|
93
|
+
dts = [1]
|
|
94
|
+
result = np.zeros((len(dts), bins), np.float64)
|
|
95
|
+
edges = np.linspace(0, range, bins + 1)
|
|
96
|
+
if locZ is not None:
|
|
97
|
+
data: np.ndarray = np.column_stack((locX, locY, locZ))
|
|
98
|
+
else:
|
|
99
|
+
data: np.ndarray = np.column_stack((locX, locY))
|
|
100
|
+
data = data[np.argsort(frames)]
|
|
101
|
+
|
|
102
|
+
ids = np.cumsum(np.bincount(frames.astype(np.int64)))
|
|
103
|
+
|
|
104
|
+
min_frame = int(np.min(frames))
|
|
105
|
+
max_frame = int(np.max(frames))
|
|
106
|
+
|
|
107
|
+
for idx, dt in enumerate(dts):
|
|
108
|
+
timer = []
|
|
109
|
+
for t in nb.prange(min_frame, max_frame - dt + 1):
|
|
110
|
+
# next_frame = current_frame + delta_t
|
|
111
|
+
nt = t + dt
|
|
112
|
+
|
|
113
|
+
if nt > max_frame:
|
|
114
|
+
continue
|
|
115
|
+
|
|
116
|
+
# with nb.objmode(dist='float64[:]'):
|
|
117
|
+
start = time.perf_counter_ns()
|
|
118
|
+
dist = calc_dist(
|
|
119
|
+
data[slice(ids[t - 1] if t > 0 else 0, ids[t])],
|
|
120
|
+
data[slice(ids[nt - 1], ids[nt])],
|
|
121
|
+
)
|
|
122
|
+
stop = time.perf_counter_ns()
|
|
123
|
+
timer.append((stop - start) / 1e6)
|
|
124
|
+
|
|
125
|
+
result[idx] += histogram(dist, 0, range, bins)
|
|
126
|
+
|
|
127
|
+
print(
|
|
128
|
+
f'{idx + 1:d}/',
|
|
129
|
+
f'{len(dts):d} TARDIS ',
|
|
130
|
+
f'{(t + 1) / (max_frame - dt + 1):.2%}... ',
|
|
131
|
+
end='\r',
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
result[idx] /= np.sum(result[idx])
|
|
135
|
+
print(
|
|
136
|
+
f'{idx + 1:d}/{len(dts):d} TARDIS {1.0:.2%}... ',
|
|
137
|
+
f'{np.mean(timer):.3f}ms | ',
|
|
138
|
+
f'{np.sum(timer):.3f}ms ',
|
|
139
|
+
end='\r',
|
|
140
|
+
)
|
|
141
|
+
return result, edges
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@nb.vectorize([nb.int64(nb.float64, nb.float64, nb.float64, nb.float64)])
|
|
145
|
+
def f(x, min_val, max_val, num_bins):
|
|
146
|
+
c = num_bins / (max_val - min_val)
|
|
147
|
+
return (x - min_val) * c
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def histogram(data, min_val, max_val, num_bins):
|
|
151
|
+
c = f(data[(data >= min_val) & (data < max_val)], min_val, max_val, num_bins)
|
|
152
|
+
counts = np.bincount(c, minlength=num_bins)
|
|
153
|
+
return counts
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@nb.vectorize([nb.float64(nb.float64, nb.float64)])
|
|
157
|
+
def diff_sq(x, y):
|
|
158
|
+
return (x - y) ** 2
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@nb.njit(parallel=True, cache=True)
|
|
162
|
+
def calc_dist(origin: np.ndarray, dest: np.ndarray):
|
|
163
|
+
res = np.zeros((origin.shape[0] * dest.shape[0]), np.float64)
|
|
164
|
+
for i in nb.prange(origin.shape[0]):
|
|
165
|
+
for j in nb.prange(dest.shape[0]):
|
|
166
|
+
res[i * dest.shape[0] + j] = math.sqrt(
|
|
167
|
+
np.sum((dest[j, :] - origin[i, :]) ** 2)
|
|
168
|
+
)
|
|
169
|
+
return res
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@nb.njit(
|
|
173
|
+
nb.float64[:, :](nb.float64[:, :], nb.int32[:], nb.int64), parallel=True, cache=True
|
|
174
|
+
)
|
|
175
|
+
def merge_localizations(data: np.ndarray, columns: np.ndarray, maxLength):
|
|
176
|
+
frame_idx = columns[0]
|
|
177
|
+
track_idx = columns[1]
|
|
178
|
+
n_idx = columns[2]
|
|
179
|
+
int_idx = columns[3]
|
|
180
|
+
|
|
181
|
+
with nb.objmode(trackIDs='float64[:]'):
|
|
182
|
+
trackIDs, inverse, trackCounts = np.unique(
|
|
183
|
+
data[:, track_idx], return_counts=True, return_inverse=True
|
|
184
|
+
)
|
|
185
|
+
mask = np.logical_and(trackIDs > 0, trackCounts <= maxLength)
|
|
186
|
+
trackIDs[np.logical_not(mask)] = 0
|
|
187
|
+
data[:, track_idx] = trackIDs[inverse]
|
|
188
|
+
trackIDs, trackCounts = trackIDs[mask], trackCounts[mask]
|
|
189
|
+
|
|
190
|
+
mergedData = np.empty((len(trackIDs),) + data.shape[1:], dtype=np.float64)
|
|
191
|
+
|
|
192
|
+
for idx in nb.prange(len(trackIDs)):
|
|
193
|
+
trackGroup = data[data[:, track_idx] == trackIDs[idx], :]
|
|
194
|
+
|
|
195
|
+
weights = trackGroup[:, int_idx]
|
|
196
|
+
for idw in range(len(weights)):
|
|
197
|
+
if weights[idw] < 1:
|
|
198
|
+
weights[idw] = 1
|
|
199
|
+
if np.sum(weights) <= 0:
|
|
200
|
+
weights = np.ones(len(weights), dtype=np.float64)
|
|
201
|
+
for col in range(trackGroup.shape[1]):
|
|
202
|
+
mergedData[idx, col] = np.sum(trackGroup[:, col] * weights) / np.sum(
|
|
203
|
+
weights
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
mergedData[idx, frame_idx] = np.min(trackGroup[:, frame_idx])
|
|
207
|
+
mergedData[idx, int_idx] = np.sum(weights)
|
|
208
|
+
mergedData[idx, n_idx] = len(trackGroup)
|
|
209
|
+
mergedData[idx, track_idx] = trackIDs[idx]
|
|
210
|
+
|
|
211
|
+
# print(
|
|
212
|
+
# 'Merging ', (idx + 1), ' / ', len(trackIDs))
|
|
213
|
+
|
|
214
|
+
if np.isnan(mergedData).any():
|
|
215
|
+
print('Nan!\n\n')
|
|
216
|
+
|
|
217
|
+
# with nb.objmode(leftData='float64[:,:]'):
|
|
218
|
+
leftIndices = np.where(data[:, track_idx] == 0)[0]
|
|
219
|
+
leftData = data[leftIndices, :]
|
|
220
|
+
|
|
221
|
+
return np.append(mergedData, leftData, axis=0)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
@nb.njit
|
|
225
|
+
def _process_single_image(image, reference, pixelSize, upsampling):
|
|
226
|
+
with nb.objmode(shift='float64[:]'):
|
|
227
|
+
shift = phase_cross_correlation(image, reference, upsample_factor=upsampling)[0]
|
|
228
|
+
return shift * pixelSize
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@nb.njit(parallel=True, cache=True)
|
|
232
|
+
def shift_estimation(sub_images, pixelSize, upsampling):
|
|
233
|
+
shifts = np.zeros((len(sub_images), 2))
|
|
234
|
+
reference = sub_images[0]
|
|
235
|
+
for idx in nb.prange(0, len(sub_images)):
|
|
236
|
+
shifts[idx] = _process_single_image(
|
|
237
|
+
sub_images[idx], reference, pixelSize, upsampling
|
|
238
|
+
)
|
|
239
|
+
return shifts
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@nb.jit(nopython=True, parallel=True)
|
|
243
|
+
def shift_correction(interpx, interpy, frame_bins, datax, datay):
|
|
244
|
+
for idx in nb.prange(0, len(interpx)):
|
|
245
|
+
mask = slice(frame_bins[idx - 1] if idx > 0 else 0, frame_bins[idx])
|
|
246
|
+
shift_x = interpx[idx]
|
|
247
|
+
shift_y = interpy[idx]
|
|
248
|
+
datax[mask] -= shift_x
|
|
249
|
+
datay[mask] -= shift_y
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def plot_drift(frames_new, interpx, interpy, title='Drift Cross-Correlation'):
|
|
253
|
+
print('Shift Plot ...', end='\r')
|
|
254
|
+
|
|
255
|
+
# plot results
|
|
256
|
+
plt = pg.plot()
|
|
257
|
+
|
|
258
|
+
plt.showGrid(x=True, y=True)
|
|
259
|
+
plt.addLegend()
|
|
260
|
+
|
|
261
|
+
# set properties of the label for y axis
|
|
262
|
+
plt.setLabel('left', 'drift', units='nm')
|
|
263
|
+
|
|
264
|
+
# set properties of the label for x axis
|
|
265
|
+
plt.setLabel('bottom', 'frame', units='')
|
|
266
|
+
|
|
267
|
+
plt.setWindowTitle(title)
|
|
268
|
+
|
|
269
|
+
# setting horizontal range
|
|
270
|
+
plt.setXRange(0, np.max(frames_new))
|
|
271
|
+
|
|
272
|
+
# setting vertical range
|
|
273
|
+
# plt.setYRange(0, 1)
|
|
274
|
+
|
|
275
|
+
plt.plot(frames_new, interpx, pen='r', symbol=None, symbolBrush=0.2, name='x-drift')
|
|
276
|
+
plt.plot(frames_new, interpy, pen='y', symbol=None, symbolBrush=0.2, name='y-drift')
|
|
277
|
+
|
|
278
|
+
print('Done ...', end='\r')
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def plot_animation_stats(
|
|
282
|
+
frame_bin_centers, locs_per_bin, title='Localizations per Frames Bin'
|
|
283
|
+
):
|
|
284
|
+
print('Plotting Stats ...', end='\r')
|
|
285
|
+
|
|
286
|
+
# Calculate bin edges from centers
|
|
287
|
+
bin_width = frame_bin_centers[1] - frame_bin_centers[0]
|
|
288
|
+
bin_edges = np.concatenate([
|
|
289
|
+
frame_bin_centers - bin_width/2,
|
|
290
|
+
[frame_bin_centers[-1] + bin_width/2]
|
|
291
|
+
])
|
|
292
|
+
|
|
293
|
+
# plot results
|
|
294
|
+
plt = pg.plot()
|
|
295
|
+
|
|
296
|
+
plt.showGrid(x=True, y=True)
|
|
297
|
+
plt.addLegend()
|
|
298
|
+
|
|
299
|
+
# set properties of the label for y axis
|
|
300
|
+
plt.setLabel('left', 'Localizations', units='counts')
|
|
301
|
+
|
|
302
|
+
# set properties of the label for x axis
|
|
303
|
+
plt.setLabel('bottom', 'Frame', units='')
|
|
304
|
+
|
|
305
|
+
plt.setWindowTitle(title)
|
|
306
|
+
|
|
307
|
+
# plot bar plot using bin edges instead of centers
|
|
308
|
+
plt.plot(
|
|
309
|
+
bin_edges,
|
|
310
|
+
locs_per_bin,
|
|
311
|
+
stepMode='center',
|
|
312
|
+
fillLevel=0,
|
|
313
|
+
fillOutline=True,
|
|
314
|
+
brush=(0, 0, 255, 150),
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
print('Done ...', end='\r')
|