def plot_gc_distribution(pp, data):
    names = data.keys()

    # Plot the 2D histogram of coverage vs gc
    for name in names:
        x = [ i * 100 for i in data[name][GC_DISTRIBUTION_NAME]['gc_samples'] ]
        y = data[name][GC_DISTRIBUTION_NAME]['cov_samples']
        

        # Use the median to determine the range to show and round
        # to nearest 100 to avoid aliasing artefacts 
        m = np.median(y)
        y_limit = math.ceil( 2*m / 100) * 100
        hist,xedges,yedges = np.histogram2d(x,y, bins=[20, 50], range=[ [0, 100.0], [0, y_limit] ])

        # draw the plot
        extent = [xedges[0], xedges[-1], yedges[0], yedges[-1] ]
        pl.imshow(hist.T,extent=extent,interpolation='nearest',origin='lower', aspect='auto')

        pl.colorbar()
        pl.title(name + ' GC Bias')
        pl.xlabel("GC %")
        pl.ylabel("k-mer coverage")
        pl.savefig(pp, format='pdf')
        pl.close()
Esempio n. 2
0
def blobFinder(img):
    shape = img.shape[0:2]

    scales = numpy.arange(0.5,7.0,0.5)
    nScales = len(scales)

    bank  = numpy.zeros(shape+(nScales,))


    for si,scale in enumerate(scales):
        print scale
        log         = numpy.abs(scale*vigra.filters.laplacianOfGaussian(img,float(scale)))
        log         = numpy.sum(log,axis=2)
        bank[:,:,si]=log

        #f = pylab.figure()
        #for n, iterImg in enumerate([log,img]):
        #    f.add_subplot(1,2, n)  # this line outputs images side-by-side
        #    pylab.imshow(numpy.swapaxes(norm01(iterImg),0,1))
        #pylab.show()


    maxScale = numpy.argmax(bank,axis=2)

    print "mima",maxScale.min(),maxScale.max()
    print maxScale

    f = pylab.figure()
    for n, iterImg in enumerate([maxScale]):
        f.add_subplot(1,1, n)  # this line outputs images side-by-side
        pylab.imshow(numpy.swapaxes(norm01(iterImg),0,1))
    pylab.show()
def bilinear_interpolation(dataset_name, feat, unfeat, repo, nbt=3):

    tlist=np.linspace(0,1,nbt)
    _, _, test=get_data(dataset_name, repo)
    xtest1, _, _ = test
    n = xtest1.shape[-1]
    N = len(xtest1)
    
    tuple_index=np.random.permutation(N)[:4]
    embeddings = feat.predict(xtest1[tuple_index])
    
    interp_array = np.zeros((nbt, nbt, n, n))
    
    for i in range(nbt):
        for j in range(nbt):
            x = (tlist[i]*embeddings[0] + (1-tlist[0])*embeddings[1])
            y = (tlist[i]*embeddings[2] + (1-tlist[0])*embeddings[3])
            x_interp = unfeat.predict(((tlist[j]*x + (1-tlist[j])*y))[None])
            interp_array[i,j]=x_interp[0,0]
            
    pl.figure(1)
    for i in range(nbt):
        for j in range(nbt):
            nb=i*nbt +j+1
            pl.subplot(nbt*100+(nbt)*10 +nb)
            pl.imshow(interp_array[i,j], cmap='Blues',interpolation='nearest')
Esempio n. 4
0
def ST_beta(r,steps = 99):
	"""
	Makes a heat map of beta over ST space, for a given value of r.
	Uses the full model.
	Steps : int {99}
		Number of steps to sample S and T at
	Returns
	=======
	None
	"""

	Ss = np.linspace(-1,3,steps)
	Ts = np.linspace(0,4,steps)
	dataFull = np.zeros( (steps,steps) )
	for i,S in enumerate(Ss):
		for j,T in enumerate(Ts):
			mod = ESS_class(r,S,T)
			state = mod.getESS()
			dataFull[i,j] = mod.beta(state,r)

	#pl.figure()
	cmap = pl.get_cmap('coolwarm')
	pl.imshow(dataFull, origin = [Ts[0], Ss[0]],\
			extent = [ Ts[0],Ts[-1],Ss[0],Ss[-1] ], vmin = -1,vmax = 1, cmap = cmap)
	pl.plot( [ Ts[0], Ts[-1] ],[ 0,0 ],color='black', linewidth = 2.5 )
	pl.plot( [ 1, 1 ],[ Ss[0],Ss[-1] ],'--',color='black',  linewidth = 2.5 )
	pl.plot( [ 0, 3 ],[ 2, -1 ],'--',color='black',  linewidth = 2.5 )
Esempio n. 5
0
    def plot_matches(self, name, show_below = True, match_maximum = None):
        """ 対応点を線で結んで画像を表示する
          入力: im1,im2(配列形式の画像)、locs1,locs2(特徴点座標)
             machescores(match()の出力)、
             show_below(対応の下に画像を表示するならTrue)"""
        im1 = self._image_1.get_array_image()
        im2 = self._image_2.get_array_image()
        self.appendimages()
        im3 = self._append_image
        if self._match_score is None:
            self.match()
        locs1 = self._image_1.get_shift_location()
        locs2 = self._image_2.get_shift_location()
        if show_below:
            im3 = numpy.vstack((im3,im3))
        pylab.figure(dpi=160)
        pylab.gray()
        pylab.imshow(im3, aspect = 'auto')

        cols1 = im1.shape[1]
        match_num = 0
        for i,m in enumerate(self._match_score):
            if m > 0 : 
                pylab.plot([locs1[i][0],locs2[m][0]+cols1], [locs1[i][1],locs2[m][1]], 'c')
                match_num = match_num + 1
            if match_maximum is not None and match_num >= match_maximum:
                break
        pylab.axis('off')
        pylab.savefig(name, dpi=160)
Esempio n. 6
0
def getOptCandGamma(cv_train, cv_label):
    print "Finding optimal C and gamma for SVM with RBF Kernel"
    C_range = 10.0 ** np.arange(-2, 9)
    gamma_range = 10.0 ** np.arange(-5, 4)
    param_grid = dict(gamma=gamma_range, C=C_range)
    cv = StratifiedKFold(y=cv_label, n_folds=40)

    # Use the svm.SVC() as the cost function to evaluate parameter choices
    # NOTE: Perhaps we should run computations in parallel if needed. Does it
    # do that already within the class?
    grid = GridSearchCV(svm.SVC(), param_grid=param_grid, cv=cv)
    grid.fit(cv_train, cv_label)

    score_dict = grid.grid_scores_
    scores = [x[1] for x in score_dict]
    scores = np.array(scores).reshape(len(C_range), len(gamma_range))
    pl.figure(figsize=(8,6))
    pl.subplots_adjust(left=0.05, right=0.95, bottom=0.15, top=0.95)
    pl.imshow(scores, interpolation='nearest', cmap=pl.cm.spectral)
    pl.xlabel('gamma')
    pl.ylabel('C')
    pl.colorbar()
    pl.xticks(np.arange(len(gamma_range)), gamma_range, rotation=45)
    pl.yticks(np.arange(len(C_range)), C_range)
    pl.show()

    print "The best classifier is: ", grid.best_estimator_
def plot_Barycenter(dataset_name, feat, unfeat, repo):

    if dataset_name==MNIST:
        _, _, test=get_data(dataset_name, repo, labels=True)
        xtest1,_,_, labels,_=test
    else:
        _, _, test=get_data(dataset_name, repo, labels=False)
        xtest1,_,_ =test
        labels=np.zeros((len(xtest1),))
    # get labels
    def bary_wdl2(index): return _bary_wdl2(index, xtest1, feat, unfeat)
    
    n=xtest1.shape[-1]
    
    num_class = (int)(max(labels)+1)
    barys=[bary_wdl2(np.where(labels==i)) for i in range(num_class)]
    pl.figure(1, (num_class, 1))
    for i in range(num_class):
        pl.subplot(1,10,1+i)
        pl.imshow(barys[i][0,0,:,:],cmap='Blues',interpolation='nearest')
        pl.xticks(())
        pl.yticks(())
        if i==0:
            pl.ylabel('DWE Bary.')
        if num_class >1:
            pl.title('{}'.format(i))
    pl.tight_layout(pad=0,h_pad=-2,w_pad=-2) 
    pl.savefig("imgs/{}_dwe_bary.pdf".format(dataset_name))
Esempio n. 8
0
    def displayResults(self,res, cm=pylab.cm.gray, title='Specify a title'):
        if self.display:
		self.count=self.count+1
        	pylab.figure(self.count)
        	pylab.imshow(res, cm, interpolation='nearest')
        	pylab.colorbar()
        	pylab.title(title)
