Esempio n. 1
0
 def norm(i):
     print 'scale %d' % i
     fres = exp.load('%s_%s_scales_mean.npy' % (strain, feat), memmap='r')
     fres_tn = exp.load('%s_%s_time_normalized_scales_mean.npy' %
                        (strain, feat),
                        memmap='r+')
     fres_tn[:, i, :] = exp.bin_data(fres[:, i, :], sbins)
Esempio n. 2
0
 def run(i):
     print 'processing worm %d' % i
     fdat = exp.load('%s_%s.npy' % (strain, feat), memmap='r')
     signal = fdat[[i], :]
     res = average(signal, kernel_flat, scales)
     #res = average(signal, kernel_gauss, scales);
     fres = exp.load('%s_%s_scales_mean.npy' % (strain, feat), memmap='r+')
     fres[i, :, :] = res[0]
def plot_shape_trajectory(tstart = 500000, tend = ntime, nfig = 100):
  xy = exp.load(wid = wid);
  
  # head tail positions
  xycht = np.load(posfile);
  print xycht.shape  
  
  # reduce to time window of interest
  xy = xy[tstart:tend,:];
  xycht = xycht[tstart:tend,:];
  
  plt.figure(nfig); plt.clf();
  plotTrajectory(xy, cmap = cm.Greys, line = 'gray');
  off= [75,75]
  plotTrajectory(xycht[:,0,:] + xy - off, cmap = cm.Reds, line = 'red');
  plotTrajectory(xycht[:,1,:] + xy - off, cmap = cm.Blues, line = None);
  plotTrajectory(xycht[:,2,:] + xy - off, cmap = cm.Greens, line = None);
def plot_body_line(tstart = 500000, tend = ntime, dt = 1, nfig = 200, lineids = [0]):
  xy = exp.load(wid = wid);
  
  # head tail positions
  lines = np.load(linefile, mmap_mode = 'r');
  #print lines.shape  
  pos = np.load(posfile);
  
  # reduce to time window of interest
  plt.figure(nfig); plt.clf();
  off = [75,75];
  for i in lineids:
    for t in range(tstart, tend, dt):
      xyt = xy[t,:];
      cl = lines[t,i,:,:];
      print xyt
      cc = cm.Blues;
      plt.plot(cl[0,:] + np.round(xyt[0]) - off[0], -cl[1,:] + np.round(xyt[1]) - off[1], color = cc(1.0 * t/(tend-tstart)));  
Created on Tue Jun 21 02:35:04 2016

