Ejemplo n.º 1
0
def sticks(date,u,v,tnorm=0.1,figurewidth=8,pickind=1,color='blue'):
    """
    sticks - create velocity stick plot

    sticks(date, u, v, tnorm=0.1, color='blue' \
            figurewidth=8, pickind=1)

    date - list/array of datetime elements
    u - list/array of velocity in eastern direction
    v - list/array of velocity in northern direction
    tnorm - length of a u=max(u,v) as part of the time axis
    color - color of sticks
    figurewidth - width of the figure in inch
    pickind - plot every "pickind"-vector
    """
    onedt=(date[-1]-date[0])
    onedt=timedelta(tnorm*onedt.days,tnorm*onedt.seconds)
    daynorm=onedt.days+onedt.seconds/86400.0

    u=np.asarray(u)
    v=np.asarray(v)
    norm=np.maximum(np.absolute(u).max(),np.absolute(v).max())

    t=[]
    f=[]
    mask=[]
    fac=pickind
    for i in range(int(len(date)/fac)):
        t.append(plt.date2num(date[i*fac]))
        f.append(0.0)
        mask.append(False)
        t.append(plt.date2num(date[i*fac] \
                + timedelta(u[i*fac]/norm*onedt.days,u[i*fac]/norm*onedt.seconds)))
        f.append(v[i*fac]/norm*daynorm)
        mask.append(False)
        t.append(plt.date2num(date[i*fac]))
        f.append(0.0)
        mask.append(True)
    
    t=np.asarray(t)
    f=np.asarray(f)
    mask=np.asarray(mask)
    f=np.ma.masked_array(f,mask=mask)
    
    plt.figure(figsize=(figurewidth,tnorm*figurewidth))
    plt.plot_date(t,f,'-',color=color)
    ax=plt.gca()
    ax.set_aspect('equal')
    ax.set_xlim(t[0],t[-1])
    ax.set_ylim(-1.0*daynorm,1.0*daynorm)
    ax.set_frame_on(False)
    ax.yaxis.set_visible(False)
Ejemplo n.º 2
0
def sticks(date, u, v, tnorm=0.1, figurewidth=8, pickind=1, color='blue'):
    """
    sticks - create velocity stick plot

    sticks(date, u, v, tnorm=0.1, color='blue' \
            figurewidth=8, pickind=1)

    date - list/array of datetime elements
    u - list/array of velocity in eastern direction
    v - list/array of velocity in northern direction
    tnorm - length of a u=max(u,v) as part of the time axis
    color - color of sticks
    figurewidth - width of the figure in inch
    pickind - plot every "pickind"-vector
    """
    onedt = (date[-1] - date[0])
    onedt = timedelta(tnorm * onedt.days, tnorm * onedt.seconds)
    daynorm = onedt.days + onedt.seconds / 86400.0

    u = np.asarray(u)
    v = np.asarray(v)
    norm = np.maximum(np.absolute(u).max(), np.absolute(v).max())

    t = []
    f = []
    mask = []
    fac = pickind
    for i in range(int(len(date) / fac)):
        t.append(plt.date2num(date[i * fac]))
        f.append(0.0)
        mask.append(False)
        t.append(plt.date2num(date[i*fac] \
                + timedelta(u[i*fac]/norm*onedt.days,u[i*fac]/norm*onedt.seconds)))
        f.append(v[i * fac] / norm * daynorm)
        mask.append(False)
        t.append(plt.date2num(date[i * fac]))
        f.append(0.0)
        mask.append(True)

    t = np.asarray(t)
    f = np.asarray(f)
    mask = np.asarray(mask)
    f = np.ma.masked_array(f, mask=mask)

    plt.figure(figsize=(figurewidth, tnorm * figurewidth))
    plt.plot_date(t, f, '-', color=color)
    ax = plt.gca()
    ax.set_aspect('equal')
    ax.set_xlim(t[0], t[-1])
    ax.set_ylim(-1.0 * daynorm, 1.0 * daynorm)
    ax.set_frame_on(False)
    ax.yaxis.set_visible(False)
Ejemplo n.º 3
0
    def signature(self,m=0,n=0, component='s_mag', 
                  vmax = None, vs_time=False, cbar_label=None,
                  *args, **kwargs):
        '''
        Visualization of a NetworkSet.

        Creates a colored image representing the some component
        of each Network in the  NetworkSet, vs frequency.
        
         


        Parameters
        ------------
        m : int
            first s-parameters index
        n : int
            second s-parameter index
        component : ['s_mag','s_db','s_deg' ..]
            scalar component of Network to visualize. should
            be a property of the Network object.
        vmax : number
            sets upper limit of colorbar, if None, will be set to
            3*mean of the magnitude of the complex difference
        vs_time: Boolean
            if True, then we assume each Network.name was made with 
            rf.now_string, and we make the y-axis a datetime axis
        cbar_label: String
            label for the colorbar 
        
        \*args,\*\*kw : arguments, keyword arguments
            passed to :func:`~pylab.imshow`


        '''
        
            
        mat = npy.array([self[k].__getattribute__(component)[:,m,n] \
            for k in range(len(self))])
        
        #if vmax is None:
        #    vmax = 3*mat.mean()
        
        if vs_time:
            # create a datetime index
            dt_idx = [now_string_2_dt(k.name ) for k in self]
            mpl_times = plb.date2num(dt_idx)
            y_max = mpl_times[0]
            y_min = mpl_times[-1]
        
        else:
            y_min =  len(self)
            y_max =  0
            
        # creates x and y scales
        freq = self[0].frequency
        extent = [freq.f_scaled[0], freq.f_scaled[-1], y_min ,y_max]
        
        # set default imshow kwargs
        kw ={'extent':extent,'aspect':'auto', 'interpolation':'nearest',
            'vmax':vmax }
        # update the users kwargs
        kw.update(kwargs)
        img = plb.imshow(mat, *args, **kw)

        if vs_time:
            ax =plb.gca()
            ax.yaxis_date()
            #date_format = plb.DateFormatter('%M:%S.%f')
            #ax.yaxis.set_major_formatter(date_format)
            #cbar.set_label('Magntidue (dB)')
            plb.ylabel('Time')
        else:
            plb.ylabel('Network #')
        
        plb.grid(0)
        freq.labelXAxis()
        
            
        cbar = plb.colorbar()
        if cbar_label is not None:
            cbar.set_label(cbar_label)

        return img