Esempio n. 9
0
def display_image_from_array(nparray,colory='binary',roi=None):
	"""
	Produce a display of the nparray 2D matrix
	@param nparray : image to display
	@type nparray : numpy 2darray
	@param colory : color mapping of the image (see http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps)
	@type colory : string
	"""
	#Set the region of interest to display :
	#  (0,0) is set at lower left corner of the image
	if roi == None:
		roi = ((0,0),nparray.shape)
		nparraydsp = nparray
		print roi
	elif type(roi[0])==tuple and type(roi[1])==tuple: 
		# Case of 2 points definition of the domain : roi = integers index of points ((x1,y1),(x2,y2))
		print roi
		nparraydsp = nparray[roi[0][0]:roi[1][0],roi[0][1]:roi[1][1]]
	elif type(roi[0])==int and type(roi[1])==int:	
		# Case of image centered domain : roi = integers (width,high)
		nparraydsp = nparray[int(nparray.shape[0]/2)-int(roi[0])/2:int(nparray.shape[0]/2)+int(roi[0])/2,int(nparray.shape[1]/2)-int(roi[1])/2:int(nparray.shape[1]/2)+int(roi[1])/2]
	fig = pylab.figure()
    #Display array with grayscale intensity and no pixel smoothing interpolation
	pylab.imshow(nparraydsp,cmap=colory,interpolation='nearest')#,origin='lower')
	pylab.colorbar()
	pylab.axis('off')
Esempio n. 10
0
def plot_samples(samples, no_of_rows, no_of_cols, pno=1, n_samples=100, plot_every=1, img_shp=(28,
    28), axes=None):
    if pno == 0:
        axes = pylab.subplot(no_of_rows, no_of_cols, pno + 1, aspect='equal')
        colored_axis(axes, "red")
        pylab.imshow(samples[pno].reshape(img_shp))
        plot_samples(samples,
                no_of_rows,
                no_of_cols,
                pno=pno + plot_every,
                n_samples=n_samples,
                plot_every=plot_every,
                img_shp=img_shp,
                axes=axes)

    if pno >= n_samples:
       colored_axis(axes, "black")
       return 0
    else:
        plot_no = pno / plot_every
        axes = pylab.subplot(no_of_rows, no_of_cols, plot_no + 1, aspect='equal')
        colored_axis(axes, "black")
        pylab.imshow(samples[pno].reshape(img_shp))
        plot_samples(samples,
                no_of_rows,
                no_of_cols,
                pno=pno + plot_every,
                n_samples=n_samples,
                plot_every=plot_every,
                img_shp=img_shp,
                axes=axes)
Esempio n. 11
0
def makeContourPlot(scores, average, HEIGHT, WIDTH, outputId, maskId, plt_title, outputdir, barcodeId=-1, vmaxVal=100):
    pylab.bone()
    #majorFormatter = FormatStrFormatter('%.f %%')
    #ax = pylab.gca()
    #ax.xaxis.set_major_formatter(majorFormatter)
    
    pylab.figure()
    ax = pylab.gca()
    ax.set_xlabel(str(WIDTH) + ' wells')
    ax.set_ylabel(str(HEIGHT) + ' wells')
    ax.autoscale_view()
    pylab.jet()
    
    pylab.imshow(scores,vmin=0, vmax=vmaxVal, origin='lower')
    pylab.vmin = 0.0
    pylab.vmax = 100.0
    ticksVal = getTicksForMaxVal(vmaxVal)
    pylab.colorbar(format='%.0f %%',ticks=ticksVal)
    print "'%s'" % average
    if(barcodeId!=-1):
        if(barcodeId==0): maskId = "No Barcode Match,"
        else:             maskId = "Barcode Id %d," % barcodeId
    if plt_title != '': maskId = '%s\n%s' % (plt_title,maskId)
    print "Checkpoint A"
    pylab.title('%s Loading Density (Avg ~ %0.f%%)' % (maskId, average))
    pylab.axis('scaled')
    print "Checkpoint B"
    pngFn = outputdir+'/'+outputId+'_density_contour.png'
    print "Try save to", pngFn;
    pylab.savefig(pngFn, bbox_inches='tight')
    print "Plot saved to", pngFn;
Esempio n. 12
0
 def img_create(self):
     '''
     Create the output jpg of the file.
     :return:
     '''
     pylab.imshow(self._dcm.pixel_array, cmap=pylab.cm.bone)
     pylab.savefig(self._str_outputImageFile)
Esempio n. 13
0
def window_fn_matrix(Q,N,num_remov=None,save_tag=None,lms=None):
    Q = n.matrix(Q); N = n.matrix(N)
    Ninv = uf.pseudo_inverse(N,num_remov=None) # XXX want to remove dynamically
    #print Ninv 
    info = n.dot(Q.H,n.dot(Ninv,Q))
    M = uf.pseudo_inverse(info,num_remov=num_remov)
    W = n.dot(M,info)

    if save_tag!=None:
        foo = W[0,:]
        foo = n.real(n.array(foo))
        foo.shape = (foo.shape[1]),
        print foo.shape
        p.scatter(lms[:,0],foo,c=lms[:,1],cmap=mpl.cm.PiYG,s=50)
        p.xlabel('l (color is m)')
        p.ylabel('W_0,lm')
        p.title('First Row of Window Function Matrix')
        p.colorbar()
        p.savefig('{0}/{1}_W.pdf'.format(fig_loc,save_tag))
        p.clf()

        print 'W ',W.shape
        p.imshow(n.real(W))
        p.title('Window Function Matrix')
        p.colorbar()
        p.savefig('{0}/{1}_W_im.pdf'.format(fig_loc,save_tag))
        p.clf()


    return W
Esempio n. 14
0
def psfplots():
	tpsf = wise.get_psf_model(1, pixpsf=True)
	
	psfp = tpsf.getPointSourcePatch(0, 0)
	psf = psfp.patch
	
	psf /= psf.sum()
	
	plt.clf()
	plt.imshow(np.log10(np.maximum(1e-5, psf)), interpolation='nearest', origin='lower')
	plt.colorbar()
	ps.savefig()
	
	h,w = psf.shape
	cx,cy = w/2, h/2
	
	X,Y = np.meshgrid(np.arange(w), np.arange(h))
	R = np.sqrt((X - cx)**2 + (Y - cy)**2)
	plt.clf()
	plt.semilogy(R.ravel(), psf.ravel(), 'b.')
	plt.xlabel('Radius (pixels)')
	plt.ylabel('PSF value')
	plt.ylim(1e-8, 1.)
	ps.savefig()
	
	plt.clf()
	plt.loglog(R.ravel(), psf.ravel(), 'b.')
	plt.xlabel('Radius (pixels)')
	plt.ylabel('PSF value')
	plt.ylim(1e-8, 1.)
	ps.savefig()
	
	print('PSF norm:', np.sqrt(np.sum(np.maximum(0, psf)**2)))
	print('PSF max:', psf.max())
def display_head(set_x, set_y, n = 5):
    '''
    show some figures based on gray image matrixs
    
    @type set_x: TensorSharedVariable, 
    @param set_x: gray level value matrix of the
    
    @type set_y: TensorVariable, 
    @param set_y: label of the figures    
    
    @type n: int, 
    @param n: numbers of figure to be display, less than 10, default 5
    '''
    import pylab
    
    if n > 10: n = 10
    img_x = set_x.get_value()[0:n].reshape(n, 28, 28)
    img_y = set_y.eval()[0:n]
    
    for i in range(n): 
        pylab.subplot(1, n, i+1); 
        pylab.axis('off'); 
        pylab.title(' %d' % img_y[i])
        pylab.gray()
        pylab.imshow(img_x[i])
Esempio n. 16
0
def dotdraw(s, direction="RL", **kwargs):
    """
  Make a drawing of an SX and display it.
  
  direction   one of "BT", "LR", "TB", "RL"
  """

    try:  # Check if we have pylab
        from pylab import imread, imshow, show, figure, axes
    except:
        # We don't have pylab, so just write out to file
        print "casadi.tools.graph.dotdraw: no pylab detected, will not show drawing on screen."
        dotgraph(s, direction=direction, **kwargs).write_ps("temp.ps")
        return

    if hasattr(show, "__class__") and show.__class__.__name__ == "PylabShow":
        # catch pyreport case, so we have true vector graphics
        figure_name = "%s%d.%s" % (show.basename, len(show.figure_list), show.figure_extension)
        show.figure_list += (figure_name,)
        dotgraph(s, direction=direction, **kwargs).write_pdf(figure_name)
        print "Here goes figure %s (dotdraw)" % figure_name
    else:
        # Matplotlib does not allow to display vector graphics on screen,
        # so we fall back to png
        temp = "_temp.png"
        dotgraph(s, direction=direction, **kwargs).write_png(temp)
        im = imread(temp)
        figure()
        ax = axes([0, 0, 1, 1], frameon=False)
        ax.set_axis_off()
        imshow(im)
        show()
Esempio n. 17
0
def plotMatrix(matrix, color_scheme, row_headers, col_headers, vmin, vmax, options):

    pylab.imshow(matrix,
                 cmap=color_scheme,
                 origin='lower',
                 vmax=vmax,
                 vmin=vmin,
                 interpolation='nearest')

    # offset=0: x=center,y=center
    # offset=0.5: y=top/x=right
    offset = 0.0

    if options.xticks:
        pylab.xticks([offset + x for x in range(len(options.xticks))],
                     options.xticks,
                     rotation="vertical",
                     fontsize="8")
    else:
        if col_headers and len(col_headers) < 100:
            pylab.xticks([offset + x for x in range(len(col_headers))],
                         col_headers,
                         rotation="vertical",
                         fontsize="8")

    if options.yticks:
        pylab.yticks([offset + y for y in range(len(options.yticks))],
                     options.yticks,
                     fontsize="8")
    else:
        if row_headers and len(row_headers) < 100:
            pylab.yticks([offset + y for y in range(len(row_headers))],
                         row_headers,
                         fontsize="8")
