In [1]:
%load_ext autoreload
%autoreload 1
#get our environment ready for data analysis times
%pylab inline
#import some os functionality so that we can be platform independent
import os
import time
#import skimage components
from skimage.external import tifffile as tif #note that this can be achieved by using the
#skimage.io with the tifffile plugin.
#better filtering than skimage
from scipy import ndimage
#import pandas
import pandas as pd
from scipy.ndimage import measurements
from scipy.ndimage.filters import median_filter
import matplotlib.gridspec as gridspec #fancy subplot layout
from matplotlib.path import Path #Needed to create shapes
import matplotlib.patches as patches #needed so show shapes on top of graphs
%aimport peaks.gauss2d
Gauss2D = peaks.gauss2d.Gauss2D
%aimport peaks.utils
detrend = peaks.utils.detrend
%aimport peaks.peakfinder
PeakFinder = peaks.peakfinder.PeakFinder
%aimport dphplotting.mip
mip = dphplotting.mip.mip
%aimport peaks.stackanalysis
PSFStackAnalyzer = peaks.stackanalysis.PSFStackAnalyzer
#from peaks.stackanalysis import PSFStackAnalyzer
In [2]:
PSF = tif.imread('testPSF2.tif')
In [3]:
mip(PSF)
Out[3]:
In [4]:
myPSF = PSFStackAnalyzer(PSF)
In [5]:
myPSF.peakfinder.plot_blobs()
Out[5]:
args = myPSF.peakfinder.blobs[:,3].argsort() myPSF.peakfinder.blobs = myPSF.peakfinder.blobs[args[::-1]][:2] myPSF.peakfinder.plot_blobs()
Testing multiprocessing speed vs single core.
for i in range(15,55,5):
t = time.clock()
myPSF.fitPeaks(i,nproc = 24)
t = time.clock()-t
print('Fit window size = {}, time = {:.3f}'.format(i,t))
With the error messages removed the output (for the SuperMicro with 24 cores) is:
Fit window size = 15, time = 14.797
Fit window size = 20, time = 14.427
Fit window size = 25, time = 16.680
Fit window size = 30, time = 17.115
Fit window size = 35, time = 18.466
Fit window size = 40, time = 19.838
Fit window size = 45, time = 23.013
Fit window size = 50, time = 27.362
for i in range(15,55,5):
t = time.clock()
myPSF.fitPeaks(i,nproc = 1)
t = time.clock()-t
print('Fit window size = {}, time = {:.3f}'.format(i,t))
Fit window size = 15, time = 102.633
Fit window size = 20, time = 99.646
Fit window size = 25, time = 113.847
Fit window size = 30, time = 125.859
Fit window size = 35, time = 131.001
Fit window size = 40, time = 129.754
Fit window size = 45, time = 129.806
Fit window size = 50, time = 158.659
for i in range(1,os.cpu_count()+1):
t = time.clock()
myPSF.fitPeaks(25,nproc = i)
t = time.clock()-t
print('nproc = {}, time = {:.3f}'.format(i,t))
nproc = 1, time = 113.227
nproc = 2, time = 63.178
nproc = 3, time = 42.811
nproc = 4, time = 33.832
nproc = 5, time = 28.651
nproc = 6, time = 24.544
nproc = 7, time = 22.445
nproc = 8, time = 22.285
nproc = 9, time = 20.816
nproc = 10, time = 19.402
nproc = 11, time = 19.322
nproc = 12, time = 18.374
nproc = 13, time = 17.402
nproc = 14, time = 17.173
nproc = 15, time = 16.277
nproc = 16, time = 16.140
nproc = 17, time = 15.746
nproc = 18, time = 15.919
nproc = 19, time = 16.068
nproc = 20, time = 15.315
nproc = 21, time = 15.558
nproc = 22, time = 15.424
nproc = 23, time = 15.778
nproc = 24, time = 15.798
In [6]:
df = pd.DataFrame([
dict(nproc = 1, time = 113.227),
dict(nproc = 2, time = 63.178),
dict(nproc = 3, time = 42.811),
dict(nproc = 4, time = 33.832),
dict(nproc = 5, time = 28.651),
dict(nproc = 6, time = 24.544),
dict(nproc = 7, time = 22.445),
dict(nproc = 8, time = 22.285),
dict(nproc = 9, time = 20.816),
dict(nproc = 10, time = 19.402),
dict(nproc = 11, time = 19.322),
dict(nproc = 12, time = 18.374),
dict(nproc = 13, time = 17.402),
dict(nproc = 14, time = 17.173),
dict(nproc = 15, time = 16.277),
dict(nproc = 16, time = 16.140),
dict(nproc = 17, time = 15.746),
dict(nproc = 18, time = 15.919),
dict(nproc = 19, time = 16.068),
dict(nproc = 20, time = 15.315),
dict(nproc = 21, time = 15.558),
dict(nproc = 22, time = 15.424),
dict(nproc = 23, time = 15.778),
dict(nproc = 24, time = 15.798)
])
df = df.assign(totcputime = df.nproc*df.time)
df.plot(x='nproc',y='time')
df.plot(x='nproc',y='totcputime')
Out[6]:
In [7]:
myPSF.fitPeaks(15,4);
In [8]:
for peak in myPSF.fits:
peak.sigma_x.plot()
In [9]:
for peak in myPSF.fits:
peak.sigma_y.plot()
In [10]:
for i, peak in enumerate(myPSF.fits):
peak.amp.plot(label=i)
In [11]:
for i, peak in enumerate(myPSF.fits):
peak.offset.plot(label=i)
In [12]:
myPSF.calc_psf_params()
df = myPSF.psf_params[myPSF.psf_params.SNR > 2]
In [13]:
myPSF.psf_params
Out[13]:
In [14]:
myPSF.plot_psf_params('z0')
In [15]:
myPSF.calc_psf_params(subrange=slice(30,70))
myPSF.psf_params = myPSF.psf_params[(myPSF.psf_params.SNR > 2)]
myPSF.psf_params.hist(figsize = (12,12))
Out[15]:
In [16]:
myPSF.calc_psf_params(subrange=slice(30,70))
argsz = (myPSF.psf_params.sigma_z - myPSF.psf_params.sigma_z.mean()) < 3*myPSF.psf_params.sigma_z.std()
argsy = (myPSF.psf_params.sigma_y - myPSF.psf_params.sigma_y.mean()) < 1*myPSF.psf_params.sigma_y.std()
argsx = (myPSF.psf_params.sigma_y - myPSF.psf_params.sigma_y.mean()) < 1*myPSF.psf_params.sigma_y.std()
args = argsz & argsx & argsy & (myPSF.psf_params.SNR > 2)
myPSF.psf_params = myPSF.psf_params[args]
In [17]:
myPSF.plot_psf_params('z0')
myPSF.plot_psf_params('sigma_z')
myPSF.plot_psf_params('sigma_x')
myPSF.plot_psf_params('sigma_y')
myPSF.peakfinder.plot_blobs()
Out[17]:
In [ ]: