Exemplo n.º 1
0
def detect_simulated_blips(amplitude=1):
    tmpdir = os.path.join(os.path.dirname(g.settings.config_file), 'tmp')
    flika_fn = 'simulated_blips.flika'
    if os.path.isdir(tmpdir):
        if flika_fn in os.listdir(tmpdir):
            pass
        else:
            shutil.rmtree(tmpdir)
            os.mkdir(tmpdir)
    else:
        os.mkdir(tmpdir)
    data_window = Window(generateBlips(amplitude),
                         filename=os.path.join(tmpdir, 'simulated_blips.tif'))
    mt, mx, my = data_window.image.shape
    data_window.setWindowTitle('Data Window')
    norm_window = data_window
    medB = 3
    gaussian_blur(medB, keepSourceWindow=True)
    makeROI('rectangle',
            pts=np.array([[medB * 2, medB * 2], [medB * 2, my - medB * 2],
                          [mx - medB * 2, my - medB * 2],
                          [mx - medB * 2, medB * 2], [medB * 2, medB * 2]]))
    set_value(0, 0, mt - 1, restrictToOutside=True)
    g.m.currentWindow.setWindowTitle('Lightly Blurred')
    binary_window2 = threshold(.3, keepSourceWindow=True)
    norm_window.setAsCurrentWindow()
    binary_window3 = threshold(1.5, keepSourceWindow=True)
    binary_window = Window(binary_window2.image + binary_window3.image)
    close([binary_window2, binary_window3])
    binary_window = threshold(1.5)
    binary_window.setWindowTitle('Binary Window')
    threshold_cluster(binary_window,
                      data_window,
                      norm_window,
                      rotatedfit=False,
                      density_threshold=2,
                      time_factor=.2,
                      roi_width=5,
                      maxPuffLen=20,
                      maxSigmaForGaussianFit=20,
                      load_flika_file=True)
Exemplo n.º 2
0
def detect_simulated_blips(amplitude=1):
    tmpdir=os.path.join(os.path.dirname(g.settings.config_file),'tmp')
    flika_fn='simulated_blips.flika'
    if os.path.isdir(tmpdir):
        if flika_fn in os.listdir(tmpdir):
            pass
        else:
            shutil.rmtree(tmpdir)
            os.mkdir(tmpdir)
    else:
        os.mkdir(tmpdir)
    data_window=Window(generateBlips(amplitude),filename=os.path.join(tmpdir,'simulated_blips.tif'))
    mt,mx,my=data_window.image.shape
    data_window.setWindowTitle('Data Window')
    norm_window=data_window
    medB=3
    gaussian_blur(medB,keepSourceWindow=True)
    makeROI('rectangle',pts=np.array([[medB*2,medB*2],[medB*2,my-medB*2],[mx-medB*2,my-medB*2],[mx-medB*2,medB*2],[medB*2,medB*2]]))
    set_value(0,0,mt-1,restrictToOutside=True)
    g.m.currentWindow.setWindowTitle('Lightly Blurred')
    binary_window2=threshold(.3,keepSourceWindow=True)
    norm_window.setAsCurrentWindow()
    binary_window3=threshold(1.5,keepSourceWindow=True)
    binary_window=Window(binary_window2.image+binary_window3.image)
    close([binary_window2,binary_window3])
    binary_window=threshold(1.5)
    binary_window.setWindowTitle('Binary Window')
    threshold_cluster(binary_window,
                      data_window,
                      norm_window,
                      rotatedfit=False, 
                      density_threshold=2, 
                      time_factor=.2, 
                      roi_width=5,
                      maxPuffLen=20, 
                      maxSigmaForGaussianFit=20,
                      load_flika_file=True)
Exemplo n.º 3
0
Created on Fri Dec 04 13:23:33 2015