def show_image(*imgs): 
    for idx, img in enumerate(imgs):
        subplot = 101 + len(imgs)*10 +idx
        pl.subplot(subplot)
        pl.imshow(img, cmap=pl.cm.gray)   
        pl.gca().set_axis_off()    
    pl.subplots_adjust(0.02, 0, 0.98, 1, 0.02, 0)        
Esempio n. 19
0
    def plot_density(self, plot_filename="out/density.png"):
        x, y, labels = self.load_data()

        figure(figsize=(self.fig_width, self.fig_height), dpi=80)
        # Perform a kernel density estimator on the coords in data.
        # The following 10 lines can be commented out if density map not needed.
        space_factor = 1.2
        xmin = space_factor * x.min()
        xmax = space_factor * x.max()
        ymin = space_factor * y.min()
        ymax = space_factor * y.max()
        X, Y = mgrid[xmin:xmax:100j, ymin:ymax:100j]
        positions = c_[X.ravel(), Y.ravel()]
        values = c_[x, y]
        kernel = stats.kde.gaussian_kde(values.T)
        Z = reshape(kernel(positions.T).T, X.T.shape)
        imshow(rot90(Z), cmap=cm.gist_earth_r, extent=[xmin, xmax, ymin, ymax])

        # Plot the labels
        num_labels_to_plot = min([len(labels), self.max_labels, len(x), len(y)])
        if self.has_labels:
            for i in range(num_labels_to_plot):
                text(x[i], y[i], labels[i])  # assumes m size and order matches labels
        else:
            plot(x, y, "k.", markersize=1)
        axis("equal")
        axis("off")
        savefig(plot_filename)
        print "wrote %s" % (plot_filename)
Esempio n. 20
0
    def _draw_solution(self):
        """ plot the current solution on our optional visualization """
        myg = self.grids[self.current_level].grid

        v = self.grids[self.current_level].get_var("v")

        pylab.imshow(
            numpy.transpose(v[myg.ilo : myg.ihi + 1, myg.jlo : myg.jhi + 1]),
            interpolation="nearest",
            origin="lower",
            extent=[self.xmin, self.xmax, self.ymin, self.ymax],
        )

        # pylab.xlabel("x")
        pylab.ylabel("y")

        if self.current_level == self.nlevels - 1:
            pylab.title(r"solving $L\phi = f$")
        else:
            pylab.title(r"solving $Le = r$")

        formatter = matplotlib.ticker.ScalarFormatter(useMathText=True)
        cb = pylab.colorbar(format=formatter, shrink=0.5)

        cb.ax.yaxis.offsetText.set_fontsize("small")
        cl = pylab.getp(cb.ax, "ymajorticklabels")
        pylab.setp(cl, fontsize="small")
Esempio n. 21
0
    def _draw_main_error(self):
        """
        plot the error with respect to the true solution on our optional
        visualization
        """
        myg = self.grids[self.nlevels - 1].grid

        v = self.grids[self.nlevels - 1].get_var("v")

        e = v - self.true_function(myg.x2d, myg.y2d)

        pylab.imshow(
            numpy.transpose(e[myg.ilo : myg.ihi + 1, myg.jlo : myg.jhi + 1]),
            interpolation="nearest",
            origin="lower",
            extent=[self.xmin, self.xmax, self.ymin, self.ymax],
        )

        pylab.xlabel("x")
        pylab.ylabel("y")

        pylab.title(r"current fine grid error")

        formatter = matplotlib.ticker.ScalarFormatter(useMathText=True)
        cb = pylab.colorbar(format=formatter, shrink=0.5)

        cb.ax.yaxis.offsetText.set_fontsize("small")
        cl = pylab.getp(cb.ax, "ymajorticklabels")
        pylab.setp(cl, fontsize="small")
Esempio n. 22
0
 def savepng(pre, img, title=None, **kwargs):
     fn = '%s-%s.png' % (pre, idstr)
     print 'Saving', fn
     plt.clf()
     plt.imshow(img, **kwargs)
     ax = plt.axis()
     if debug:
         print len(xplotx),len(allobjx)
         for i,(objx,objy,objc) in enumerate(zip(allobjx,allobjy,allobjc)):
             plt.plot(objx,objy,'-',c=objc)
             tempx = []
             tempx.append(xplotx[i])
             tempx.append(objx[0])
             tempy = []
             tempy.append(xploty[i])
             tempy.append(objy[0])
             plt.plot(tempx,tempy,'-',c='purple')
         plt.plot(pointx,pointy,'y.')
         plt.plot(xplotx,xploty,'xg')
     plt.axis(ax)
     if title is not None:
         plt.title(title)
     plt.colorbar()
     plt.gray()
     plt.savefig(fn)
Esempio n. 23
0
    def draw(self):

        print self.edgeno

        pos = 0
        dy = 8
        edgeno = self.edgeno
        edge = self.edges[edgeno]
        edgeprev = self.edges[edgeno-1]
        p = np.round(edge["top"](1024))
        top = min(p+2*dy, 2048)
        bot = min(p-2*dy, 2048)
        self.cutout = self.flat[1][bot:top,:].copy()

        pl.figure(1)
        pl.clf()
        start = 0
        dy = 512
        for i in xrange(2048/dy):
            pl.subplot(2048/dy,1,i+1)
            pl.xlim(start, start+dy)

            if i == 0: pl.title("edge %i] %s|%s" % (edgeno,
                edgeprev["Target_Name"], edge["Target_Name"]))


            pl.subplots_adjust(left=.07,right=.99,bottom=.05,top=.95)

            pl.imshow(self.flat[1][bot:top,start:start+dy], extent=(start,
                start+dy, bot, top), cmap='Greys', vmin=2000, vmax=6000)

            pix = np.arange(start, start+dy)
            pl.plot(pix, edge["top"](pix), 'r', linewidth=1)
            pl.plot(pix, edgeprev["bottom"](pix), 'r', linewidth=1)
            pl.plot(edge["xposs_top"], edge["yposs_top"], 'o')
            pl.plot(edgeprev["xposs_bot"], edgeprev["yposs_bot"], 'o')


            hpp = edge["hpps"]
            pl.axvline(hpp[0],ymax=.5, color='blue', linewidth=5)
            pl.axvline(hpp[1],ymax=.5, color='red', linewidth=5)

            hpp = edgeprev["hpps"]
            pl.axvline(hpp[0],ymin=.5,color='blue', linewidth=5)
            pl.axvline(hpp[1],ymin=.5,color='red', linewidth=5)


            if False:
                L = top-bot
                Lx = len(edge["xposs"])
                for i in xrange(Lx):
                    xp = edge["xposs"][i]
                    frac1 = (edge["top"](xp)-bot-1)/L
                    pl.axvline(xp,ymin=frac1)

                for xp in edgeprev["xposs"]: 
                    frac2 = (edgeprev["bottom"](xp)-bot)/L
                    pl.axvline(xp,ymax=frac2)

            start += dy
Esempio n. 24
0
def centerofmass(array,threshold=None,useBrightest=0):
    '''
    array is a float 32 2-dimensional numpy array
    cent = numpy.array([x,y])
    '''
    newarray = None
    useBrightest = int(useBrightest)
    if(threshold!=None):
        boolarray = array>=threshold
        newarray = boolarray*array
    else:
        newarray = array + 0

    if(useBrightest>0):
        newarray = brightest(newarray,useBrightest)

    #Classic
    cent = np.zeros(2)
    totalmass = float(newarray.sum())
    Xgrid,Ygrid = np.meshgrid(np.arange(newarray.shape[1]),np.arange(newarray.shape[0]))
    if totalmass<1.0:
        print 'totalmass: ',
        print totalmass
        imshow(newarray)
        show()

    cent[1] = np.sum(Ygrid*newarray)/totalmass
    cent[0] = np.sum(Xgrid*newarray)/totalmass
    return cent
Esempio n. 25
0
def explore_data(data, images, target):

	# try to determine the type of data...
	print "data_type belonging to key data:"
	try: 
		print np.dtype(data)
	except TypeError as err:
		print err
	
	print "It has dimension", np.shape(data)

	# plot a 3
	
	# get indices of all threes in target
	threes = np.where(target == 3)
	#assert threes is not empty
	assert(len(threes) > 0)
	# choose the first 3
	three_indx = threes[0]
	# get the image
	img = images[three_indx][0]

	#plot it
	plot.figure()
	plot.gray()
	plot.imshow(img, interpolation = "nearest")
	plot.show()
	plot.close()
