Ejemplo n.º 1
0
def draw_mosaic_image(ax, aligner, img):
    if img is not None:
        if sys.version_info[0] != 2:
            warnings.warn('ModestImage module (required for image display)'
                          ' is only compatible with Python 2')
            img = None
        elif modest_image is None:
            warnings.warn('Please install ModestImage for image display')
            img = None
    if img is not None:
        modest_image.imshow(ax, img)
    else:
        h, w = aligner.mosaic_shape
        # Draw a single-pixel image in the lowest color in the colormap,
        # stretched across the same extent that the real image would be.
        # This makes the graph edge colors visible even if there's no image.
        ax.imshow([[0]], extent=(-0.5, w - 0.5, h - 0.5, -0.5))
Ejemplo n.º 2
0
def plot_waterfallc(wat, qindex=1, aspect = None,vmax=None, vmin=None, interpolation = 'none',
                    save=False, return_fig=False, cmap='viridis',*argv,**kwargs):   
    '''plot waterfall for a giving compressed file
    
       FD: class object, the compressed file handler
       labeled_array: np.array, a ROI mask
       qindex: the index number of q, will calculate where( labeled_array == qindex)
       aspect: the aspect ratio of the plot
       
       Return waterfall
       Plot the waterfall
    
    '''    
    #wat = cal_waterfallc( FD, labeled_array, qindex=qindex)
    if RUN_GUI:
        fig = Figure(figsize=(8,6))
        ax = fig.add_subplot(111)
    else:
        fig, ax = plt.subplots(figsize=(8,6))   
        
    if 'uid' in kwargs:
        uid = kwargs['uid']
    else:
        uid = 'uid'            
    #fig, ax = plt.subplots(figsize=(8,6))
    ax.set_ylabel('Pixel')
    ax.set_xlabel('Frame')
    ax.set_title('%s_Waterfall_Plot_@qind=%s'%(uid, qindex) )
    if 'beg' in kwargs:
        beg = kwargs['beg']
    else:
        beg=0    
    extent = [  beg, len(wat)+beg, 0, len( wat.T) ]
    if vmax is None:
        vmax=wat.max()
    if vmin is None:
        vmin = wat.min()
    if aspect is None:
        aspect = wat.shape[0]/wat.shape[1]
    im = imshow(ax, wat.T, cmap=cmap, vmax=vmax,extent= extent,interpolation = interpolation )    
    #im = ax.imshow(wat.T, cmap='viridis', vmax=vmax,extent= extent,interpolation = interpolation )
    fig.colorbar( im   )
    ax.set_aspect( aspect)
    
    if save:
        #dt =datetime.now()
        #CurTime = '%s%02d%02d-%02d%02d-' % (dt.year, dt.month, dt.day,dt.hour,dt.minute)             
        path = kwargs['path'] 

        #fp = path + "uid= %s--Waterfall-"%uid + CurTime + '.png'     
        fp = path + "%s_waterfall"%uid  + '.png'    
        plt.savefig( fp, dpi=fig.dpi)
        
    #plt.show()
    if return_fig:
        return fig,ax, im 
Ejemplo n.º 3
0
def test_imshow_creates_modest_image():
    """returns a modestImage"""
    data = default_data()
    fig = plt.figure()
    ax = fig.add_subplot(111)

    artist = imshow(ax, data)

    assert isinstance(artist, ModestImage)
    assert artist in artist.axes.images
Ejemplo n.º 4
0
def main(argv=sys.argv):

    try:
        import modest_image
    except ImportError:
        print(
            "Please install ModestImage (Python 2.7 only) to use this script.")
        exit()

    filepath = argv[1]

    channel = 0
    if len(argv) >= 3:
        channel = int(argv[2])

    reader = reg.BioformatsReader(filepath)
    metadata = reader.metadata

    positions = metadata.positions - metadata.origin
    mshape = (
        (metadata.positions + metadata.size - metadata.origin).max(axis=0) +
        1).astype(int)
    mosaic = np.zeros(mshape, dtype=np.uint16)

    total = reader.metadata.num_images
    for i in range(total):
        sys.stdout.write("\rLoading %d/%d" % (i + 1, total))
        sys.stdout.flush()
        reg.paste(mosaic, reader.read(c=channel, series=i), positions[i],
                  np.maximum)
    print()

    ax = plt.gca()

    modest_image.imshow(ax, mosaic)

    h, w = metadata.size
    for xy in np.fliplr(positions):
        ax.add_patch(mpatches.Rectangle(xy, w, h, color='black', fill=False))

    plt.show()
Ejemplo n.º 5
0
def show_img(img, save=False, vmin=None, vmax=None,cmap='winter',fontsize=24,
             axis_on=True,title_on=True,xlabel=None,ylabel=None,aspect=1.0,
        title='img_', show=True, logs=False,outDir=None, sizex=9,sizey=9 ):
    """show a two-D image"""
    #show img
    ax = plt.gca()
    F = plt.gcf()
    #print F.get_size_inches()
    F.set_size_inches(sizex,sizey)
    #plt.figure(figsize=(12, 12))
    if vmin==None:vmin=img.min()
    if vmax==None:vmax=img.max()
    if not logs:
        artist = imshow(ax, img,cmap=plt.get_cmap(cmap), vmin=vmin,vmax=vmax )
        
    if logs:
        img= log(img)        
        if vmin==None:vmin=img[nonzero(img)].min() #img.min()
        artist = imshow(ax, img,cmap=plt.get_cmap(cmap),vmin=vmin, vmax=vmax,)
    
    dx,dy=img.shape
    #print dx,dy
    ax.set_ylim(0,dx-1)
    ax.set_xlim(0,dy-1)
    #ax.set_aspect('auto')
    if aspect!=1.0:
        im = ax.get_images()
        extent =  im[0].get_extent()
        ax.set_aspect(abs((extent[1]-extent[0])/(extent[3]-extent[2]))/aspect)
    if title_on:plt.title(  title,fontsize=fontsize )
    #else:plt.title( None)
    if not axis_on:plt.axis('off')
    if xlabel!=None:plt.xlabel(xlabel,fontsize=18)
    if ylabel!=None:plt.ylabel(ylabel,fontsize=18)
    plt.setp(ax.get_xticklabels(),  fontsize=fontsize)
    plt.setp(ax.get_yticklabels(),  fontsize=fontsize)
    if save:
        if outDir!=None:fp=outDir + title + '_.png'
        else:fp= title + '_.png'
        plt.savefig( fp )        
    if show:plt.show()
