Exemplo n.º 1
0
def _math_tex_to_qpixmap(math_tex: str, fs: int):
    # set up a mpl figure instance
    fig = Figure()
    fig.patch.set_facecolor('none')
    fig.set_canvas(FigureCanvasAgg(fig))
    renderer = fig.canvas.get_renderer()

    # plot the math_tex expression
    ax = fig.add_axes([0, 0, 1, 1])
    ax.axis('off')
    ax.patch.set_facecolor('none')
    t = ax.text(0, 0, math_tex, ha='left', va='bottom', fontsize=fs)

    # fit figure size to text artist
    f_width, f_height = fig.get_size_inches()
    fig_bbox = fig.get_window_extent(renderer)
    text_bbox = t.get_window_extent(renderer)
    tight_fwidth = text_bbox.width * f_width / fig_bbox.width
    tight_fheight = text_bbox.height * f_height / fig_bbox.height
    fig.set_size_inches(tight_fwidth, tight_fheight)

    # convert mpl figure to QPixmap
    buf, size = fig.canvas.print_to_buffer()

    return QPixmap(QImage.rgbSwapped(QImage(buf, size[0], size[1], QImage.Format_ARGB32)))
Exemplo n.º 2
0
 def __init__(self, parent=None, width=5, height=5, dpi=100):
     self.fig = Figure(figsize=(width, height), dpi=dpi)
     FigureCanvasQTAgg.__init__(self, self.fig)
     self.setParent(parent)
     FigureCanvasQTAgg.setSizePolicy(self, QtGui.QSizePolicy.Expanding,
                                     QtGui.QSizePolicy.Expanding)
     FigureCanvasQTAgg.updateGeometry(self)
Exemplo n.º 3
0
def ant_ant_stat_frame(title_text, full_pol_array, station_names, output_name=None, dpi=50, **kwargs):
    if output_name is None:
        fig = figure(figsize=(32,30), dpi=dpi)
    else:
        fig=Figure(figsize=(32,30), dpi=dpi)

    if output_name is None:
        fig.suptitle(title_text, fontsize=30)
    else:
        fig.suptitle(title_text+' '+output_name, fontsize=30)
    
    ax1=fig.add_subplot(2,2,1)
    ant_ant_stat_plot(fig, ax1, title_text+' XX', full_pol_array[:,:,0], station_names, **kwargs)
    
    ax2=fig.add_subplot(2,2,2)
    ant_ant_stat_plot(fig, ax2, title_text+' XY', full_pol_array[:,:,1], station_names, **kwargs)
    
    ax3=fig.add_subplot(2,2,3)
    ant_ant_stat_plot(fig, ax3, title_text+' YX', full_pol_array[:,:,2], station_names, **kwargs)
    
    ax4=fig.add_subplot(2,2,4)
    ant_ant_stat_plot(fig, ax4, title_text+' YY', full_pol_array[:,:,3], station_names, **kwargs)

    if output_name is not None:
        canvas = FigureCanvasAgg(fig)
        if output_name[-4:] in ['.jpg', '.JPG']:
            canvas.print_jpg(output_name, dpi=dpi, quality=55)
        else:
            canvas.print_figure(output_name, dpi=dpi)
        pass
    pass
Exemplo n.º 4
0
 def __init__(self, parent=None, width=15, height=5, dpi=100):
     self.fig = Figure(figsize=(width, height), dpi=dpi)
     FigureCanvasQTAgg.__init__(self, self.fig)
     self.setParent(parent)
     self.ax = self.fig.add_subplot(111)
     # self.ax.figure.subplots_adjust(left=0.08, right=0.92, bottom=0.1, top=0.95)
     FigureCanvasQTAgg.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
     FigureCanvasQTAgg.updateGeometry(self)
Exemplo n.º 5
0
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        print(width, height)
        self.fig = Figure(figsize=(width, height), dpi=dpi)
        self.parent = parent
        self.axes = self.fig.add_subplot(111)

        FigureCanvas.__init__(self, self.fig)
        self.setParent(parent)