Esempio n. 26
0
def ST_pi_pure(r,steps = 99):
	"""
	Makes a heat map over ST space for a given value of r, using the pure strategy model, plotting
	fitness.

	Inputs
	======
	r : float
		Value of relatedness
	steps : int {99}
		Number of points to sample S and T at.

	"""

	Ss = np.linspace(-1,2,steps)
	Ts = np.linspace(0,3,steps)
	dataFull = np.zeros( (steps,steps) )
	for i,S in enumerate(Ss):
		for j,T in enumerate(Ts):
			x = ESS_pure(r,S,T)
			dataFull[i,j] = fit_pure(x,r,S,T)/maximal_possible_fitness(S,T)

	#pl.figure()
	cmap = pl.get_cmap('Reds')
	pl.imshow(dataFull, origin = [Ts[0], Ss[0]], interpolation = 'nearest',\
			extent = [ Ts[0],Ts[-1],Ss[0],Ss[-1] ], cmap = cmap, vmin = 0, vmax = .5*(Ss[-1]+Ts[-1]))
	pl.plot( [ Ts[0], Ts[-1] ],[ 0,0 ],color='black', linewidth = 2.5 )
	pl.plot( [ 1, 1 ],[ Ss[0],Ss[-1] ],'--',color='black',  linewidth = 2.5 )
	pl.plot( [ 0, 3 ],[ 2, -1 ],'--',color='black',  linewidth = 2.5 )
Esempio n. 27
0
def main():
    src_cv_img_1 = cv.LoadImage("data/gorskaya/images/1/g126.jpg")
    src_cv_img_gray_1 = cv.LoadImage("data/gorskaya/images/1/g126.jpg", 
        cv.CV_LOAD_IMAGE_GRAYSCALE)

    src_cv_img_2 = cv.LoadImage("data/gorskaya/images/1/g127.jpg")
    src_cv_img_gray_2 = cv.LoadImage("data/gorskaya/images/1/g127.jpg", 
        cv.CV_LOAD_IMAGE_GRAYSCALE)

    (keypoints_1, descriptors_1) = \
        cv.ExtractSURF(src_cv_img_gray_1, None, cv.CreateMemStorage(), 
            (0, 30000, 3, 1))
    (keypoints_2, descriptors_2) = \
        cv.ExtractSURF(src_cv_img_gray_2, None, cv.CreateMemStorage(), 
            (0, 30000, 3, 1))

    print("Found {0} and {1} keypoints".format(
        len(keypoints_1), len(keypoints_2)))

    src_arr_1 = array(src_cv_img_1[:, :])[:, :, ::-1]
    src_arr_2 = array(src_cv_img_2[:, :])[:, :, ::-1]

    pylab.rc('image', interpolation='nearest')

    pylab.subplot(121)
    pylab.imshow(src_arr_1)
    pylab.plot(*zip(*[k[0] for k in keypoints_1]), 
        marker='.', color='r', ls='')

    pylab.subplot(122)
    pylab.imshow(src_arr_2)
    pylab.plot(*zip(*[k[0] for k in keypoints_2]), 
        marker='.', color='r', ls='')

    pylab.show()
Esempio n. 28
0
def ShowDynamicalResults(indexmap,output):
    import pylab
    pylab.figure()
    for i in range(4):
        pylab.subplot('22'+str(i+1))
        pylab.imshow(indexmap[i],interpolation='nearest')
    pylab.savefig(output+'.png')
Esempio n. 29
0
def ST_xA(r,steps = 99):
	"""
	Makes a heat map for x over ST space for a given r using the full model.
	inputs
	======
	r : float
		Value of relatedness
	steps: int {99}
		Number of decrete points at which to sample S and T

	"""


	Ss = np.linspace(-1,2,steps)
	Ts = np.linspace(0,3,steps)
	dataFull = np.zeros( (steps,steps) )
	for i,S in enumerate(Ss):
		for j,T in enumerate(Ts):
			mod = ESS_class(r,S,T)
			state = mod.getESS()
			dataFull[i,j] = mod.xA(state,r)

	#pl.figure()
	cmap = pl.get_cmap('Reds')
	pl.imshow(dataFull, origin = [Ts[0], Ss[0]],\
			extent = [ Ts[0],Ts[-1],Ss[0],Ss[-1] ], vmin = 0,vmax = 1, cmap = cmap)
	pl.plot( [ Ts[0], Ts[-1] ],[ 0,0 ],color='black', linewidth = 2.5 )
	pl.plot( [ 1, 1 ],[ Ss[0],Ss[-1] ],'--',color='black',  linewidth = 2.5 )
	pl.plot( [ 0, 3 ],[ 2, -1 ],'--',color='black',  linewidth = 2.5 )
Esempio n. 30
0
def dispims_color(M, border=0, bordercolor=[0.0, 0.0, 0.0], savePath=None, *imshow_args, **imshow_keyargs):
    """ Display an array of rgb images. 

    The input array is assumed to have the shape numimages x numpixelsY x numpixelsX x 3
    """
    bordercolor = numpy.array(bordercolor)[None, None, :]
    numimages = len(M)
    M = M.copy()
    for i in range(M.shape[0]):
        M[i] -= M[i].flatten().min()
        M[i] /= M[i].flatten().max()
    height, width, three = M[0].shape
    assert three == 3
    
    n0 = numpy.int(numpy.ceil(numpy.sqrt(numimages)))
    n1 = numpy.int(numpy.ceil(numpy.sqrt(numimages)))
    im = numpy.array(bordercolor)*numpy.ones(
                             ((height+border)*n1+border,(width+border)*n0+border, 1),dtype='<f8')
    for i in range(n0):
        for j in range(n1):
            if i*n1+j < numimages:
                im[j*(height+border)+border:(j+1)*(height+border)+border,
                   i*(width+border)+border:(i+1)*(width+border)+border,:] = numpy.concatenate((
                  numpy.concatenate((M[i*n1+j,:,:,:],
                         bordercolor*numpy.ones((height,border,3),dtype=float)), 1),
                  bordercolor*numpy.ones((border,width+border,3),dtype=float)
                  ), 0)
    imshow_keyargs["interpolation"]="nearest"
    pylab.imshow(im, *imshow_args, **imshow_keyargs)
    
    if savePath == None:
        pylab.show()
    else:
        pylab.savefig(savePath)
Esempio n. 31
0
n1 = WNoiseGenerator( sample_freq=sfreq, numsamples=nsamples, seed=1 )
n2 = WNoiseGenerator( sample_freq=sfreq, numsamples=nsamples, seed=2, rms=0.7 )
n3 = WNoiseGenerator( sample_freq=sfreq, numsamples=nsamples, seed=3, rms=0.5 )
p1 = PointSource( signal=n1, mpos=mg,  loc=(-0.1,-0.1,0.3) )
p2 = PointSource( signal=n2, mpos=mg,  loc=(0.15,0,0.3) )
p3 = PointSource( signal=n3, mpos=mg,  loc=(0,0.1,0.3) )
pa = Mixer( source=p1, sources=[p2,p3] )
wh5 = WriteH5( source=pa, name=h5savefile )
wh5.save()

# analyze the data and generate map
ts = TimeSamples( name=h5savefile )
ps = PowerSpectra( time_data=ts, block_size=128, window='Hanning' )
rg = RectGrid( x_min=-0.2, x_max=0.2, y_min=-0.2, y_max=0.2, z=0.3, \
increment=0.01 )
bb = BeamformerBase( freq_data=ps, grid=rg, mpos=mg )
pm = bb.synthetic( 8000, 3 )
Lm = L_p( pm )

# show map
imshow( Lm.T, origin='lower', vmin=Lm.max()-10, extent=rg.extend(), \
interpolation='bicubic')
colorbar()

# plot microphone geometry
figure(2)
plt.plot(mg.mpos[0],mg.mpos[1],'o')
axis('equal')

show()
Esempio n. 32
0
    print('One file only, not saving!')
    fname_new = name_new[0]
#%%
# fname_new='Yr_d1_501_d2_398_d3_1_order_F_frames_369_.mmap'
Yr, dims, T = cm.load_memmap(fname_new)
d1, d2 = dims
images = np.reshape(Yr.T, [T] + list(dims), order='F')
Y = np.reshape(Yr, dims + (T, ), order='F')
#%%
if np.min(images) < 0:
    raise Exception('Movie too negative, add_to_movie should be larger')
if np.sum(np.isnan(images)) > 0:
    raise Exception('Movie contains nan! You did not remove enough borders')
#%%
Cn = cm.local_correlations(Y[:, :, :3000])
pl.imshow(Cn, cmap='gray')