@author: ckirst
"""

import os
import numpy as np
import matplotlib.pyplot as plt


from scripts.analyse_wormshape import analyse_shape


import experiment as exp;

xydata = exp.load(wid= 80)
ntime = xydata.shape[0];

#create results data array for traces, points

wid = 80;

basedir = '/home/ckirst/Science/Projects/CElegansBehaviour/Analysis/Data/2016_06_21_Wormshapes/'
linefile = os.path.join(basedir, "shape_wid=%d_lines.npy" % wid);
posfile  = os.path.join(basedir, "shape_wid=%d_positions.npy" % wid);
curfile =  os.path.join(basedir, "shape_wid=%d_curvature.npy" % wid);
figfile =  os.path.join(basedir, "shape_wid=%d_t=%s.png" % (wid, "%d"));

# create the files

linedata = np.zeros((ntime, 3, 2, 50));
Esempio n. 6
0
  
  
  
#animate movie  
fig, ax = plt.subplots(1,3)

wid = 96;

img = exp.load_img(t=100000, wid = wid)[20:130, 20:130];
img2 =exp.load_img(t=100000+1, wid = wid)[20:130, 20:130];
figimg = ax[0].imshow(img, cmap = 'gray', clim = (0,256),  interpolation="nearest");
delta = np.asarray(img2, dtype = float) - np.asarray(img, dtype = float)
figimg2 = ax[1].imshow(delta, cmap = 'jet', clim = (-30,60),  interpolation="nearest");
plt.show();

xy = exp.load(wid = wid);

t0 = 507000;
#line, = ax[2].plot([], [], lw=2, color = 'b', marker = 'o');


for t in range(t0, t0 + 15000, 2):
  img = img2;
  img2 = exp.load_img(t=t+1, wid = wid)[20:130, 20:130];
  delta = np.asarray(img2, dtype = float) - np.asarray(img, dtype = float)
  figimg.set_data(img);
  figimg2.set_data(delta);
  #line.set_data(xy[t0:t,0], xy[t0:t,1]);

  #ax[2].plot(xy[t-1:t,0], xy[t-1:t,1], color = 'gray');    
  ax[2].scatter(xy[t,0], -xy[t,1]);  
Esempio n. 7
0
        fdat = exp.load('%s_%s.npy' % (strain, feat), memmap='r')
        signal = fdat[[i], :]
        res = average(signal, kernel_flat, scales)
        #res = average(signal, kernel_gauss, scales);
        fres = exp.load('%s_%s_scales_mean.npy' % (strain, feat), memmap='r+')
        fres[i, :, :] = res[0]

    from multiprocessing import Pool  #, cpu_count;

    #pool = Pool(processes = cpu_count()-6);
    pool = Pool(processes=12)

    pool.map(run, range(data.nworms))

    ### Time normalize data
    fres = exp.load('%s_%s_scales_mean.npy' % (strain, feat), memmap='r')

    sbins = exp.stage_bins(data, nbins=8192)
    res_shape = (fres.shape[0], fres.shape[1], sbins[0].shape[1])

    exp.memmap('%s_%s_time_normalized_scales_mean.npy' % (strain, feat),
               shape=res_shape,
               mode='w+')

    def norm(i):
        print 'scale %d' % i
        fres = exp.load('%s_%s_scales_mean.npy' % (strain, feat), memmap='r')
        fres_tn = exp.load('%s_%s_time_normalized_scales_mean.npy' %
                           (strain, feat),
                           memmap='r+')
        fres_tn[:, i, :] = exp.bin_data(fres[:, i, :], sbins)
Esempio n. 8
0
    printExecutionTime()
    outputResults()
    sys.exit(1)


def printExecutionTime():
    print("total time: %s" % showTime(time.time() - startTime))


def outputResults():
    with open(args.output, "w") as f:
        pickle.dump(exp, f)
        pickle.dump(results, f)


exp = experiment.load(args.exp)
experiment.clearHDFS()
results = {}
runNum = 0
totalRuns = len(exp) * args.numruns
startTime = time.time()
signal.signal(signal.SIGINT, exitHandler)
for run in exp:
    print("running %s" % run)
    s_hat = experiment.Estimate()
    margins_hat = [experiment.Estimate() for i in xrange(2)]
    # record the complete final info from the history server for each run just in
    # case it's useful later.
    finalInfo = []
    for i in range(args.numruns):
        info = logger.AppInfo(args.host, measure=False)
Esempio n. 9
0
      dur_up_min[w,b] = 0;
      dur_up_mean[w,b] = 0;
    
    du = durs_dw[w][b];
    if len(du) > 0:
      dur_dw_max[w,b] = du.max();
      dur_dw_min[w,b] = du.min();
      dur_dw_mean[w,b] = du.mean();
    else:
      dur_dw_max[w,b] = 1;
      dur_dw_min[w,b] = 0;
      dur_dw_mean[w,b] = 0;



dord = exp.load('%s_%s_order.npy' % (strain, feat));


mm = dur_up_mean.max()
dur_up_mean[dur_up_mean == mm] = 0;

plt.figure(2); plt.clf();
dur_names = ['dur_up_max', 'dur_up_min', 'dur_dw_max', 'dur_dw_min', 'dur_up_mean', 'dur_dw_mean', 'ndurs_up'];
fplt.plot_image_array((dur_up_max, dur_up_min, dur_dw_max, dur_dw_min, dur_up_mean, dur_dw_mean, ndurs_up), order = dord, names = dur_names)
plt.tight_layout()
# make histograms for each worm

dbins = 10;

dist_dur_up = np.zeros((nworms, nbins, dbins));
dist_dur_dw = np.zeros((nworms, nbins, dbins));
Matlab to Numpy Data Conversion Routines for Worm Images
"""
__license__ = 'MIT License <http://www.opensource.org/licenses/mit-license.php>'
__author__ = 'Christoph Kirst <*****@*****.**>'
__docformat__ = 'rest'