Ejemplo n.º 6
0
def test_imshow_mimics_mpl():
    """properties of two axes and artists objects should be same"""

    data = default_data()
    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122)

    artist1 = ax1.imshow(data)
    artist2 = imshow(ax2, data)

    check_artist_props(artist1, artist2)
    check_axes_props(ax1, ax2)
Ejemplo n.º 7
0
    def _generate_plot(ax, power_data, title, min_db, max_db):
        """
        Generate a ZPLS plot for an individual channel
        :param ax:  matplotlib axis to receive the plot image
        :param power_data:  Transducer data array
        :param title:  plot title
        :param min_db: minimum power level
        :param max_db: maximum power level
        """
        # only generate plots for the transducers that have data
        if power_data.size <= 0:
            return

        ax.set_title(title, fontsize=ZPLSPlot.font_size_large)
        return imshow(ax, power_data, interpolation='none', aspect='auto', cmap='jet', vmin=min_db, vmax=max_db)
def show_g12q_taus( g12q, taus,  slice_width=10, timeperframe=1,vmin= 1, vmax= 1.25 ):    
    
    ''' 
    Dec 16, 2015, Y.G.@CHX
    Plot tau-lines as a function of age with two correlation function 
 
    
    Parameters:
        g12q: a 2-D array, one-q two correlation function, shape as ( imgs_length, imgs_length )
        tau, a dict, tau lines  
                 the keys of dict is tau(slice center) in unit of pixel
                 dict[key]:    
                           a 1-D array, shape as ( tau_line-length ), 
                 obtained by: for example,
                         taus = get_tau_from_g12q( g12b_norm[:,:,0], slice_num = 5, slice_width=1, 
                  slice_start=3, slice_end= 5000-1  ))
                         
                           
    Options:
        slice_width: int,  each slice width in unit of pixel, for line width of a plot
        timeperframe: float, time per frame for axis unit
        vmin, float, matplot vmin
        vmax, float, matplot vmax
   
    Return:
         two plots, one for tau lines~ages, g12q, 
 
    One example:     
        show_g12q_taus( g12b_norm[:,:,0], taus,  slice_width=50, 
               timeperframe=1,vmin=1.01,vmax=1.55 )
    '''
     
     
     
    age_center = list( taus.keys() )
    print ('the cut tau centers are: ' +str(age_center)     )
    M,N = g12q.shape

    #fig, ax = plt.subplots( figsize = (8,8) )
    
    figw =10
    figh = 10
    fig = plt.figure(figsize=(figw,figh)) 
    
    gs = gridspec.GridSpec(1, 2, width_ratios=[10, 8],height_ratios=[8,8]   ) 
    ax = plt.subplot(gs[0])     
    ax1 = plt.subplot(gs[1])     
    im = imshow(ax,  g12q, origin='lower' , cmap='viridis', 
             norm= LogNorm( vmin= vmin, vmax= vmax ) , extent=[0, N, 0, N ] )

    linS = []
    linE=[]
    linS.append( zip(  np.int_(age_center) -1, [0]*len(age_center)   ))
    linE.append( zip(  [N -1]*len(age_center), N  - np.int_(age_center)   ))
    for i, [ps,pe] in enumerate(zip(linS[0],linE[0])):
        lined= slice_width  #/2. *draw_scale_tau  #in data width
        linewidth=    (lined * (figh*72./N)) * 0.8
        #print (ps,pe)
        ax.plot( [ps[0],pe[0]],[ps[1],pe[1]], linewidth=linewidth ) #, color=   )  
    
    ax.set_title(  '%s_frames'%(N)    )
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)    
    
    ax1.set_title("Tau_Cuts_in_G12")
    for i in sorted(taus.keys()):
        gx= np.arange(len(taus[i])) * timeperframe
        marker = next(markers)        
        ax1.plot( gx,taus[i], '-%s'%marker, label=r"$tau= %.1f s$"%(i*timeperframe))
        ax1.set_ylim( vmin,vmax )
        ax1.set_xlabel(r'$t (s)$',fontsize=5)
        ax1.set_ylabel("g2")
        ax1.set_xscale('log')
    ax1.legend(fontsize='small', loc='best' ) 