Exemplo n.º 6
0
 def __init__(self, parent=None, width=15, height=5, dpi=100):
     self.fig = Figure(figsize=(width, height), dpi=dpi)
     FigureCanvasQTAgg.__init__(self, self.fig)
     self.setParent(parent)
     self.ax = self.fig.add_subplot(111)
     self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                        QtWidgets.QSizePolicy.Expanding)
     self.updateGeometry()
Exemplo n.º 7
0
 def __init__(self, parent=None, width=15, height=5, dpi=100):
     self.fig = Figure(figsize=(width, height), dpi=dpi)
     FigureCanvasQTAgg.__init__(self, self.fig)
     self.setParent(parent)
     self.axes2D = self.fig.add_subplot(111)
     FigureCanvasQTAgg.updateGeometry(self)
     self.axes2D.figure.subplots_adjust(left=0.01, right=0.92,
                                        bottom=0.05, top=0.98)
     self.notes = []
Exemplo n.º 8
0
def SavePlot(y, filename, xtitle='', ytitle='', title=''):
    plot = Figure(figsize=(12, 3))
    ax = plot.add_subplot(111)
    #    plot.grid(True)
    ax.set_title(title)
    ax.set_xlabel(xtitle)
    ax.set_ylabel(ytitle)
    #    ax.axis(ymax=1, ymin =-3)
    plot.subplots_adjust(left=0.1, bottom=0.2)

    x = range(len(y))
    #    ax.plot(x, nu.log2(Y))
    ax.plot(x, y)
    FigureCanvasAgg(ax.get_figure()).print_figure(filename, dpi=120)
    return
Exemplo n.º 9
0
    def __init__(self,  dim=2, parent=None):
        self.fig = Figure(figsize=(10, 10), dpi=100)
        self.dim = dim
        FigureCanvasQTAgg.__init__(self, self.fig)
        self.setParent(parent)
        FigureCanvasQTAgg.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        FigureCanvasQTAgg.updateGeometry(self)

        if dim==2:
            self.ax = self.fig.add_subplot(111)
            self.ax.figure.subplots_adjust(left=0.08, right=0.98, bottom=0.08, top=0.92)

        else:
            self.ax = Axes3D(self.fig)
            self.ax.mouse_init(rotate_btn=1, zoom_btn=2)

        FigureCanvasQTAgg.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        FigureCanvasQTAgg.updateGeometry(self)
Exemplo n.º 10
0
def timeseries_station_page(ms, station_name, time_slots, data, fn=abs, output_name=None):
    dpi=50
    if output_name is None:
        fig = figure(figsize=(32,24), dpi=dpi)
    else:
        fig = Figure(figsize=(32,24), dpi=dpi)

    station_name_list = list(ms.tables['antennae']['NAME'])
    station_id        = station_name_list.index(station_name)
    num_ant           = len(ms.tables['antennae'])
    tsn               = time_slots-time_slots[0]
    pol_names         = corr_type(ms.tables['polarization']['CORR_TYPE'][0])
    ref_freq_mhz      = ms.tables['spectral_windows'][0]['REF_FREQUENCY']/1.e6

    fig.suptitle(ms.msname+': '+fn.__name__+'(vis) with '+station_name+' at %3.2f MHz' % (ref_freq_mhz,), fontsize='large')

    median_amp = ma.median(ma.mean(ma.median(fn(data[station_id,:,0::3,:]), axis=-1), axis=-1), axis=-1)
    
    for id2,name in enumerate(station_name_list):
        ax = fig.add_subplot(ceil(num_ant/4.0),4, id2+1)
        ax.plot(tsn, fn(data[station_id,id2,0,:]), c='blue'  , label=pol_names[0])
        ax.plot(tsn, fn(data[station_id,id2,1,:]), c='green' , label=pol_names[1])
        ax.plot(tsn, fn(data[station_id,id2,2,:]), c='purple', label=pol_names[2])
        ax.plot(tsn, fn(data[station_id,id2,3,:]), c='red'   , label=pol_names[3])
        ax.grid()
        ax.set_ylabel(station_name_list[id2], rotation='horizontal')
        ax.set_ylim(0.0, 3*median_amp)
        ax.set_yticklabels([])
        if id2 < len(station_name_list)-4:
            ax.set_xticklabels([])
        else:
            ax.set_xlabel('Time [s]')    
        pass
    fig.subplots_adjust(hspace=0.0, top=0.95, bottom=0.04)
    if output_name is not None:
        canvas = FigureCanvasAgg(fig)
        if output_name[-4:] in ['.jpg', '.JPG']:
            canvas.print_jpg(output_name, dpi=dpi, quality=55)
        else:
            canvas.print_figure(output_name, dpi=dpi)
        pass
    pass