# check cam data:
import matplotlib.pyplot as plt;
import scipy.io
import numpy as np


import experiment as exp
reload(exp)

wxy = exp.load(wid = 96, valid_only=False);


i = 0;
i = 2;

i += 1;
#fn = '/data/Science/Projects/CElegansBehaviour/Experiment/CAM814A4/corrdCAM814A4CAM814_2015-11-20-174505-%04d.mat' % i;
fn = '/data/Science/Projects/CElegansBehaviour/Experiment/CAM819A3/corrdCAM819A3CAM819_2015-09-14-175453-%04d.mat' % i;

data = scipy.io.loadmat(fn)
xy = data['x_y_coor']

plt.figure(10); plt.clf();
plt.subplot(3,1,1);
plt.plot(xy[:,0] - xy[0,0])
Esempio n. 11
0
Matlab to Numpy Data Conversion Routines for Worm Images
"""
__license__ = 'MIT License <http://www.opensource.org/licenses/mit-license.php>'
__author__ = 'Christoph Kirst <*****@*****.**>'
__docformat__ = 'rest'

# check cam data:
import matplotlib.pyplot as plt
import scipy.io
import numpy as np

import experiment as exp
reload(exp)

wxy = exp.load(wid=96, valid_only=False)

i = 0
i = 2

i += 1
#fn = '/data/Science/Projects/CElegansBehaviour/Experiment/CAM814A4/corrdCAM814A4CAM814_2015-11-20-174505-%04d.mat' % i;
fn = '/data/Science/Projects/CElegansBehaviour/Experiment/CAM819A3/corrdCAM819A3CAM819_2015-09-14-175453-%04d.mat' % i

data = scipy.io.loadmat(fn)
xy = data['x_y_coor']

plt.figure(10)
plt.clf()
plt.subplot(3, 1, 1)
plt.plot(xy[:, 0] - xy[0, 0])
Esempio n. 12
0
#animate movie
fig, ax = plt.subplots(1, 3)

wid = 96

img = exp.load_img(t=100000, wid=wid)[20:130, 20:130]
img2 = exp.load_img(t=100000 + 1, wid=wid)[20:130, 20:130]
figimg = ax[0].imshow(img, cmap='gray', clim=(0, 256), interpolation="nearest")
delta = np.asarray(img2, dtype=float) - np.asarray(img, dtype=float)
figimg2 = ax[1].imshow(delta,
                       cmap='jet',
                       clim=(-30, 60),
                       interpolation="nearest")
plt.show()

xy = exp.load(wid=wid)

t0 = 507000
#line, = ax[2].plot([], [], lw=2, color = 'b', marker = 'o');

for t in range(t0, t0 + 15000, 2):
    img = img2
    img2 = exp.load_img(t=t + 1, wid=wid)[20:130, 20:130]
    delta = np.asarray(img2, dtype=float) - np.asarray(img, dtype=float)
    figimg.set_data(img)
    figimg2.set_data(delta)
    #line.set_data(xy[t0:t,0], xy[t0:t,1]);

    #ax[2].plot(xy[t-1:t,0], xy[t-1:t,1], color = 'gray');
    ax[2].scatter(xy[t, 0], -xy[t, 1])