#%%
if not is_patches:
    #%%
    K = 35  # number of neurons expected per patch
    gSig = [7, 7]  # expected half size of neurons
    merge_thresh = 0.8  # merging threshold, max correlation allowed
    p = 2  # order of the autoregressive system
    cnm = cnmf.CNMF(n_processes,
                    method_init=init_method,
                    k=K,
                    gSig=gSig,
                    merge_thresh=merge_thresh,
                    p=p,
                    dview=dview,
Esempio n. 33
0
#!/usr/bin/env python

from inputimages import f0, f180
from scipy import ndimage
import numpy as np

rotation = 3.2

data0 = f0.getData()
data0 = ndimage.rotate(data0, rotation)

data180 = f180.getData()
data180 = np.fliplr(data180)

import pylab
# pylab.imshow(data0)
pylab.imshow(data180)
pylab.colorbar()
pylab.show()
Esempio n. 34
0
        z = z * z + c
        if (z.real * z.real + z.imag * z.imag) >= 4:
            return i

    return 255


@autojit
def create_fractal(min_x, max_x, min_y, max_y, image, iters):
    height = image.shape[0]
    width = image.shape[1]

    pixel_size_x = (max_x - min_x) / width
    pixel_size_y = (max_y - min_y) / height
    for x in range(width):
        real = min_x + x * pixel_size_x
        for y in range(height):
            imag = min_y + y * pixel_size_y
            color = mandel(real, imag, iters)
            image[y, x] = color

    return image


image = np.zeros((1024, 1024), dtype=np.uint8)
#image = np.zeros((500, 750), dtype=np.uint8)
imshow(create_fractal(-2.0, 1.0, -1.0, 1.0, image, 20))
jet()
ion()
show()
Esempio n. 35
0
from PIL import Image
import numpy as np
import pylab as pl
from scipy.ndimage import filters, measurements, morphology
from common import imtools

# Apply the label() function to a thresholded image of your choice. Use histograms
# and the resulting label image to plot the distribution of object sizes in the image.

im = np.array(Image.open('data/aircraft-formation.jpg').convert('L'))
im_bin = 1 * (im < 128)

#labels, nbr_objects = measurements.label(im_bin)
im_open = morphology.binary_opening(im_bin, np.ones((9, 5)), iterations=1)
labels_open, nbr_objects_open = measurements.label(im_open)
print('Number of objects:', nbr_objects_open)

pl.figure('Labels')
pl.subplot(1, 2, 1)
pl.gray()
pl.title('Labeled Image')
pl.imshow(labels_open)
pl.subplot(1, 2, 2)
pl.title('Histogram')
pl.hist(labels_open.flatten(), bins=nbr_objects_open, log=True)

pl.show()
    total_labels = np.array(total_labels)[rand_perm]
    np.savez('use_cases/edge-cutter/residual_crops_all_classes.npz',
             all_masks_gt=total_crops, labels_gt=total_labels)
#%%
# the data, shuffled and split between train and test sets
with np.load('use_cases/edge-cutter/residual_crops_all_classes.npz') as ld:
    all_masks_gt = ld['all_masks_gt']
    labels_gt = ld['labels_gt']
#%%
num_sampl = 30000
predictions = loaded_model.predict(
    all_masks_gt[:num_sampl, :, :, None], batch_size=32, verbose=1)
#cm.movie(np.squeeze(all_masks_gt[np.where(predictions[:num_sampl,1]<0.1)[0]])).play(gain=3., magnification = 5, fr = 10)
#%%
from skimage.util.montage import montage2d
pl.imshow(montage2d(all_masks_gt[np.where((labels_gt[:num_sampl] == 2) & (
    predictions[:num_sampl, 0] <= 0.5))[0]].squeeze()))
#%%
fname_new = '/mnt/ceph/neuro/labeling/neurofinder.03.00.test/images/final_map/Yr_d1_498_d2_467_d3_1_order_C_frames_2250_.mmap'
gSig = [8, 8]
gt_file = os.path.join(os.path.split(fname_new)[0], os.path.split(
    fname_new)[1][:-4] + 'match_masks.npz')
base_name = fname_new.split('/')[5]
maxT = 8100
with np.load(gt_file, encoding='latin1') as ld:
    print(ld.keys())
    locals().update(ld)
    A_gt = scipy.sparse.coo_matrix(A_gt[()])
    dims = (d1, d2)
    C_gt = C_gt[:, :maxT]
    YrA_gt = YrA_gt[:, :maxT]
    f_gt = f_gt[:, :maxT]
Esempio n. 37
0
def showrgb(r,g=None,b=None):
    if g is None: g = r
    if b is None: b = r
    imshow(array([r,g,b]).transpose([1,2,0]))
Esempio n. 38
0
save_movie_rigid = True  # save the movies vs just get the template
t1 = time.time()
fname_tot_rig, total_template_rig, templates_rig, shifts_rig = cm.motion_correction.motion_correct_batch_rigid(
    fname,
    max_shifts,
    dview=dview,
    splits=splits,
    num_splits_to_process=num_splits_to_process,
    num_iter=num_iter,
    template=None,
    shifts_opencv=shifts_opencv,
    save_movie_rigid=save_movie_rigid)
t2 = time.time() - t1
print(t2)
pl.imshow(total_template_rig,
          cmap='gray',
          vmax=np.percentile(total_template_rig, 95))
#%%
pl.close()
pl.plot(shifts_rig)
#%%
m_rig = cm.load(fname_tot_rig)
#%%
add_to_movie = -np.min(total_template_rig) + 1
print(add_to_movie)
#%% visualize movies

m_rig.resize(1, 1, .2).play(fr=30,
                            gain=5,
                            magnification=1,
                            offset=add_to_movie)
Esempio n. 39
0
mags, dircts, dircts_thresh, spatial_masks_thrs = cm.behavior.behavior.extract_magnitude_and_angle_from_OF(
    spatial_filter_,
    time_trace_,
    of_or,
    num_std_mag_for_angle=num_std_mag_for_angle,
    sav_filter_size=3,
    only_magnitude=only_magnitude)
#%% if you want to visualize optical flow
ms = [mask * fr for fr in m]
ms = np.dstack(ms)
ms = cm.movie(ms.transpose([2, 0, 1]))
_ = cm.behavior.behavior.compute_optical_flow(ms,
                                              do_show=True,
                                              polar_coord=True)

#%% spatial components
count = 0
for comp in spatial_filter_:
    count += 1
    pl.subplot(2, 2, count)
    pl.imshow(comp)
#%% temporal components (magnitude and angle in polar coordinates)
count = 0
for magnitude, angle in zip(mags, dircts):
    count += 1
    pl.subplot(2, 2, count)
    pl.plot(magnitude / np.nanmax(magnitude))
    angle_ = angle.copy()
    angle_[magnitude < np.std(magnitude) * 1.5] = np.nan
    pl.plot(angle_ / 2 / np.pi)
Esempio n. 40
0
    def plot_item(self, m, ind, x, r, k, label, U, scores, feature_weights):
        """
    plot_item(self, m, ind, x, r, k, label, U, scores, feature_weights):
    
    Plot selection m (index ind, data in x) and its reconstruction r,
    with k and label to annotate of the plot.

    Also show the residual and the RGB visualization of the selected image.

    U, scores, and feature_weights are optional; ignored in this method,
    used in some classes' submethods.
    """

        if x == [] or r == []:
            print "Error: No data in x and/or r."
            return

        vmin = min(np.nanmin(x), np.nanmin(r))
        vmax = max(np.nanmax(x), np.nanmax(r))

        # Create my own color map; middle is neutral/gray, high is red, low is blue.
        cdict = {
            'red': ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)),
            'green': ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)),
            'blue': ((0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0))
        }
        cmap = matplotlib.colors.LinearSegmentedColormap('res', cdict, 256)

        matplotlib.rc('axes', edgecolor='w')

        pylab.figure()
        pylab.subplots_adjust(wspace=0.1, left=0)

        # FIRST SUBPLOT: filterbank data

        pylab.subplot(2, 2, 1)
        im = pylab.imshow(x.reshape((self.nfreq, self.ntime)),
                          vmin=vmin,
                          vmax=vmax)
        pylab.tick_params(\
          axis='both',          # changes apply to the x-axis
          which='both',      # both major and minor ticks are affected
          bottom='off',      # ticks along the bottom edge are off
          left='off',      # ticks along the left edge are off
          right='off',      # ticks along the right edge are off
          top='off',         # ticks along the top edge are off
          labelbottom='off', # labels along the bottom edge are off
          labelleft='off')   # labels along the left edge are off?
        pylab.xlabel('Original Data')

        pylab.colorbar(im)

        # SECOND SUBPLOT: reconstructed data

        pylab.subplot(2, 2, 2)
        im = pylab.imshow(r.reshape((self.nfreq, self.ntime)),
                          vmin=vmin,
                          vmax=vmax)
        pylab.tick_params(\
          axis='both',          # changes apply to the x-axis
          which='both',      # both major and minor ticks are affected
          bottom='off',      # ticks along the bottom edge are off
          left='off',      # ticks along the left edge are off
          right='off',      # ticks along the right edge are off
          top='off',         # ticks along the top edge are off
          labelbottom='off', # labels along the bottom edge are off
          labelleft='off')   # labels along the left edge are off?
        pylab.xlabel('Reconstructed Data')
        pylab.colorbar(im)

        # THIRD SUBPLOT: residual data

        pylab.subplot(2, 2, 3)
        resid = x - r

        # Tweak vmin and vmax so 0 is always in the middle (white)
        absmax = max(abs(vmin), abs(vmax))
        im = pylab.imshow(resid.reshape((self.nfreq, self.ntime)),
                          cmap=cmap,
                          vmin=-absmax,
                          vmax=absmax)
        pylab.tick_params(\
          axis='both',          # changes apply to the x-axis
          which='both',      # both major and minor ticks are affected
          bottom='off',      # ticks along the bottom edge are off
          left='off',      # ticks along the left edge are off
          right='off',      # ticks along the right edge are off
          top='off',         # ticks along the top edge are off
          labelbottom='off', # labels along the bottom edge are off
          labelleft='off')   # labels along the left edge are off?
        pylab.xlabel('Residual')

        cbar = pylab.colorbar(im)

        pylab.suptitle('DEMUD selection %d (%s), item %d, using K=%d' % \
                       (m, label, ind, k))

        outdir = os.path.join('results', self.name)
        if not os.path.exists(outdir):
            os.mkdir(outdir)
        figfile = os.path.join(outdir,
                               '%s-sel-%d-k-%d.pdf' % (self.name, m, k))
        pylab.savefig(figfile, bbox_inches='tight', pad_inches=0.1)
        pylab.close()