@author: Kyle Ellefsen
"""
import numpy as np

from plugins.detect_puffs.puff_simulator.puff_simulator import simulate_puffs
from plugins.detect_puffs.threshold_cluster import threshold_cluster
data_window = simulate_puffs(nFrames=1000, nPuffs=20)
data_window = g.m.currentWindow
norm_window = data_window
norm_window.setName('Normalized Window')
binary_window = threshold(1.1, keepSourceWindow=True)
binary_window.setName('Binary Window')
threshold_cluster(binary_window,
                  data_window,
                  norm_window,
                  density_threshold=5.8)

## run through manual steps

## once threshold_cluster has run, see what the percentage of puffs it detected, and the false positive rate

detected_puffs = g.m.puffAnalyzer.puffs.puffs
simulated_puffs = simulate_puffs.puffs
nearest_puffs = []
for puff in detected_puffs:
    k = puff.kinetics
    detected_puff = np.array([k['t_peak'], k['x'], k['y']])
    difference = np.sqrt(np.sum((simulated_puffs - detected_puff)**2, 1))
    closest_idx = np.argmin(difference)
    #distance=difference[closest_idx]
Exemplo n.º 4
0
"""
Created on Fri Dec 04 13:23:33 2015

@author: Kyle Ellefsen
"""
import numpy as np

from plugins.detect_puffs.puff_simulator.puff_simulator import simulate_puffs
from plugins.detect_puffs.threshold_cluster import threshold_cluster
data_window=simulate_puffs(nFrames=1000,nPuffs=20)
data_window=g.m.currentWindow
norm_window=data_window
norm_window.setName('Normalized Window')
binary_window=threshold(1.1, keepSourceWindow=True)
binary_window.setName('Binary Window')
threshold_cluster(binary_window,data_window,norm_window,density_threshold=5.8)

## run through manual steps

## once threshold_cluster has run, see what the percentage of puffs it detected, and the false positive rate


detected_puffs=g.m.puffAnalyzer.puffs.puffs
simulated_puffs=simulate_puffs.puffs
nearest_puffs=[]
for puff in detected_puffs:
    k=puff.kinetics
    detected_puff=np.array([k['t_peak'],k['x'],k['y']])
    difference=np.sqrt(np.sum((simulated_puffs-detected_puff)**2,1))
    closest_idx=np.argmin(difference)
    #distance=difference[closest_idx]
@author: Kyle Ellefsen
"""
if __name__ == '__main__':
    import os, sys
    flika_dir = os.path.join(os.path.expanduser('~'), 'Documents', 'GitHub',
                             'flika')
    sys.path.append(flika_dir)
    from flika import *
    start_flika()

    from plugins.detect_puffs.threshold_cluster import threshold_cluster
    from plugins.detect_puffs.puff_simulator.puff_simulator import simulate_puffs
    simulate_puffs(nFrames=1000, nPuffs=20)
    baseline = -5  # This is the mean pixel value in the absence of photons.
    subtract(baseline)
    data_window = ratio(
        0, 30, 'average'
    )  # ratio(first_frame, nFrames, ratio_type). Now we are in F/F0
    data_window.setName('Data Window (F/F0)')
    norm_image = data_window.image - 1
    norm_window = Window(norm_image)
    norm_window.setName('Normalized Window')
    blurred_window = gaussian_blur(2, norm_edges=True, keepSourceWindow=True)
    blurred_window.setName('Blurred Window')
    threshold_cluster(data_window,
                      blurred_window,
                      blurred_window,
                      blur_thresh=.3)

    sys.exit(
        g.app.exec_())  # This is required to run outside of Spyder or PyCharm
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 06 11:24:36 2015

@author: Kyle Ellefsen
"""
if __name__ == '__main__':
    import os, sys; flika_dir = os.path.join(os.path.expanduser('~'),'Documents', 'GitHub', 'flika'); sys.path.append(flika_dir); from flika import *; start_flika()
    from plugins.detect_puffs.threshold_cluster import threshold_cluster
    from plugins.detect_puffs.puff_simulator.puff_simulator import simulate_puffs
    simulate_puffs(nFrames=1000,nPuffs=20)
    baseline = -5  # This is the mean pixel value in the absence of photons.
    subtract(baseline)
    data_window=ratio(0, 30, 'average')  # ratio(first_frame, nFrames, ratio_type). Now we are in F/F0
    data_window.setName('Data Window (F/F0)')
    norm_image = data_window.image - 1
    norm_window = Window(norm_image)
    norm_window.setName('Normalized Window')
    blurred_window = gaussian_blur(2, norm_edges=True, keepSourceWindow=True)
    blurred_window.setName('Blurred Window')
    threshold_cluster(data_window, blurred_window, blurred_window, blur_thresh=.3)
    sys.exit(g.app.exec_())  # This is required to run outside of Spyder or PyCharm