1
- # Copyright 2012 Daniel B. Allan
2
-
3
- # http://pha.jhu.edu/~dallan
4
- # http://www.danallan.com
5
- #
6
- # This program is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 3 of the License, or (at
9
- # your option) any later version.
10
- #
11
- # This program is distributed in the hope that it will be useful, but
12
- # WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, see <http://www.gnu.org/licenses>.
18
-
19
1
20
2
from __future__ import division
21
3
import warnings
@@ -120,7 +102,7 @@ def refine(raw_image, image, radius, coords, max_iterations=10, engine='auto',
120
102
Characterize the neighborhood of a local maximum, and iteratively
121
103
hone in on its center-of-brightness. Return its coordinates, integrated
122
104
brightness, size (Rg), eccentricity (0=circular), and signal strength.
123
-
105
+
124
106
Parameters
125
107
----------
126
108
raw_image : array (any dimensions)
@@ -146,15 +128,15 @@ def refine(raw_image, image, radius, coords, max_iterations=10, engine='auto',
146
128
engine = 'python'
147
129
if engine == 'python' :
148
130
coords = np .array (coords ) # a copy, will not modify in place
149
- results = _refine (raw_image , image , radius , coords , max_iterations ,
131
+ results = _refine (raw_image , image , radius , coords , max_iterations ,
150
132
characterize , walkthrough )
151
133
elif engine == 'numba' :
152
134
if not NUMBA_AVAILABLE :
153
135
warnings .warn ("numba could not be imported. Without it, the "
154
136
"'numba' engine runs very slow. Use the 'python' "
155
137
"engine or install numba." , UserWarning )
156
138
if image .ndim != 2 :
157
- raise NotImplementedError ("The numba engine only supports 2D "
139
+ raise NotImplementedError ("The numba engine only supports 2D "
158
140
"images. You can extend it if you feel "
159
141
"like a hero." )
160
142
if walkthrough :
@@ -225,7 +207,7 @@ def _refine(raw_image, image, radius, coords, max_iterations,
225
207
# If we're off by less than half a pixel, interpolate.
226
208
else :
227
209
# Here, coord is a float. We are off the grid.
228
- neighborhood = ndimage .shift (neighborhood , - off_center ,
210
+ neighborhood = ndimage .shift (neighborhood , - off_center ,
229
211
order = 2 , mode = 'constant' , cval = 0 )
230
212
new_coord = coord + off_center
231
213
# Disallow any whole-pixels moves on future iterations.
@@ -357,7 +339,7 @@ def _numba_refine(raw_image, image, radius, coords, max_iterations,
357
339
# TODO Implement this for numba.
358
340
# Remember to zero cm_n somewhere in here.
359
341
# Here, coord is a float. We are off the grid.
360
- # neighborhood = ndimage.shift(neighborhood, -off_center,
342
+ # neighborhood = ndimage.shift(neighborhood, -off_center,
361
343
# order=2, mode='constant', cval=0)
362
344
# new_coord = np.float_(coord) + off_center
363
345
# Disallow any whole-pixels moves on future iterations.
@@ -420,7 +402,7 @@ def _numba_refine(raw_image, image, radius, coords, max_iterations,
420
402
def locate (raw_image , diameter , minmass = 100. , maxsize = None , separation = None ,
421
403
noise_size = 1 , smoothing_size = None , threshold = 1 , invert = False ,
422
404
percentile = 64 , topn = None , preprocess = True , max_iterations = 10 ,
423
- filter_before = True , filter_after = True ,
405
+ filter_before = True , filter_after = True ,
424
406
characterize = True , engine = 'auto' ):
425
407
"""Locate Gaussian-like blobs of a given approximate size.
426
408
@@ -449,7 +431,7 @@ def locate(raw_image, diameter, minmass=100., maxsize=None, separation=None,
449
431
default.
450
432
percentile : Features must have a peak brighter than pixels in this
451
433
percentile. This helps eliminate spurrious peaks.
452
- topn : Return only the N brightest features above minmass.
434
+ topn : Return only the N brightest features above minmass.
453
435
If None (default), return all features above minmass.
454
436
455
437
Returns
@@ -554,7 +536,7 @@ def locate(raw_image, diameter, minmass=100., maxsize=None, separation=None,
554
536
if maxsize is not None :
555
537
approx_size = np .empty (count_maxima )
556
538
for i in range (count_maxima ):
557
- approx_size [i ] = estimate_size (image , radius , coords [i ],
539
+ approx_size [i ] = estimate_size (image , radius , coords [i ],
558
540
approx_mass [i ])
559
541
condition &= approx_size < maxsize
560
542
coords = coords [condition ]
@@ -644,7 +626,7 @@ def batch(frames, diameter, minmass=100, maxsize=None, separation=None,
644
626
default.
645
627
percentile : Features must have a peak brighter than pixels in this
646
628
percentile. This helps eliminate spurrious peaks.
647
- topn : Return only the N brightest features above minmass.
629
+ topn : Return only the N brightest features above minmass.
648
630
If None (default), return all features above minmass.
649
631
650
632
Returns
@@ -688,7 +670,7 @@ def batch(frames, diameter, minmass=100, maxsize=None, separation=None,
688
670
References
689
671
----------
690
672
.. [1] Crocker, J.C., Grier, D.G. http://dx.doi.org/10.1006/jcis.1996.0217
691
-
673
+
692
674
"""
693
675
# Gather meta information and save as YAML in current directory.
694
676
timestamp = pd .datetime .utcnow ().strftime ('%Y-%m-%d-%H%M%S' )
@@ -698,12 +680,13 @@ def batch(frames, diameter, minmass=100, maxsize=None, separation=None,
698
680
source = None
699
681
meta_info = dict (timestamp = timestamp ,
700
682
trackpy_version = trackpy .__version__ ,
701
- source = source , diameter = diameter , minmass = minmass ,
702
- maxsize = maxsize , separation = separation ,
703
- noise_size = noise_size , smoothing_size = smoothing_size ,
704
- invert = invert , percentile = percentile , topn = topn ,
683
+ source = source , diameter = diameter , minmass = minmass ,
684
+ maxsize = maxsize , separation = separation ,
685
+ noise_size = noise_size , smoothing_size = smoothing_size ,
686
+ invert = invert , percentile = percentile , topn = topn ,
705
687
preprocess = preprocess , max_iterations = max_iterations ,
706
688
filter_before = filter_before , filter_after = filter_after )
689
+
707
690
if meta :
708
691
if isinstance (meta , str ):
709
692
filename = meta
0 commit comments