Esempio n. 41
0
    def testMergeHeavyFootprints(self):
        mi = afwImage.MaskedImageF(20, 10)
        objectPixelVal = (42, 0x9, 400)

        spanList = []
        for y, x0, x1 in [(1, 9, 12), (2, 12, 13), (3, 11, 15)]:
            spanList.append(afwGeom.Span(y, x0, x1))
            for x in range(x0, x1 + 1):
                mi[x, y, afwImage.LOCAL] = objectPixelVal

        foot = afwDetect.Footprint(afwGeom.SpanSet(spanList))

        hfoot1 = afwDetect.makeHeavyFootprint(self.foot, self.mi)
        hfoot2 = afwDetect.makeHeavyFootprint(foot, mi)

        hsum = afwDetect.mergeHeavyFootprints(hfoot1, hfoot2)

        bb = hsum.getBBox()
        self.assertEqual(bb.getMinX(), 9)
        self.assertEqual(bb.getMaxX(), 15)
        self.assertEqual(bb.getMinY(), 1)
        self.assertEqual(bb.getMaxY(), 3)

        msum = afwImage.MaskedImageF(20, 10)
        hsum.insert(msum)

        sa = msum.getImage().getArray()

        self.assertFloatsEqual(sa[1, 9:13], objectPixelVal[0])
        self.assertFloatsEqual(sa[2, 12:14],
                               objectPixelVal[0] + self.objectPixelVal[0])
        self.assertFloatsEqual(sa[2, 10:12], self.objectPixelVal[0])

        sv = msum.getVariance().getArray()

        self.assertFloatsEqual(sv[1, 9:13], objectPixelVal[2])
        self.assertFloatsEqual(sv[2, 12:14],
                               objectPixelVal[2] + self.objectPixelVal[2])
        self.assertFloatsEqual(sv[2, 10:12], self.objectPixelVal[2])

        sm = msum.getMask().getArray()

        self.assertFloatsEqual(sm[1, 9:13], objectPixelVal[1])
        self.assertFloatsEqual(sm[2, 12:14],
                               objectPixelVal[1] | self.objectPixelVal[1])
        self.assertFloatsEqual(sm[2, 10:12], self.objectPixelVal[1])

        if False:
            import matplotlib
            matplotlib.use('Agg')
            import pylab as plt
            im1 = afwImage.ImageF(bb)
            hfoot1.insert(im1)
            im2 = afwImage.ImageF(bb)
            hfoot2.insert(im2)
            im3 = afwImage.ImageF(bb)
            hsum.insert(im3)
            plt.clf()
            plt.subplot(1, 3, 1)
            plt.imshow(im1.getArray(), interpolation='nearest', origin='lower')
            plt.subplot(1, 3, 2)
            plt.imshow(im2.getArray(), interpolation='nearest', origin='lower')
            plt.subplot(1, 3, 3)
            plt.imshow(im3.getArray(), interpolation='nearest', origin='lower')
            plt.savefig('merge.png')
Esempio n. 42
0
for j in range(16):
    new_pos = seq.predict(track[np.newaxis, ::, ::, ::, ::])
    new = new_pos[::, -1, ::, ::, ::]
    track = np.concatenate((track, new), axis=0)

# And then compare the predictions
# to the ground truth
track2 = noisy_movies[which][::, ::, ::, ::]
for i in range(15):
    fig = plt.figure(figsize=(10, 5))

    ax = fig.add_subplot(121)

    if i >= 7:
        ax.text(1, 3, 'Predictions !', fontsize=20, color='w')
    else:
        ax.text(1, 3, 'Initial trajectory', fontsize=20)

    toplot = track[i, ::, ::, 0]

    plt.imshow(toplot)
    ax = fig.add_subplot(122)
    plt.text(1, 3, 'Ground truth', fontsize=20)

    toplot = track2[i, ::, ::, 0]
    if i >= 2:
        toplot = shifted_movies[which][i - 1, ::, ::, 0]

    plt.imshow(toplot)
    plt.savefig('%i_animate.png' % (i + 1))
Esempio n. 43
0
fig.canvas.mpl_connect('scroll_event', on_scroll)

bg = pylab.imread(
    os.path.join(os.path.join(path, 'images'), args.locale + '.jpg'))
pylab.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
ax = pylab.subplot(111)

bg_width = 27.7
bg_height = 16.66
corner_offset_x = -5.5
corner_offset_y = -bg_height + 3

extent = (corner_offset_x, bg_width + corner_offset_x, corner_offset_y,
          bg_height + corner_offset_y)
pylab.imshow(bg, extent=extent, origin='lower')

xs = [m['position'][1] for m in marks]
ys = [m['position'][0] for m in marks]
reverse = {
    ind: marks[ind]['tag' if args.tags else 'object']
    for ind in range(len(marks))
}
labels = [
    m['object'] + ('' if m['tag'] is None else ' (' + m['tag'] + ')')
    for m in marks
]

point_plot = pylab.plot(xs, ys, 'ro', picker=10.0, pickradius=8,
                        markersize=8)[0]
label_texts = []
Esempio n. 44
0
print('Cafe sale: {}'.format(cafe_prod))
print('Total croissants : {}'.format(cafe_prod.sum()))


#%% #### Plotting bakeries in the city
# 
# Next we plot the position of the bakeries and cafés on the map. The size of the circle is proportional to their production.
# 

# In[4]:



pl.figure(1,(8,7))
pl.clf()
pl.imshow(Imap,interpolation='bilinear') # plot the map
pl.scatter(bakery_pos[:,0],bakery_pos[:,1],s=bakery_prod,c='r', edgecolors='k',label='Bakeries')
pl.scatter(cafe_pos[:,0],cafe_pos[:,1],s=cafe_prod,c='b', edgecolors='k',label='Cafés')
pl.legend()
pl.title('Manhattan Bakeries and Cafés');


#%% #### Cost matrix
# 
# 
# We compute the cost matrix between the bakeries and the cafés, this will be the transport cost matrix. This can be done using the [ot.dist](http://pot.readthedocs.io/en/stable/all.html#ot.dist) that defaults to squared euclidean distance but can return other things such as cityblock (or manhattan distance). 
# 
# 

#%% #### Solving the OT problem with [ot.emd](http://pot.readthedocs.io/en/stable/all.html#ot.emd)
Esempio n. 45
0
    ss=None,
    dview=dview)

A_off_thr = A_off_thr > 0
size_neurons = A_off_thr.sum(0)
A_off_thr = A_off_thr[:, (size_neurons > min_size_neuro)
                      & (size_neurons < max_size_neuro)]
C_off_thr = C_off[(size_neurons > min_size_neuro) &
                  (size_neurons < max_size_neuro), :116000]
print(A_off_thr.shape)

C_off_thr = np.array(
    [CC.reshape([-1, n_frames_per_bin]).max(1) for CC in C_off_thr])
#%%
pl.figure()
pl.imshow(A_off_thr.sum(-1).reshape(dims_off, order='F'))

#%%
if False:
    online_file = 'results_analysis_online_JEFF_DS_2_1.0.npz'
    with np.load(online_file) as ld:
        print(ld.keys())
        locals().update(ld)
#%%
# with np.load('results_full_movie_online_may5/results_analysis_online_JEFF_90k.take7_no_batch.npz') as ld:
#online_file ='/opt/local/privateCaImAn/JEFF_MAY_14_AFT_BETTER_INIT_UPDATES_NO_STATS/results_analysis_online_JEFF_LAST_90000.npz'
#online_file ='/mnt/ceph/neuro/DataForPublications/OnlineCNMF/Jeff/EP_linux/results_analysis_online_JEFF_LAST__DS_2_90000.npz'
#online_file  = '/opt/local/privateCaImAn/RES_NIPS_JEFF_r_val_0.85_fitness_-40-20/results_analysis_online_JEFF_DS_2.npz'
online_file = '/mnt/home/agiovann/SOFTWARE/privateCaImAn/results_analysis_online_neurofinder.03.00t.npz'

#online_file ='/mnt/ceph/neuro/SUE_results_online_DS/results_analysis_online_SUE__DS_2_116043.npz'
Esempio n. 46
0
def plot_image(image, title, path):
    pl.figure()
    pl.imshow(image)
    pl.title(title)
    pl.savefig(path)
Esempio n. 47
0
            return '{}_color.png'.format(mode)
        else:
            return '{}_polygons.json'.format(mode)


if __name__ == "__main__":
    dataset = CityScapes(split="train", exp_dict={})
    batch = dataset[0]
    images = batch["images"]
    masks = batch["masks"]

    inv_normalize = transforms.Normalize(
        mean=[-0.485 / 0.229, -0.456 / 0.224, -0.406 / 0.225],
        std=[1 / 0.229, 1 / 0.224, 1 / 0.255])

    inv_image = inv_normalize(images.float())

    # combined = 0.5*inv_image + 0.5*masks
    masks_arr = np.array(FT.to_pil_image(masks.float()))
    images_arr = np.array(FT.to_pil_image(inv_image.float()))

    image_label_overlay = label2rgb(masks_arr, image=images_arr)

    inv_image = FT.to_pil_image(inv_image)

    plt.imshow(images_arr)
    plt.savefig("img.png")
    plt.imshow(masks_arr)
    plt.savefig("mask.png")
    plt.imshow(image_label_overlay)
    plt.savefig("overlay.png")
