Esempio n. 1
0
def plot_2d_to_axis(
    spectrum: Spectrum2D,
    ax: Axes,
    cmap: Union[str, Colormap] = 'viridis',
    interpolation: str = 'nearest',
    norm: Optional[Normalize] = None,
) -> NonUniformImage:
    """Plot Spectrum2D object to Axes

    Parameters
    ----------
    spectrum
        2D data object for plotting as NonUniformImage. The x_tick_labels
        attribute will be used to mark labelled points.
    ax
        Matplotlib axes to which image will be drawn
    cmap
        Matplotlib colormap or registered colormap name
    interpolation
        Interpolation method: 'nearest' or 'bilinear' for a pixellated or
        smooth result
    norm
        Matplotlib normalization object; set this in order to ensure separate
        plots are on the same colour scale.

    """
    x_unit = spectrum.x_data_unit
    y_unit = spectrum.y_data_unit
    z_unit = spectrum.z_data_unit

    x_bins = spectrum.get_bin_edges('x').to(x_unit).magnitude
    y_bins = spectrum.get_bin_edges('y').to(y_unit).magnitude

    image = NonUniformImage(ax,
                            interpolation=interpolation,
                            extent=(min(x_bins), max(x_bins), min(y_bins),
                                    max(y_bins)),
                            cmap=cmap)
    if norm is not None:
        image.set_norm(norm)

    image.set_data(
        spectrum.get_bin_centres('x').to(x_unit).magnitude,
        spectrum.get_bin_centres('y').to(y_unit).magnitude,
        spectrum.z_data.to(z_unit).magnitude.T)
    ax.images.append(image)
    ax.set_xlim(min(x_bins), max(x_bins))
    ax.set_ylim(min(y_bins), max(y_bins))

    _set_x_tick_labels(ax, spectrum.x_tick_labels, spectrum.x_data)

    return image
Esempio n. 2
0
File: plots.py Progetto: nbren12/gnl
def plot2d(x, y, z, ax=None, cmap='RdGy', norm=None, **kw):
    """ Plot dataset using NonUniformImage class

    Parameters
    ----------
    x : (nx,)
    y : (ny,)
    z : (nx,nz)
        
    """
    from matplotlib.image import NonUniformImage
    if ax is None:
        fig = plt.gcf()
        ax = fig.add_subplot(111)

    xlim = (x.min(), x.max())
    ylim = (y.min(), y.max())

    im = NonUniformImage(ax,
                         interpolation='bilinear',
                         extent=xlim + ylim,
                         cmap=cmap)

    if norm is not None:
        im.set_norm(norm)

    im.set_data(x, y, z, **kw)
    ax.images.append(im)
    #plt.colorbar(im)
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    def update(z):
        return im.set_data(x, y, z, **kw)

    return im, update
Esempio n. 3
0
def test_nonuniformimage_setnorm():
    ax = plt.gca()
    im = NonUniformImage(ax)
    im.set_norm(plt.Normalize())
Esempio n. 4
0
def test_nonuniformimage_setnorm():
    ax = plt.gca()
    im = NonUniformImage(ax)
    im.set_norm(plt.Normalize())
Esempio n. 5
0
def tsys_show_dynspec(out,idx=None,ampscl=None,domedian=True,frq='linear'):
    ''' Given "standard" output of rd_tsys_multi(), possibly
        calibrated using calibration.sp_apply_cal() and/or 
        background-subtracted using calibration.sp_bg_subtract(),
        make a nice image plot of the dynamic spectrum.  The
        plot can contain multiple panels if domedian is False,
        or plot a single spectrum representing the median of
        multiple antennas.  Only linear frequency scale is supported
        at this time.
    '''
    from matplotlib.image import NonUniformImage
    from matplotlib.dates import AutoDateLocator, DateFormatter
    from matplotlib import colors
    from matplotlib.pyplot import locator_params
    from util import Time

    nant, npol, nf, nt = out['tsys'].shape
    if idx is None:
        idx_ = np.arange(nt)
    else:
        idx_ = idx
    ut = Time(out['ut_mjd'][idx_],format='mjd')
    utd = (ut.mjd - int(ut[0].mjd) + 1).astype('float')
    good = np.where(out['fghz'] > 2.0)[0]
    if frq == 'linear':
        fghz = out['fghz'][good]
    else:
        fghz = np.log10(out['fghz'][good])

    locator = AutoDateLocator(interval_multiples=True) #maxticks=7,minticks=3,
    tsys = out['tsys'][:,:,good,idx_]
    if domedian:
        medtsys = np.nanmedian(np.nanmedian(tsys,0),0)
        fig = plt.figure()
        fig.suptitle('EOVSA Total Power Data for '+ut[0].iso[:10],fontsize=14)
        # Plot X-feed
        ax = fig.add_subplot(211)
        ax.xaxis_date()
        ax.set_ylabel('Frequency [GHz]')
        ax.set_title('Median Total Power')
        extent=[utd[0],utd[-1],fghz[0],fghz[-1]]