def show_g12q_aged_g2( g12q, g2_aged, taus_aged = None, slice_width=10, timeperframe=1,vmin= 1, vmax= 1.25, 
                      save=True, uid='uid', path='', *argv,**kwargs): 
    
    ''' 
    Octo 20, 2017, add taus_aged option 
    
    Dec 16, 2015, Y.G.@CHX
    Plot one-time correlation function of different age with two correlation function 
    Parameters:
        g12q: a 2-D array, one-q two correlation function, shape as ( imgs_length, imgs_length ) 
        tau_aged: a dict, taus for different age
        g2_aged: a dict, one time correlation function at different age
                 obtained by: for example,
                 g2_aged = get_aged_g2_from_g12q( g12q, slice_num =3, slice_width= 500, 
                                                  slice_start=4000, slice_end= 20000-4000  )
                 the keys of dict is ages in unit of pixel
                 dict[key]:    
                           a 1-D array, shape as ( imgs_length ), 
                           a one-q one-time correlation function                          
                           
    Options:
        slice_width: int,  each slice width in unit of pixel, for line width of a plot
        timeperframe: float, time per frame for axis unit
        vmin, float, matplot vmin
        vmax, float, matplot vmax
   
    Return:
         two plots, one for the two-time correlation, g12q, 
 
    One example:     
        show_g12q_aged_g2( g12q, g2_aged,timeperframe=1,vmin= 1, vmax= 1.22 )
    '''
    
    age_center = np.array( list( sorted( g2_aged.keys() ) ) ) 
    print ('the cut age centers are: ' + str(age_center)     )    
    age_center = np.int_(np.array( list( sorted( g2_aged.keys() ) ) )/timeperframe) *2  #in pixel
    M,N = g12q.shape

    #fig, ax = plt.subplots( figsize = (8,8) )
    
    figw =10
    figh = 8
    fig = plt.figure(figsize=(figw,figh)) 
    
    #gs = gridspec.GridSpec(1, 2, width_ratios=[10, 8],height_ratios=[8,8]   ) 
    gs = gridspec.GridSpec(1, 2   ) 
    ax = plt.subplot(gs[0])
    im = imshow(ax, g12q, origin='lower' , cmap='viridis', 
             norm= LogNorm( vmin, vmax ), extent=[0, N,0,N])
    
    #plt.gca().set_xticks(ticks)
    ticks  = np.round( plt.gca().get_xticks() * timeperframe, 2) 
    #print( ticks )
    ax.set_xticklabels(ticks )
    ax.set_yticklabels(ticks )
    #plt.xticks(ticks, fontsize=9)
    
    #), extent=[0, g12q.shape[0]*timeperframe, 0, g12q.shape[0]*timeperframe ] ) 
    
    ax1 = plt.subplot(gs[1])     
    linS1 = [ [0]*len(age_center ), np.int_(age_center - slice_width//2 )  ]
    linS2 = [ [0]*len(age_center ), np.int_(age_center + slice_width//2 )  ] 
    linE1 = [  np.int_(age_center - slice_width//2  ), [0]*len(age_center) ]
    linE2 = [  np.int_(age_center + slice_width//2  ), [0]*len(age_center) ]     
    linC = [ [0]*len(age_center ), np.int_(age_center ) ] 
    
    for i in range( len(age_center ) ):
        ps = linS1[1][i]
        pe = linE1[0][i]
        if ps>=N:s0=ps - N;s1=N
        else:s0=0;s1=ps   
        e0 = s1;e1=s0    
        #if pe>=N:e0=N;e1=pe - N
        #else:e0=pe;e1=0 
        
        ps = linS2[1][i]
        pe = linE2[0][i]
        if ps>=N:S0=ps - N;S1=N
        else:S0=0;S1=ps        
        #if pe>=N:e0=N;E1=pe - N
        #else:E0=pe;E1=0 
        E0=S1;E1=S0
        
        ps = linC[1][i]
        if ps>=N:C0=ps - N;C1=N
        else:C0=0;C1=ps        
        #if pe>=N:e0=N;E1=pe - N
        #else:E0=pe;E1=0 
        D0=C1;D1=C0
        
        lined= slice_width/2.  #in data width
        linewidthc=    (lined * (figh*72./N)) * 0.5  
        #print( s0,e0, s1,e1, S0,E0, S1, E1)
        
        #lined= slice_width/2.  #in data width
        #linewidth=    (lined * (figh*72./N)) * 0.8        
        linewidth = 1        
        ax.plot( [s0,e0],[s1,e1], linewidth=linewidth , ls = '--', alpha=1 , color= colors_array[i]   )  
        ax.plot( [S0,E0],[S1,E1], linewidth=linewidth , ls = '--', alpha=1 , color= colors_array[i]   ) 
        #print( i, [s0,e0],[s1,e1], [S0,E0],[S1,E1], colors_array[i]   )
        ax.plot( [C0,D0],[C1,D1], linewidth=linewidthc , ls = '-', alpha=.0 , color= colors_array[i]   )  
    
    #ax.set_title(  '%s_frames'%(N)    )
    ax.set_title(  "%s_two_time"%uid )
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)     
    ax1.set_title("%s_aged_g2"%uid)
    ki=0
    for i in sorted(g2_aged.keys()):
        #ax = fig.add_subplot(sx,sy,sn+1 )
        if taus_aged is None:
            gx= np.arange(len(g2_aged[i])) * timeperframe
        else:
            gx = taus_aged[i]
        #marker = next(markers)     
        #print( g2_aged[i], marker )
        #print(i)
        ax1.plot( gx,g2_aged[i], marker = '%s'%markers_array[ki], ls='-', color= colors_array[ki],  label=r"$t_a= %.1f s$"%i)
        #print( i, ki, colors_array[ki]  )
        ki += 1
        ax1.set_ylim( vmin, vmax )
        ax1.set_xlabel(r"$\tau $ $(s)$", fontsize=18) 
        ax1.set_ylabel("g2")
        ax1.set_xscale('log')
    ax1.legend(fontsize='small', loc='best' )             
    if save:
        #fp = path + "uid= %s--Waterfall-"%uid + CurTime + '.png'     
        fp = path + "%s_aged_g2"%uid  + '.png' 
        #print( fp )
        fig.savefig( fp, dpi=fig.dpi)  
def show_one_C12( C12,  fig_ax=None,  return_fig=False,interpolation = 'none',cmap='viridis',
                 *argv,**kwargs):  
 
    '''
    plot one-q of two-time correlation function
    C12: two-time correlation function, with shape as [ time, time, qs]
    q_ind: if integer, for a SAXS q, the nth of q to be plotted
            if a list: for a GiSAXS [qz_ind, qr_ind]  
    kwargs: support        
        timeperframe: the time interval
        N1: the start frame(time)
        N2: the end frame(time)
        vmin/vmax: for plot
        title: if True, show the tile
    
    e.g.,
        show_C12(g12b, q_ind=1, N1=0, N2=500, vmin=1.05, vmax=1.07,  )
    
    '''
  
    #strs =  [ 'timeperframe', 'N1', 'N2', 'vmin', 'vmax', 'title'] 
    
    if 'uid' in kwargs:
        uid=kwargs['uid']
    else:
        uid='uid'
        
        
    shape = C12.shape 
    
    if 'timeperframe' in kwargs.keys():
        timeperframe =  kwargs['timeperframe']
    else:
        timeperframe=1
        
    if 'vmin' in kwargs.keys():
        vmin =  kwargs['vmin']
    else:
        vmin=1
    if 'vmax' in kwargs.keys():
        vmax =  kwargs['vmax']
    else:
        vmax=1.05        
        
    if 'N1' in kwargs.keys():
        N1 =  kwargs['N1']
    else:
        N1=0
        
    if 'N2' in kwargs.keys():
        N2 =  kwargs['N2']
    else:
        N2= shape[0]
    if 'title' in kwargs.keys():
        title =  kwargs['title']
    else:
        title=True        

    data = C12[N1:N2,N1:N2]
    if fig_ax is None:
        if RUN_GUI:
            fig = Figure()
            ax = fig.add_subplot(111)
        else:
            fig, ax = plt.subplots()
    else:
        fig,ax=fig_ax
    im = imshow(ax,  data, origin='lower' , cmap=cmap, 
                 norm= LogNorm( vmin, vmax ),  
            extent=[0, data.shape[0]*timeperframe, 0, data.shape[0]*timeperframe ],
                interpolation = interpolation)
    if title:

        tit = '%s-[%s-%s] frames'%(uid,N1,N2)            

        ax.set_title( tit  )
    else:
        tit=''        
        #ax.set_title('%s-%s frames--Qth= %s'%(N1,N2,g12_num))
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)
    
    save=False    
    if 'save' in kwargs:
        save=kwargs['save']
    if save:       
        path=kwargs['path']
        #fp = path + 'Two-time--uid=%s'%(uid) + tit + CurTime + '.png'
        fp = path + '%s_Two_time'%(uid) + '.png'
        plt.savefig( fp, dpi=fig.dpi)        
     
    if return_fig:
        return fig, ax, im
Ejemplo n.º 11
0
def generate_plots(trans_array, trans_array_time, td_f, td_dr, title, filename):
    """
    Generate plots for a transducer
    @param trans_array Transducer data array
    @param trans_array_time Transducer internal time array
    @param td_f Transducer frequency
    @param td_dr Transducer's sample thickness (in range)
    @param title Transducer title
    @param filename png file name to save the figure to
    """

    # only generate plots for the transducers that have data
    if np.size(trans_array_time) <= 0:
        return

    # determine size of the data array
    max_depth, max_time = np.shape(trans_array)
    min_depth = 0
    min_time = 0

    # subset/decimate the x & y ticks so that we don't plot everyone
    num_xticks = 7
    num_yticks = 10

    min_db = -180
    max_db = -59

    cbar_ticks = np.arange(min_db, max_db, 20)

    # convert time, which represents the number of 100-nanosecond intervals that
    # have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC)
    # to unix time, i.e. seconds since 1970-01-01 00:00:00.
    # 11644473600 == difference between 1601 and 1970
    # 1e7 == divide by 10 million to convert to seconds
    trans_array_time = np.array(trans_array_time) / 1e7 - 11644473600
    trans_array_time = (trans_array_time / (60*60*24)) + REF_TIME

    # subset the xticks so that we don't plot every one
    xticks = np.linspace(0, max_time, num_xticks)
    # format trans_array_time array so that it can be used to label the x-axis
    xticklabels = [i.strftime('%Y-%m-%d %H:%M:%S')
                   for i in num2date(trans_array_time[::round(xticks[1])])]

    # subset the yticks so that we don't plot everyone
    yticks = np.linspace(0, max_depth, num_yticks)
    # create range vector (depth in meters)
    yticklabels = np.round(np.arange(0, max_depth, round(yticks[1])) * td_dr)

    fig, ax = plt.subplots()
    ax.grid(False)
    figure_title = 'Converted Power: ' + title + 'Frequency: ' + str(td_f)
    ax.set_title(figure_title, fontsize=12)
    ax.set_xlabel('time (UTC)', fontsize=10)
    ax.set_ylabel('depth (m)', fontsize=10)

    # rotates and right aligns the x labels, and moves the bottom of the
    # axes up to make room for them
    ax.set_xticks(xticks)
    ax.set_xticklabels(xticklabels, rotation=25, horizontalalignment='right', fontsize=10)

    ax.set_yticks(yticks)
    ax.set_yticklabels(yticklabels, fontsize=10)

    ax.tick_params(axis="both", labelcolor="k", pad=4)

    # set the x and y limits
    ax.set_ylim(max_depth, min_depth)
    ax.set_xlim(min_time, max_time)

    # plot the colorbar
    cax = imshow(ax, trans_array, interpolation='none', aspect='auto', cmap='jet', vmin=min_db, vmax=max_db)
    cb = fig.colorbar(cax, orientation='horizontal', ticks=cbar_ticks, shrink=.6)
    cb.ax.set_xticklabels(cbar_ticks, fontsize=8)  # horizontally oriented colorbar
    cb.set_label('dB', fontsize=10)
    cb.ax.set_xlim(-180, -60)

    fig.tight_layout(pad=1.2)
    # adjust the subplot so that the x-tick labels will fit on the canvas
    fig.subplots_adjust(bottom=0.1)

    plt.figtext(0.01, 0.01, '*Note: Strictly sequential time tags are not guaranteed.',
                axes=ax, fontsize=7)

    # reposition the cbar
    cb.ax.set_position([.4, .05, .4, .1])

    # save the figure
    fig.savefig(filename, dpi=300)

    # close the figure
    plt.close()
def show_g12q_taus( g12q, taus,  slice_width=10, timeperframe=1,vmin= 1, vmax= 1.25 ):    
    
    ''' 
    Dec 16, 2015, Y.G.@CHX
    Plot tau-lines as a function of age with two correlation function 
 
    
    Parameters:
        g12q: a 2-D array, one-q two correlation function, shape as ( imgs_length, imgs_length )
        tau, a dict, tau lines  
                 the keys of dict is tau(slice center) in unit of pixel
                 dict[key]:    
                           a 1-D array, shape as ( tau_line-length ), 
                 obtained by: for example,
                         taus = get_tau_from_g12q( g12b_norm[:,:,0], slice_num = 5, slice_width=1, 
                  slice_start=3, slice_end= 5000-1  ))
                         
                           
    Options:
        slice_width: int,  each slice width in unit of pixel, for line width of a plot
        timeperframe: float, time per frame for axis unit
        vmin, float, matplot vmin
        vmax, float, matplot vmax
   
    Return:
         two plots, one for tau lines~ages, g12q, 
 
    One example:     
        show_g12q_taus( g12b_norm[:,:,0], taus,  slice_width=50, 
               timeperframe=1,vmin=1.01,vmax=1.55 )
    '''
     
     
     
    age_center = list( taus.keys() )
    print ('the cut tau centers are: ' +str(age_center)     )
    M,N = g12q.shape

    #fig, ax = plt.subplots( figsize = (8,8) )
    
    figw =10
    figh = 10
    fig = plt.figure(figsize=(figw,figh)) 
    
    gs = gridspec.GridSpec(1, 2, width_ratios=[10, 8],height_ratios=[8,8]   ) 
    ax = plt.subplot(gs[0])     
    ax1 = plt.subplot(gs[1])     
    im = imshow(ax,  g12q, origin='lower' , cmap='viridis', 
             norm= LogNorm( vmin= vmin, vmax= vmax ) , extent=[0, N, 0, N ] )

    linS = []
    linE=[]
    linS.append( zip(  np.int_(age_center) -1, [0]*len(age_center)   ))
    linE.append( zip(  [N -1]*len(age_center), N  - np.int_(age_center)   ))
    for i, [ps,pe] in enumerate(zip(linS[0],linE[0])):
        lined= slice_width  #/2. *draw_scale_tau  #in data width
        linewidth=    (lined * (figh*72./N)) * 0.8
        #print (ps,pe)
        ax.plot( [ps[0],pe[0]],[ps[1],pe[1]], linewidth=linewidth ) #, color=   )  
    
    ax.set_title(  '%s_frames'%(N)    )
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)    
    
    ax1.set_title("Tau_Cuts_in_G12")
    for i in sorted(taus.keys()):
        gx= np.arange(len(taus[i])) * timeperframe
        marker = next(markers)        
        ax1.plot( gx,taus[i], '-%s'%marker, label=r"$tau= %.1f s$"%(i*timeperframe))
        ax1.set_ylim( vmin,vmax )
        ax1.set_xlabel(r'$t (s)$',fontsize=5)
        ax1.set_ylabel("g2")
        ax1.set_xscale('log')
    ax1.legend(fontsize='small', loc='best' ) 
def show_g12q_aged_g2( g12q, g2_aged, taus_aged = None, slice_width=10, timeperframe=1,vmin= 1, vmax= 1.25, 
                      save=True, uid='uid', path='', *argv,**kwargs): 
    
    ''' 
    Octo 20, 2017, add taus_aged option 
    
    Dec 16, 2015, Y.G.@CHX
    Plot one-time correlation function of different age with two correlation function 
    Parameters:
        g12q: a 2-D array, one-q two correlation function, shape as ( imgs_length, imgs_length ) 
        tau_aged: a dict, taus for different age
        g2_aged: a dict, one time correlation function at different age
                 obtained by: for example,
                 g2_aged = get_aged_g2_from_g12q( g12q, slice_num =3, slice_width= 500, 
                                                  slice_start=4000, slice_end= 20000-4000  )
                 the keys of dict is ages in unit of pixel
                 dict[key]:    
                           a 1-D array, shape as ( imgs_length ), 
                           a one-q one-time correlation function                          
                           
    Options:
        slice_width: int,  each slice width in unit of pixel, for line width of a plot
        timeperframe: float, time per frame for axis unit
        vmin, float, matplot vmin
        vmax, float, matplot vmax
   
    Return:
         two plots, one for the two-time correlation, g12q, 
 
    One example:     
        show_g12q_aged_g2( g12q, g2_aged,timeperframe=1,vmin= 1, vmax= 1.22 )
    '''
    
    age_center = np.array( list( sorted( g2_aged.keys() ) ) ) 
    print ('the cut age centers are: ' + str(age_center)     )    
    age_center = np.int_(np.array( list( sorted( g2_aged.keys() ) ) )/timeperframe) *2  #in pixel
    M,N = g12q.shape

    #fig, ax = plt.subplots( figsize = (8,8) )
    
    figw =10
    figh = 8
    fig = plt.figure(figsize=(figw,figh)) 
    
    #gs = gridspec.GridSpec(1, 2, width_ratios=[10, 8],height_ratios=[8,8]   ) 
    gs = gridspec.GridSpec(1, 2   ) 
    ax = plt.subplot(gs[0])
    im = imshow(ax, g12q, origin='lower' , cmap='viridis', 
             norm= LogNorm( vmin, vmax ), extent=[0, N,0,N])
    
    #plt.gca().set_xticks(ticks)
    ticks  = np.round( plt.gca().get_xticks() * timeperframe, 2) 
    #print( ticks )
    ax.set_xticklabels(ticks )
    ax.set_yticklabels(ticks )
    #plt.xticks(ticks, fontsize=9)
    
    #), extent=[0, g12q.shape[0]*timeperframe, 0, g12q.shape[0]*timeperframe ] ) 
    
    ax1 = plt.subplot(gs[1])     
    linS1 = [ [0]*len(age_center ), np.int_(age_center - slice_width//2 )  ]
    linS2 = [ [0]*len(age_center ), np.int_(age_center + slice_width//2 )  ] 
    linE1 = [  np.int_(age_center - slice_width//2  ), [0]*len(age_center) ]
    linE2 = [  np.int_(age_center + slice_width//2  ), [0]*len(age_center) ]     
    linC = [ [0]*len(age_center ), np.int_(age_center ) ] 
    
    for i in range( len(age_center ) ):
        ps = linS1[1][i]
        pe = linE1[0][i]
        if ps>=N:s0=ps - N;s1=N
        else:s0=0;s1=ps   
        e0 = s1;e1=s0    
        #if pe>=N:e0=N;e1=pe - N
        #else:e0=pe;e1=0 
        
        ps = linS2[1][i]
        pe = linE2[0][i]
        if ps>=N:S0=ps - N;S1=N
        else:S0=0;S1=ps        
        #if pe>=N:e0=N;E1=pe - N
        #else:E0=pe;E1=0 
        E0=S1;E1=S0
        
        ps = linC[1][i]
        if ps>=N:C0=ps - N;C1=N
        else:C0=0;C1=ps        
        #if pe>=N:e0=N;E1=pe - N
        #else:E0=pe;E1=0 
        D0=C1;D1=C0
        
        lined= slice_width/2.  #in data width
        linewidthc=    (lined * (figh*72./N)) * 0.5  
        #print( s0,e0, s1,e1, S0,E0, S1, E1)
        
        #lined= slice_width/2.  #in data width
        #linewidth=    (lined * (figh*72./N)) * 0.8        
        linewidth = 1        
        ax.plot( [s0,e0],[s1,e1], linewidth=linewidth , ls = '--', alpha=1 , color= colors_array[i]   )  
        ax.plot( [S0,E0],[S1,E1], linewidth=linewidth , ls = '--', alpha=1 , color= colors_array[i]   ) 
        #print( i, [s0,e0],[s1,e1], [S0,E0],[S1,E1], colors_array[i]   )
        ax.plot( [C0,D0],[C1,D1], linewidth=linewidthc , ls = '-', alpha=.0 , color= colors_array[i]   )  
    
    #ax.set_title(  '%s_frames'%(N)    )
    ax.set_title(  "%s_two_time"%uid )
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)     
    ax1.set_title("%s_aged_g2"%uid)
    ki=0
    for i in sorted(g2_aged.keys()):
        #ax = fig.add_subplot(sx,sy,sn+1 )
        if taus_aged is None:
            gx= np.arange(len(g2_aged[i])) * timeperframe
        else:
            gx = taus_aged[i]
        #marker = next(markers)     
        #print( g2_aged[i], marker )
        #print(i)
        ax1.plot( gx,g2_aged[i], marker = '%s'%markers_array[ki], ls='-', color= colors_array[ki],  label=r"$t_a= %.1f s$"%i)
        #print( i, ki, colors_array[ki]  )
        ki += 1
        ax1.set_ylim( vmin, vmax )
        ax1.set_xlabel(r"$\tau $ $(s)$", fontsize=18) 
        ax1.set_ylabel("g2")
        ax1.set_xscale('log')
    ax1.legend(fontsize='small', loc='best' )             
    if save:
        #fp = path + "uid= %s--Waterfall-"%uid + CurTime + '.png'     
        fp = path + "%s_aged_g2"%uid  + '.png' 
        #print( fp )
        fig.savefig( fp, dpi=fig.dpi)  
def show_C12(C12,  fig_ax=None, q_ind=1, return_fig=False, interpolation = 'none', cmap='viridis',
             logs=True, qlabel=None, *argv,**kwargs):  
 
    '''
    plot one-q of two-time correlation function
    C12: two-time correlation function, with shape as [ time, time, qs]
    q_ind: if integer, for a SAXS q, the nth of q to be plotted, starting from 1,
            if a list: for a GiSAXS [qz_ind, qr_ind]  
    kwargs: support        
        timeperframe: the time interval
        N1: the start frame(time)
        N2: the end frame(time)
        vmin/vmax: for plot
        title: if True, show the tile
    
    e.g.,
        show_C12(g12b, q_ind=1, N1=0, N2=500, vmin=1.05, vmax=1.07,  )
    
    '''
  
    #strs =  [ 'timeperframe', 'N1', 'N2', 'vmin', 'vmax', 'title'] 
    
    if 'uid' in kwargs:
        uid=kwargs['uid']
    else:
        uid='uid'
    shape = C12.shape   
    if (q_ind<0) or (q_ind>shape[2]-1):
        raise Exceptions("Error: qind starts from 0 (corresponding to python array index 0, but in the plot it will show as 1) to the max Q-length of two time funcs-1 %s."%shape[2]-1) 
 
                 
    if isinstance(q_ind, int):
        C12_num = q_ind #-1
    else:
        qz_ind, qr_ind = q_ind #-1
        C12_num =  qz_ind * num_qr + qr_ind 
    
    if 'timeperframe' in kwargs.keys():
        timeperframe =  kwargs['timeperframe']
    else:
        timeperframe=1
        
    if 'vmin' in kwargs.keys():
        vmin =  kwargs['vmin']
    else:
        vmin=1
    if 'vmax' in kwargs.keys():
        vmax =  kwargs['vmax']
    else:
        vmax=1.05        
        
    if 'N1' in kwargs.keys():
        N1 =  kwargs['N1']
        if N1<0:
            N1 = 0
    else:
        N1=0
        
    if 'N2' in kwargs.keys():
        N2 =  kwargs['N2']
        if N2>shape[0]:
            N2 = shape[0]
    else:
        N2= shape[0]
    if 'title' in kwargs.keys():
        title =  kwargs['title']
    else:
        title=True        

    data = C12[N1:N2,N1:N2,C12_num]
    if fig_ax is None:
        if RUN_GUI:
            fig = Figure()
            ax = fig.add_subplot(111)
        else:
            fig, ax = plt.subplots()
    else:
        fig,ax=fig_ax

    #extent=[0, data.shape[0]*timeperframe, 0, data.shape[0]*timeperframe ]
    extent= np.array( [N1, N2, N1, N2]) *timeperframe 
    
    if logs: 
        im = imshow(ax,  data, origin='lower' , cmap=cmap, 
                 norm= LogNorm( vmin, vmax ), interpolation = interpolation, 
            extent=extent )
    else:
        im = imshow(ax, data, origin='lower' , cmap=cmap, 
                 vmin=vmin, vmax=vmax, interpolation = interpolation, 
            extent=extent )    
    if qlabel is not None:
        if isinstance(q_ind, int):
            qstr = 'Qth= %s-qval=%s'%(C12_num+1, qlabel[C12_num])  
    else:
        qstr = 'Qth= %s'%(C12_num+1)  
    if title:
        if isinstance(q_ind, int):
            tit = '%s-[%s-%s] frames--'%(uid,N1,N2)  + qstr          
        else:
            tit =  '%s-[%s-%s] frames--Qzth= %s--Qrth= %s'%(uid,N1,N2, qz_ind, qr_ind )
        ax.set_title( tit  )
    else:
        tit=''        
        #ax.set_title('%s-%s frames--Qth= %s'%(N1,N2,g12_num))
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)
    
    save=False    
    if 'save' in kwargs:
        save=kwargs['save']
    if save:       
        path=kwargs['path']
        #fp = path + 'Two-time--uid=%s'%(uid) + tit + CurTime + '.png'
        fp = path + '%s_Two_time'%(uid) + '.png'
        plt.savefig( fp, dpi=fig.dpi)        
     
    if return_fig:
        return fig, ax, im
def show_one_C12( C12,  fig_ax=None,  return_fig=False,interpolation = 'none',cmap='viridis',
                 *argv,**kwargs):  
 
    '''
    plot one-q of two-time correlation function
    C12: two-time correlation function, with shape as [ time, time, qs]
    q_ind: if integer, for a SAXS q, the nth of q to be plotted
            if a list: for a GiSAXS [qz_ind, qr_ind]  
    kwargs: support        
        timeperframe: the time interval
        N1: the start frame(time)
        N2: the end frame(time)
        vmin/vmax: for plot
        title: if True, show the tile
    
    e.g.,
        show_C12(g12b, q_ind=1, N1=0, N2=500, vmin=1.05, vmax=1.07,  )
    
    '''
  
    #strs =  [ 'timeperframe', 'N1', 'N2', 'vmin', 'vmax', 'title'] 
    
    if 'uid' in kwargs:
        uid=kwargs['uid']
    else:
        uid='uid'
        
        
    shape = C12.shape 
    
    if 'timeperframe' in kwargs.keys():
        timeperframe =  kwargs['timeperframe']
    else:
        timeperframe=1
        
    if 'vmin' in kwargs.keys():
        vmin =  kwargs['vmin']
    else:
        vmin=1
    if 'vmax' in kwargs.keys():
        vmax =  kwargs['vmax']
    else:
        vmax=1.05        
        
    if 'N1' in kwargs.keys():
        N1 =  kwargs['N1']
    else:
        N1=0
        
    if 'N2' in kwargs.keys():
        N2 =  kwargs['N2']
    else:
        N2= shape[0]
    if 'title' in kwargs.keys():
        title =  kwargs['title']
    else:
        title=True        

    data = C12[N1:N2,N1:N2]
    if fig_ax is None:
        if RUN_GUI:
            fig = Figure()
            ax = fig.add_subplot(111)
        else:
            fig, ax = plt.subplots()
    else:
        fig,ax=fig_ax
    im = imshow(ax,  data, origin='lower' , cmap=cmap, 
                 norm= LogNorm( vmin, vmax ),  
            extent=[0, data.shape[0]*timeperframe, 0, data.shape[0]*timeperframe ],
                interpolation = interpolation)
    if title:

        tit = '%s-[%s-%s] frames'%(uid,N1,N2)            

        ax.set_title( tit  )
    else:
        tit=''        
        #ax.set_title('%s-%s frames--Qth= %s'%(N1,N2,g12_num))
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)
    
    save=False    
    if 'save' in kwargs:
        save=kwargs['save']
    if save:       
        path=kwargs['path']
        #fp = path + 'Two-time--uid=%s'%(uid) + tit + CurTime + '.png'
        fp = path + '%s_Two_time'%(uid) + '.png'
        plt.savefig( fp, dpi=fig.dpi)        
     
    if return_fig:
        return fig, ax, im
Ejemplo n.º 16
0
def generate_plots(trans_array, trans_array_time, td_f, td_dR, title,
                   filename):
    """
    Generate plots for a transducer
    @param trans_array Transducer data array
    @param trans_array_time Transducer internal time array
    @param td_f Transducer frequency
    @param td_dR Transducer's sample thickness (in range)
    @param title Transducer title
    @param filename png file name to save the figure to
    """

    # only generate plots for the transducers that have data
    if np.size(trans_array_time) <= 0:
        return

    # determine size of the data array
    max_depth, max_time = np.shape(trans_array)
    min_depth = 0
    min_time = 0

    # subset/decimate the x & y ticks so that we don't plot everyone
    num_xticks = 7
    num_yticks = 10

    min_db = -180
    max_db = -59

    cbar_ticks = np.arange(min_db, max_db, 20)

    # convert time, which represents the number of 100-nanosecond intervals that
    # have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC)
    # to unix time, i.e. seconds since 1970-01-01 00:00:00.
    # 11644473600 == difference between 1601 and 1970
    # 1e7 == divide by 10 million to convert to seconds
    trans_array_time = np.array(trans_array_time) / 1e7 - 11644473600
    trans_array_time = (trans_array_time / (60 * 60 * 24)) + REF_TIME

    # subset the xticks so that we don't plot every one
    xticks = np.linspace(0, max_time, num_xticks)
    # format trans_array_time array so that it can be used to label the x-axis
    xticklabels = [
        i.strftime('%Y-%m-%d %H:%M:%S')
        for i in num2date(trans_array_time[::round(xticks[1])])
    ]

    # subset the yticks so that we don't plot everyone
    yticks = np.linspace(0, max_depth, num_yticks)
    # create range vector (depth in meters)
    yticklabels = np.round(np.arange(0, max_depth, round(yticks[1])) * td_dR)

    fig, ax = plt.subplots()
    ax.grid(False)
    figure_title = 'Converted Power: ' + title + 'Frequency: ' + str(td_f)
    ax.set_title(figure_title, fontsize=12)
    ax.set_xlabel('time (UTC)', fontsize=10)
    ax.set_ylabel('depth (m)', fontsize=10)

    # rotates and right aligns the x labels, and moves the bottom of the
    # axes up to make room for them
    ax.set_xticks(xticks)
    ax.set_xticklabels(xticklabels,
                       rotation=25,
                       horizontalalignment='right',
                       fontsize=10)

    ax.set_yticks(yticks)
    ax.set_yticklabels(yticklabels, fontsize=10)

    ax.tick_params(axis="both", labelcolor="k", pad=4)

    # set the x and y limits
    ax.set_ylim(max_depth, min_depth)
    ax.set_xlim(min_time, max_time)

    # plot the colorbar
    cax = imshow(ax,
                 trans_array,
                 interpolation='none',
                 aspect='auto',
                 cmap='jet',
                 vmin=min_db,
                 vmax=max_db)
    cb = fig.colorbar(cax,
                      orientation='horizontal',
                      ticks=cbar_ticks,
                      shrink=.6)
    cb.ax.set_xticklabels(cbar_ticks,
                          fontsize=8)  # horizontally oriented colorbar
    cb.set_label('dB', fontsize=10)
    cb.ax.set_xlim(-180, -60)

    fig.tight_layout(pad=1.2)
    # adjust the subplot so that the x-tick labels will fit on the canvas
    fig.subplots_adjust(bottom=0.1)

    plt.figtext(0.01,
                0.01,
                '*Note: Strictly sequential time tags are not guaranteed.',
                axes=ax,
                fontsize=7)

    # reposition the cbar
    cb.ax.set_position([.4, .05, .4, .1])

    # save the figure
    fig.savefig(filename, dpi=300)

    # close the figure
    plt.close()
Ejemplo n.º 17
0
def plot_waterfallc(wat,
                    qindex=1,
                    aspect=None,
                    vmax=None,
                    vmin=None,
                    interpolation='none',
                    save=False,
                    return_fig=False,
                    cmap='viridis',
                    *argv,
                    **kwargs):
    '''plot waterfall for a giving compressed file
    
       FD: class object, the compressed file handler
       labeled_array: np.array, a ROI mask
       qindex: the index number of q, will calculate where( labeled_array == qindex)
       aspect: the aspect ratio of the plot
       
       Return waterfall
       Plot the waterfall
    
    '''
    #wat = cal_waterfallc( FD, labeled_array, qindex=qindex)
    if RUN_GUI:
        fig = Figure(figsize=(8, 6))
        ax = fig.add_subplot(111)
    else:
        fig, ax = plt.subplots(figsize=(8, 6))

    if 'uid' in kwargs:
        uid = kwargs['uid']
    else:
        uid = 'uid'
    #fig, ax = plt.subplots(figsize=(8,6))
    ax.set_ylabel('Pixel')
    ax.set_xlabel('Frame')
    ax.set_title('%s_Waterfall_Plot_@qind=%s' % (uid, qindex))
    if 'beg' in kwargs:
        beg = kwargs['beg']
    else:
        beg = 0
    extent = [beg, len(wat) + beg, 0, len(wat.T)]
    if vmax is None:
        vmax = wat.max()
    if vmin is None:
        vmin = wat.min()
    if aspect is None:
        aspect = wat.shape[0] / wat.shape[1]
    im = imshow(ax,
                wat.T,
                cmap=cmap,
                vmax=vmax,
                extent=extent,
                interpolation=interpolation)
    #im = ax.imshow(wat.T, cmap='viridis', vmax=vmax,extent= extent,interpolation = interpolation )
    fig.colorbar(im)
    ax.set_aspect(aspect)

    if save:
        #dt =datetime.now()
        #CurTime = '%s%02d%02d-%02d%02d-' % (dt.year, dt.month, dt.day,dt.hour,dt.minute)
        path = kwargs['path']

        #fp = path + "uid= %s--Waterfall-"%uid + CurTime + '.png'
        fp = path + "%s_waterfall" % uid + '.png'
        plt.savefig(fp, dpi=fig.dpi)

    #plt.show()
    if return_fig:
        return fig, ax, im
def show_C12(C12,  fig_ax=None, q_ind=1, return_fig=False, interpolation = 'none', cmap='viridis',
             logs=True, qlabel=None, *argv,**kwargs):  
 
    '''
    plot one-q of two-time correlation function
    C12: two-time correlation function, with shape as [ time, time, qs]
    q_ind: if integer, for a SAXS q, the nth of q to be plotted, starting from 1,
            if a list: for a GiSAXS [qz_ind, qr_ind]  
    kwargs: support        
        timeperframe: the time interval
        N1: the start frame(time)
        N2: the end frame(time)
        vmin/vmax: for plot
        title: if True, show the tile
    
    e.g.,
        show_C12(g12b, q_ind=1, N1=0, N2=500, vmin=1.05, vmax=1.07,  )
    
    '''
  
    #strs =  [ 'timeperframe', 'N1', 'N2', 'vmin', 'vmax', 'title'] 
    
    if 'uid' in kwargs:
        uid=kwargs['uid']
    else:
        uid='uid'
    shape = C12.shape   
    if (q_ind<1) or (q_ind>shape[2]):
        raise Exceptions("Error: qind starts from 1 (corresponding to python array index 0, but in the plot it will show as 1) to the max Q-length of two time funcs %s."%shape[2]) 
 
                 
    if isinstance(q_ind, int):
        C12_num = q_ind -1
    else:
        qz_ind, qr_ind = q_ind -1
        C12_num =  qz_ind * num_qr + qr_ind 
    
    if 'timeperframe' in kwargs.keys():
        timeperframe =  kwargs['timeperframe']
    else:
        timeperframe=1
        
    if 'vmin' in kwargs.keys():
        vmin =  kwargs['vmin']
    else:
        vmin=1
    if 'vmax' in kwargs.keys():
        vmax =  kwargs['vmax']
    else:
        vmax=1.05        
        
    if 'N1' in kwargs.keys():
        N1 =  kwargs['N1']
        if N1<0:
            N1 = 0
    else:
        N1=0
        
    if 'N2' in kwargs.keys():
        N2 =  kwargs['N2']
        if N2>shape[0]:
            N2 = shape[0]
    else:
        N2= shape[0]
    if 'title' in kwargs.keys():
        title =  kwargs['title']
    else:
        title=True        

    data = C12[N1:N2,N1:N2,C12_num]
    if fig_ax is None:
        if RUN_GUI:
            fig = Figure()
            ax = fig.add_subplot(111)
        else:
            fig, ax = plt.subplots()
    else:
        fig,ax=fig_ax

    #extent=[0, data.shape[0]*timeperframe, 0, data.shape[0]*timeperframe ]
    extent= np.array( [N1, N2, N1, N2]) *timeperframe 
    
    if logs: 
        im = imshow(ax,  data, origin='lower' , cmap=cmap, 
                 norm= LogNorm( vmin, vmax ), interpolation = interpolation, 
            extent=extent )
    else:
        im = imshow(ax, data, origin='lower' , cmap=cmap, 
                 vmin=vmin, vmax=vmax, interpolation = interpolation, 
            extent=extent )    
    if qlabel is not None:
        if isinstance(q_ind, int):
            qstr = 'Qth= %s-qval=%s'%(C12_num+1, qlabel[C12_num])  
    else:
        qstr = 'Qth= %s'%(C12_num+1)  
    if title:
        if isinstance(q_ind, int):
            tit = '%s-[%s-%s] frames--'%(uid,N1,N2)  + qstr          
        else:
            tit =  '%s-[%s-%s] frames--Qzth= %s--Qrth= %s'%(uid,N1,N2, qz_ind, qr_ind )
        ax.set_title( tit  )
    else:
        tit=''        
        #ax.set_title('%s-%s frames--Qth= %s'%(N1,N2,g12_num))
    ax.set_xlabel( r'$t_1$ $(s)$', fontsize = 18)
    ax.set_ylabel( r'$t_2$ $(s)$', fontsize = 18)
    fig.colorbar(im)
    
    save=False    
    if 'save' in kwargs:
        save=kwargs['save']
    if save:       
        path=kwargs['path']
        #fp = path + 'Two-time--uid=%s'%(uid) + tit + CurTime + '.png'
        fp = path + '%s_Two_time'%(uid) + '.png'
        plt.savefig( fp, dpi=fig.dpi)        
     
    if return_fig:
        return fig, ax, im