Esempio n. 48
0
def _lss_corr(obs,
              interactive=True,
              maxcr=False,
              figno=20,
              rawxy=None,
              target='target',
              chatter=0):
    '''determine the LSS correction for the readout streak source '''
    import os
    import numpy as np
    try:
        from astropy.io import fits
    except:
        import pyfits as fits
    from pylab import figure,imshow,ginput,axvspan,\
         axhspan,plot,autumn,title,clf
    file = obs['infile']
    ext = obs['extension']
    cols = obs['streak_col_SN_CR_ERR']
    kol = []
    countrates = []
    circle = [
        np.sin(np.arange(0, 2 * np.pi, 0.05)),
        np.cos(np.arange(0, 2 * np.pi, 0.05))
    ]
    for k in cols:
        kol.append(k[1])  # S/N
        countrates.append(k[2])
    kol = np.array(kol)
    if len(kol) == 0:
        print("zero array kol in _lss_corr ???!!!!")
        print("LSS correction cannot be determined.")
        return 1.0, (0, 0), (1100.5, 1100.5)
    k_sn_max = np.where(np.max(kol) == kol)  # maximum s/n column
    print("k S/N max=", k_sn_max[0][0])
    kol = []
    for k in cols:
        kol.append(k[0])  # column number relative to bottom rh corner subimage
    if len(kol) == 0:
        print("LSS correction cannot be determined.")
        return 1.0, (0, 0), (1100.5, 1100.5)
    im = fits.getdata(file, ext=ext)
    hdr = fits.getheader(file, ext=ext)
    #binx = hdr['binx']
    mn = im.mean()
    sig = im.std()
    #   plot
    figure(figno)
    clf()
    autumn()
    imshow(im, vmin=mn - 0.2 * sig, vmax=mn + 2 * sig)
    if rawxy != None:
        rawx, rawy = rawxy
        R = hdr['windowdx'] / 15.
        plot(R * circle[0] + rawx - hdr['windowy0'],
             R * circle[1] + rawy - hdr['windowx0'],
             '-',
             color='m',
             alpha=0.7,
             lw=2)
    title(u"PUT CURSOR on your OBJECT", fontsize=16)
    if not maxcr:
        count = 0
        for k in kol:
            axvspan(k - 6,
                    k + 6,
                    0.01,
                    0.99,
                    facecolor='k',
                    alpha=0.3 - 0.02 * count)
            count += 1
    else:
        k = k_sn_max[0][0]
        axvspan(k - 10, k + 10, 0.01, 0.99, facecolor='k', alpha=0.2)
    happy = False
    skip = False
    count = 0
    while not happy:
        print("put the cursor on the location of your source")
        count += 1
        coord = ginput(timeout=0)
        print("selected:", coord)
        if len(coord[0]) == 2:
            print("window corner:", hdr['windowx0'], hdr['windowy0'])
            xloc = coord[0][0] + hdr['windowx0']
            yloc = coord[0][1] + hdr['windowy0']
            print("on detector (full raw image)  should be :", xloc, yloc)
            #plot(coord[0][0],coord[0][1],'+',markersize=14,color='k',lw=2) #can't see it
            axhspan(coord[0][1] - 6,
                    coord[0][1] + 6,
                    0,
                    1,
                    facecolor='k',
                    alpha=0.3)
            if rawxy != None:
                rawx, rawy = rawxy
                R = hdr['windowdx'] / 15.
                plot(R * circle[0] + rawx - hdr['windowx0'],
                     R * circle[1] + rawy - hdr['windowy0'],
                     '-',
                     color='k',
                     alpha=0.7,
                     lw=1)
                #plot(rawx-hdr['windowx0'],rawy-hdr['windowy0'],'o',markersize=25,color='w',alpha=0.3)
            ans = raw_input("happy (yes,skip,no): ")
            if len(ans) > 0:
                if ans.upper()[0] == 'Y':
                    happy = True
                if ans.upper()[0] == 'S':
                    return 0.0, coord[0], (yloc + 104, xloc + 78)
        else:
            print("no position found")
        if count > 10:
            print("Too many tries: aborting")
            happy = True
    im = ''
    try:
        lss = 1.0
        band = obs['band']
        caldb = os.getenv('CALDB')
        command = "quzcif swift uvota - "+band.upper()+\
           " SKYFLAT "+\
           obs['dateobs'].split('T')[0]+"  "+\
    obs['dateobs'].split('T')[1]+" - > lssfile.1234.tmp"
        print(command)
        os.system(command)
        f = open('lssfile.1234.tmp')
        lssfile = f.readline()
        f.close()
        f = fits.getdata(lssfile.split()[0], ext=int(lssfile.split()[1]))
        lss = f[yloc, xloc]
        print("lss correction = ", lss, "  coords=", coord[0],
              (yloc + 104, xloc + 78))
        return lss, coord[0], (yloc + 104, xloc + 78)
    except:
        print("LSS correction cannot be determined.")
        return 1.0, (0, 0), (1100.5, 1100.5)
Esempio n. 49
0
        generator.cleargrads()
        vgg.cleargrads()
        gen_loss.backward()
        gen_opt.update()
        vgg_opt.update()
        gen_loss.unchain_backward()

        sum_dis_loss += loss_dis.data.get()
        sum_gen_loss += gen_loss.data.get()

        if epoch % interval == 0 and batch == 0:
            serializers.save_npz("%s/generator_%d.model"%(outdir,epoch), generator)
            with chainer.using_config("train", False):
                y = generator(x_test)
            y = y.data.get()
            sr = x_test.data.get()
            for i_ in range(testsize):
                tmp = (np.clip((sr[i_,:,:,:])*127.5 + 127.5, 0, 255)).transpose(1,2,0).astype(np.uint8)
                pylab.subplot(testsize,2,2*i_+1)
                pylab.imshow(tmp)
                pylab.axis('off')
                pylab.savefig('%s/visualize_%d.png'%(outdir, epoch))
                tmp = (np.clip((y[i_,:,:,:])*127.5 + 127.5, 0, 255)).transpose(1,2,0).astype(np.uint8)
                pylab.subplot(testsize,2,2*i_+2)
                pylab.imshow(tmp)
                pylab.axis('off')
                pylab.savefig('%s/visualize_%d.png'%(outdir, epoch))

    print("epoch : {}".format(epoch))
    print("Discriminator loss : {}".format(sum_dis_loss / Ntrain))
    print("Generator loss : {}".format(sum_gen_loss / Ntrain))
Esempio n. 50
0
    c = complex(x, y)
    Z = complex(0, 0)

    for i in range(iterations):
        Z = Z**2 + c
        if abs(Z) >= 2:
            return i

    return 255


def fractal(x_axis, y_axis, iterations, height=500, width=750):
    img = np.zeros((height, width))

    pixel_size_x = (x_axis['max'] - x_axis['min']) / width
    pixel_size_y = (y_axis['max'] - y_axis['min']) / height

    for x in range(width):
        real_x = x_axis['min'] + x * pixel_size_x
        for y in range(height):
            real_y = y_axis['min'] + y * pixel_size_y
            img[y, x] = mandelbrot(real_x, real_y, iterations)

    return img


if __name__ == '__main__':
    image = fractal({'min': -2, 'max': 1}, {'min': -1, 'max': 1}, 100)
    pl.imshow(image, cmap='prism')
    pl.show()
Esempio n. 51
0
# 载入模型进行图像类别预测
saver = tf.train.Saver()
savedir = "./model"
with tf.Session() as sess:
    # 当保存的是某次迭代后得到的模型(训练中断保存了检查点),载入该模型
    ckpt = tf.train.latest_checkpoint(savedir)  # 得到中断时所保存的checkpoint
    if ckpt != None:
        saver.restore(sess, ckpt)  # 利用这次checkpoint载入模型

    output = tf.argmax(pred, 1)
    batch_xs, batch_ys = mnist.train.next_batch(2)
    output_class, pred_prob = sess.run([output, pred],
                                       feed_dict={
                                           x: batch_xs,
                                           y: batch_ys
                                       })
    print("Actual class:", tf.argmax(batch_ys, 1).eval())
    print("Prediction class:", output_class)
    print("One-hot probability:", pred_prob)

    im = batch_xs[0]
    im = im.reshape(-1, 28)
    pylab.imshow(im)
    pylab.show()

    im = batch_xs[1]
    im = im.reshape(-1, 28)
    pylab.imshow(im)
    pylab.show()
Esempio n. 52
0
from PIL import Image
from PCV.tools.pca import pca
from utils.imtools import *
import pylab as plt
import numpy as np

imlist = get_imlist(os.getcwd() + '/images/fontimages/a_thumbs')

# Open one image to get size
im = np.array(Image.open(imlist[0]))
m, n = im.shape[0:2]
imnbr = len(imlist)

# Create matrix to store all flatted images
immatrix = np.array(
    [np.array(Image.open(impath)).flatten() for impath in imlist], 'f')

# Perform PCA
V, S, immean = pca(immatrix)