#        extent=[ut[0],ut[-1],fghz[0],fghz[-1]]
        im = NonUniformImage(ax,extent=extent)
        if ampscl != None:
            im.set_norm(colors.Normalize(vmin=ampscl[0],vmax=ampscl[1]))
        im.set_data(utd,fghz,medtsys)
        #fig.colorbar(im,ax)
        ax.images.append(im)
        ax.set_xlim(extent[0],extent[1])
        ax.set_ylim(extent[2],extent[3])
        ax.xaxis.set_major_locator(locator)
        #ax.xaxis.set_minor_locator(MinuteLocator(interval=10))
        # Set up date formatting
        fmt = DateFormatter('%H:%M:%S')
        ax.xaxis.set_major_formatter(fmt)
        labels = (10**ax.get_yticks()).astype('str')
        for i in range(len(labels)):
            labels[i] = labels[i][:4]
        ax.set_yticklabels(labels)
        # Repeat for Y-feed
        ax = fig.add_subplot(212)
        ax.xaxis_date()
        ax.set_xlabel('Start time '+ut[0].iso[:19]+' UT')
        ax.set_title('Median of Y-poln')
        ax.set_ylabel('Frequency [GHz]')
        im = NonUniformImage(ax,extent=extent)
        if ampscl != None:
            im.set_norm(colors.Normalize(vmin=ampscl[0],vmax=ampscl[1]))
        im.set_data(utd,fghz,medytsys)
        #fig.colorbar(im,ax)
        ax.images.append(im)
        ax.set_xlim(extent[0],extent[1])
        ax.set_ylim(extent[2],extent[3])
        ax.xaxis.set_major_locator(locator)
        # Set up date formatting
        ax.xaxis.set_major_formatter(fmt)
        ax.set_yticklabels(labels)
    plt.draw()
    plt.show()
Esempio n. 6
0
def tsys_show_dynspec(out, idx=None, ampscl=None, domedian=True, frq='linear'):
    ''' Given "standard" output of rd_tsys_multi(), possibly
        calibrated using calibration.sp_apply_cal() and/or 
        background-subtracted using calibration.sp_bg_subtract(),
        make a nice image plot of the dynamic spectrum.  The
        plot can contain multiple panels if domedian is False,
        or plot a single spectrum representing the median of
        multiple antennas.  Only linear frequency scale is supported
        at this time.
    '''
    from matplotlib.image import NonUniformImage
    from matplotlib.dates import AutoDateLocator, DateFormatter
    from matplotlib import colors
    from matplotlib.pyplot import locator_params
    from util import Time

    nant, npol, nf, nt = out['tsys'].shape
    if idx is None:
        idx_ = np.arange(nt)
    else:
        idx_ = idx
    ut = Time(out['ut_mjd'][idx_], format='mjd')
    utd = (ut.mjd - int(ut[0].mjd) + 1).astype('float')
    good = np.where(out['fghz'] > 2.0)[0]
    if frq == 'linear':
        fghz = out['fghz'][good]
    else:
        fghz = np.log10(out['fghz'][good])

    locator = AutoDateLocator(interval_multiples=True)  #maxticks=7,minticks=3,
    tsys = out['tsys'][:, :, good, idx_]
    if domedian:
        medtsys = np.nanmedian(np.nanmedian(tsys, 0), 0)
        fig = plt.figure()
        fig.suptitle('EOVSA Total Power Data for ' + ut[0].iso[:10],
                     fontsize=14)
        # Plot X-feed
        ax = fig.add_subplot(211)
        ax.xaxis_date()
        ax.set_ylabel('Frequency [GHz]')
        ax.set_title('Median Total Power')
        extent = [utd[0], utd[-1], fghz[0], fghz[-1]]
        #        extent=[ut[0],ut[-1],fghz[0],fghz[-1]]
        im = NonUniformImage(ax, extent=extent)
        if ampscl != None:
            im.set_norm(colors.Normalize(vmin=ampscl[0], vmax=ampscl[1]))
        im.set_data(utd, fghz, medtsys)
        #fig.colorbar(im,ax)
        ax.images.append(im)
        ax.set_xlim(extent[0], extent[1])
        ax.set_ylim(extent[2], extent[3])
        ax.xaxis.set_major_locator(locator)
        #ax.xaxis.set_minor_locator(MinuteLocator(interval=10))
        # Set up date formatting
        fmt = DateFormatter('%H:%M:%S')
        ax.xaxis.set_major_formatter(fmt)
        labels = (10**ax.get_yticks()).astype('str')
        for i in range(len(labels)):
            labels[i] = labels[i][:4]
        ax.set_yticklabels(labels)
        # Repeat for Y-feed
        ax = fig.add_subplot(212)
        ax.xaxis_date()
        ax.set_xlabel('Start time ' + ut[0].iso[:19] + ' UT')
        ax.set_title('Median of Y-poln')
        ax.set_ylabel('Frequency [GHz]')
        im = NonUniformImage(ax, extent=extent)
        if ampscl != None:
            im.set_norm(colors.Normalize(vmin=ampscl[0], vmax=ampscl[1]))
        im.set_data(utd, fghz, medytsys)
        #fig.colorbar(im,ax)
        ax.images.append(im)
        ax.set_xlim(extent[0], extent[1])
        ax.set_ylim(extent[2], extent[3])
        ax.xaxis.set_major_locator(locator)
        # Set up date formatting
        ax.xaxis.set_major_formatter(fmt)
        ax.set_yticklabels(labels)
    plt.draw()
    plt.show()