Exemplo n.º 11
0
def station_gain_bar_chart(ms, station_name, time_slots, data, output_name= None):
    dpi=50
    if output_name is None:
        fig = figure(figsize=(38,24), dpi=dpi)
    else:
        fig = Figure(figsize=(38,24), dpi=dpi)

    station_name_list = list(ms.tables['antennae']['NAME'])
    num_stations      = len(station_name_list)
    station_id        = station_name_list.index(station_name)
    ref_freq_mhz      = ms.tables['spectral_windows'][0]['REF_FREQUENCY']/1.e6

    
    is_autocorrelation = array([station_name == name for name in ms.tables['antennae']['NAME']])

    noise = ma.array(data[station_id,:, 1:3,:].imag.std(axis=-1).mean(axis=-1),
                     mask = is_autocorrelation)
    sig    = median(abs(data[station_id, :, :, :]),axis=-1)
    signal = ma.array(sig, mask = is_autocorrelation[:, newaxis]*ones((num_stations, 4)))
    ax = fig.add_subplot(1,1,1)
    xx_bars = ax.bar(arange(len(station_name_list))-0.4, signal[:, 0], width=0.2, color='blue', label='xx')
    xy_bars = ax.bar(arange(len(station_name_list))-0.2, signal[:, 1], width=0.2, color='lightblue', label='xy')
    yx_bars = ax.bar(arange(len(station_name_list))    , signal[:, 2], width=0.2, color='lightpink', label='yx')
    yy_bars = ax.bar(arange(len(station_name_list))+0.2, signal[:, 3], width=0.2, color='red', label='yy')
    for x_pos, name  in enumerate(station_name_list):
        if name != station_name:
            ax.text(x_pos, signal[x_pos,:].max()*1.02, name, rotation='vertical',
                    horizontalalignment='center', verticalalignment='bottom',
                    fontsize=25)
            ax.text(x_pos, signal[x_pos,:].max()*-0.01, name, rotation='vertical',
                    horizontalalignment='center', verticalalignment='top',
                    fontsize=25)
        else:
            ax.text(x_pos, 0.0, ' Reference station: '+name, rotation='vertical',
                    horizontalalignment='center', verticalalignment='bottom',
                    fontsize=25)

    ax.set_xlabel('Station', fontsize=40)
    ax.set_ylabel('Visibility amplitude', fontsize=40)
    ax.set_ylim(0, ma.max(signal)*1.2)
    ax.set_xlim(-1.0, num_stations)
    ax.set_xticklabels([])
    ax.set_title('%s:\nVis. amp. with station %s at %5.2f MHz' %
                 (ms.msname, station_name, ref_freq_mhz),
                 fontsize=40)
    old_legend_fontsize = rcParams['legend.fontsize']
    rcParams.update({'legend.fontsize': 25})
    legend_instance = ax.legend()
    
    
    for label in ax.get_yticklabels():
        label.set_fontsize(40)
    
    if output_name is not None:
        canvas = FigureCanvasAgg(fig)
        if output_name[-4:] in ['.jpg', '.JPG']:
            canvas.print_jpg(output_name, dpi=dpi, quality=55)
        else:
            canvas.print_figure(output_name, dpi=dpi)
        pass

    rcParams.update({'legend.fontsize': old_legend_fontsize})