# Show some images
plt.figure()
plt.gray()
plt.subplot(241)
plt.imshow(immean.reshape(m, n))
for i in range(7):
    plt.subplot(2, 4, i + 2)
    plt.imshow(V[i].reshape(m, n))

plt.show()
Esempio n. 53
0
                             EllipseESoft(0., 0., 0.))

    tractor = Tractor(tims, [galaxy])

    # Plot images
    ima = dict(interpolation='nearest',
               origin='lower',
               cmap='gray',
               vmin=-5. * pixnoise,
               vmax=20. * pixnoise)
    plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.92)
    plt.clf()
    for i, band in enumerate(bands):
        for e in range(nepochs):
            plt.subplot(nepochs, len(bands), e * len(bands) + i + 1)
            plt.imshow(tims[nepochs * i + e].getImage(), **ima)
            plt.xticks([])
            plt.yticks([])
            plt.title('%s #%i' % (band, e + 1))
    plt.suptitle('Images')
    plt.savefig('8.png')

    # Plot initial models:
    mods = [tractor.getModelImage(i) for i in range(len(tims))]
    plt.clf()
    for i, band in enumerate(bands):
        for e in range(nepochs):
            plt.subplot(nepochs, len(bands), e * len(bands) + i + 1)
            plt.imshow(mods[nepochs * i + e], **ima)
            plt.xticks([])
            plt.yticks([])
Esempio n. 54
0
 def plot(self, data_num):
     print("Warning: Python prints plots in a stupid stupid way!")
     plt.imshow(np.log(self.intensity_mats[data_num][-1:0:-1] + 1), aspect='auto')
Esempio n. 55
0
for slice, freq in enumerate(freqs):
    nancut = (array[slice] < 10e10) & (array[slice] != NaN)
    cut = (array[slice] > 3.0 * array[slice][nancut].std())
    array[slice][cut] = 3.0 * array[slice][nancut].std()
    cut = (array[slice] < -3.0 * array[slice][nancut].std())
    array[slice][cut] = -3.0 * array[slice][nancut].std()

    #   Need to rotate array[slice] because axes were flipped
    new_array = scipy.transpose(array[slice])
    medianv = median(array[slice][nancut])

    #   Alternate plotting command to set temperature limits
    pylab.imshow(new_array,
                 cmap='hot',
                 vmin=-0.1,
                 vmax=0.1,
                 extent=(ras.max(), ras.min(), decs.min(), decs.max()),
                 origin='lower')
    #   pylab.imshow(new_array, interpolation='gaussian', cmap='hot', extent=(ras.max(),ras.min(),decs.min(),decs.max()), origin='lower')
    pylab.colorbar()  #For some reason this isn't working, fixed...
    pylab.savefig(filename2 + str(freq)[:3] + '.png')
    #   pylab.savefig('v_'+filename2+str(freq)[:3]+'.png')
    pylab.clf()

#Alternate code if want to plot in term of dec instead of freq.
#for slice, dec in enumerate(decs):
#   print slice
#   print dec
#   nancut = (array[:,:,slice] < 10e10) & ( array[:,:,slice] != NaN )
#   cut = ( array[:,:,slice] > 3.0*array[:,:,slice][nancut].std() )
#   array[:,:,slice][cut] = 3.0*array[:,:,slice][nancut].std()
Esempio n. 56
0
        for j in range(0, n - 1):
            Val_sum += z[i][j]  #Find Sum to calculate Mean
            if (z[i][j] > Max):
                Max = z[i][j]
                Max_x = i
                Max_y = j
    #Mean =  Val_sum / (float)( m * n )

    initial_guess = (Max, 0, Max_x, Max_y, 2)
    popt, pcov = opt.curve_fit(luv_mix_2D_10, (x, y),
                               z.ravel(),
                               p0=initial_guess)
    data_fitted = luv_mix_2D_10((x, y), *popt)

    print 'Optimum fitting parameters [amplitude, offset, x0, y0, k]'
    print popt

    f, axarr = plt.subplots(3, sharex=True)
    axarr[0].imshow(z, cmap='Greys')
    axarr[1].imshow(data_fitted.reshape(m, n), cmap='Greys')
    axarr[2].imshow(z - data_fitted.reshape(m, n), cmap='Greys')
    plt.figure()
    plt.imshow(z - data_fitted.reshape(m, n), cmap='Greys')
    polar_image = plot_polar_image(z - data_fitted.reshape(m, n),
                                   (popt[2], popt[3]))
    row_mean, row_median, row_index = get_statistics(polar_image)
    plt.figure()
    plt.plot(row_index, row_mean, label='Mean Row Intensity')
    plt.plot(row_index, row_median, label='Median Row Intensity')
    plt.show()
Sig_obs = gp.set_obs_data(X, Y)
gp.set_predict_points(X_pred)

# PLOT TRAINING DATA AND PRE-LEARNING PREDICTION
pl.figure(1)
pl.plot(X, Y, 'bo', label="Data")
pl.plot(gp.X_pred, gp.mu_pred, 'b', lw=0.5)

#y = gp.sample_prediction()
#pl.plot(gp.X_pred, y, "or", ms=1.)
#y = gp.sample_prediction()
#pl.plot(gp.X_pred, y, "og", ms=1.)

# PLOT PRE-LEARNING COV MATRIX
pl.figure(2)
pl.imshow(Sig_obs)
pl.colorbar()

# TRAIN
theta = train(gp.ll_obs_data, theta0, eta, T=100)

# PLOT POST-LEARNING PREDICTION
pl.figure(1)
k2 = build_k(*theta)
gp2 = GP(k2, sig2_obs=sig_obs**2)
Sig_obs2 = gp2.set_obs_data(X, Y)
gp2.set_predict_points(X_pred)
pl.plot(gp2.X_pred, gp2.mu_pred, 'g', lw=1.)

# PLOT POST-LEARNING COV MATRIX
pl.figure(3)
Esempio n. 58
0
    from .dr10 import DR10
    from astrometry.util.util import Tan

    tempdir = tempfile.gettempdir()

    sdss = DR10(basedir=tempdir)
    sdss.saveUnzippedFiles(tempdir)

    W, H = 100, 100
    pixscale = 1.
    cd = pixscale / 3600.
    targetwcs = Tan(120., 10., W / 2., H / 2., -cd, 0., 0., cd, float(W),
                    float(H))
    rgb = get_sdss_cutout(targetwcs, sdss)

    plt.clf()
    plt.imshow(rgb, interpolation='nearest', origin='lower')
    plt.savefig('cutout1.png')

    W, H = 3000, 3000
    pixscale = 0.5
    cd = pixscale / 3600.
    targetwcs = Tan(120., 10., W / 2., H / 2., -cd, 0., 0., cd, float(W),
                    float(H))
    rgb = get_sdss_cutout(targetwcs, sdss)

    plt.clf()
    plt.imshow(rgb, interpolation='nearest', origin='lower')
    plt.savefig('cutout2.png')
Esempio n. 59
0
    filtermap = {'i.MP9701': 'i2'}
    coim = get_cfht_coadd_image(RA, DEC, S, filtermap=filtermap)

    rr, dd = [], []
    xx, yy = [], []
    for i in outliers:
        print 'Outlier source', cat[i]
        rr.append(cat[i].getPosition().ra)
        dd.append(cat[i].getPosition().dec)
        x, y = coim.getWcs().positionToPixel(cat[i].getPosition())
        xx.append(x)
        yy.append(y)
    plt.clf()
    plt.imshow(coim.getImage(),
               interpolation='nearest',
               origin='lower',
               vmin=coim.zr[0],
               vmax=coim.zr[1])
    plt.gray()
    ax = plt.axis()
    #plt.plot(rr, dd, 'r+', ms=10)
    plt.plot(xx, yy, 'o', ms=25, mec='r', lw=2, alpha=0.5)
    plt.axis(ax)
    plt.savefig('outliers.png')


def s1():
    (allp, i2mags, cat) = unpickle_from_file('s1-258.pickle')
    plt.figure(figsize=(6, 6))

    T = fits_table('ri.fits')
Esempio n. 60
0
# Using SVM
C_range = 10.**np.arange(1, 7, 0.25)
gamma_range = 2.**np.arange(-5, -1, 0.25)
parameters = dict(gamma=gamma_range, C=C_range)
model = SVC(cache_size=1024, kernel='rbf')
grid = GridSearchCV(model, parameters, cv=5, verbose=1, n_jobs=1)
grid.fit(features, Y)

print("Best score: ", grid.best_score_)
print("Best classifier is: ", grid.best_estimator_)

# plot the scores of the grid
# grid_scores_ contains parameter settings and scores
score_dict = grid.grid_scores_

# We extract just the scores
scores = [x[1] for x in score_dict]
scores = np.array(scores).reshape(len(C_range), len(gamma_range))

# draw heatmap of accuracy as a function of gamma and C
pl.figure()
pl.subplots_adjust(left=0.05, right=0.95, bottom=0.15, top=0.95)
pl.imshow(scores, interpolation='nearest', cmap=pl.cm.spectral)
pl.xlabel('gamma')
pl.ylabel('C')
pl.colorbar()
pl.xticks(np.arange(len(gamma_range)), gamma_range, rotation=45)
pl.yticks(np.arange(len(C_range)), C_range)
pl.show()