Esempio n. 1
0
def setticks(ax,
             xlog=False,
             ylog=False,
             xmajor=5,
             xminor=1,
             ymajor=2,
             yminor=0.5):

    if not xlog:
        xmajorLocator = pylab.MultipleLocator(xmajor)
        xmajorFormatter = pylab.FormatStrFormatter('%d')
        xminorLocator = pylab.MultipleLocator(xminor)
        ax.xaxis.set_major_locator(xmajorLocator)
        #ax.xaxis.set_major_formatter(xmajorFormatter)
        ax.xaxis.set_minor_locator(xminorLocator)

    if not ylog:
        ymajorLocator = pylab.MultipleLocator(ymajor)
        ymajorFormatter = pylab.FormatStrFormatter('%d')
        yminorLocator = pylab.MultipleLocator(yminor)
        ax.yaxis.set_major_locator(ymajorLocator)
        #ax.yaxis.set_major_formatter(ymajorFormatter)
        ax.yaxis.set_minor_locator(yminorLocator)

    ax.get_yaxis().set_tick_params(which='both', direction='out')
    ax.get_xaxis().set_tick_params(which='both', direction='out')
    for tick in ax.xaxis.get_ticklines():
        tick.set_markersize(3.25)
    for tick in ax.yaxis.get_ticklines():
        tick.set_markersize(3.25)
    for tick in ax.xaxis.get_ticklines(minor=True):
        tick.set_markersize(2.75)
    for tick in ax.yaxis.get_ticklines(minor=True):
        tick.set_markersize(2.75)
Esempio n. 2
0
    def plot_spectrum(self, p, plot_variable):
        varlist = []
        if plot_variable:
            if plot_variable not in p.pot_list:
                raise ArgumentError("variable %s not found" % plot_variable)
            ##hack
            for k, t in self.V.items():
                if isinstance(k, P):
                    if not isinstance(t, dict):
                        t = dict(value=t)
                    var = t.get('var')
                    if var is None:
                        var = str(k) + 'v'
                    if var == plot_variable:
                        break
            loga = t.get('a', 0)
            inv = t.get('inv', 0)
            for i in range(5):
                pot = i / 4
                lbl = "%s" % pot
                if inv:
                    pot = 1 - pot
                if loga:
                    pot = (math.exp(loga * pot) - 1) / (math.exp(loga) - 1)
                varlist.append((plot_variable, pot, lbl))
        else:
            varlist.append((None, None, p.out_labels))
        n = None
        cut = None

        def spec(y):
            s = 20 * np.log10(abs(np.fft.fft(y, n, axis=0)[cut]))
            return np.where(s > -80, s, np.nan)

        labels = []
        for var, val, lbl in varlist:
            if var is not None:
                p.set_variable(var, val)
            y = self.spectrum_signal(p, magnitude=1e-4)
            if n is None:
                n = dk_lib.pow2roundup(len(y))
                cut = slice(n * 20 // int(self.FS), n * 10000 // int(self.FS))
                w = fftfreq(n, 1.0 / self.FS)[cut]
            pl.semilogx(w, spec(y), label=plot_variable)
            pl.xlabel('Frequency')
            pl.ylabel('Magnitude ')
            if plot_variable:
                pl.title(plot_variable)
            if isinstance(lbl, basestring):
                labels.append(lbl)
            else:
                labels.extend(lbl)
        ax = pl.gca()
        ax.grid()
        ax.yaxis.set_major_formatter(pl.FormatStrFormatter('%d dB'))
        ax.xaxis.set_major_formatter(pl.FormatStrFormatter('%d Hz'))
        self.finish_plot(labels, loc='upper left')
Esempio n. 3
0
def plotTrans(root):
    """
    Plot the fractional change in plate scale and PA over many different
    starlists that  have been aligned. You can either give align results
    for many different epochs or align results for many different cleaned
    frames in a single epoch.

    root - align output
    """
    tab = asciidata.open(root + '.trans')

    a0 = tab[3].tonumarray()
    a0e = tab[4].tonumarray()
    a1 = tab[5].tonumarray()
    a1e = tab[6].tonumarray()
    a2 = tab[7].tonumarray()
    a2e = tab[8].tonumarray()
    b0 = tab[9].tonumarray()
    b0e = tab[10].tonumarray()
    b1 = tab[11].tonumarray()
    b1e = tab[12].tonumarray()
    b2 = tab[13].tonumarray()
    b2e = tab[14].tonumarray()

    trans = []
    for ff in range(len(a0)):
        tt = objects.Transform()
        tt.a = [a0[ff], a1[ff], a2[ff]]
        tt.b = [b0[ff], b1[ff], b2[ff]]
        tt.aerr = [a0e[ff], a1e[ff], a2e[ff]]
        tt.berr = [b0e[ff], b1e[ff], b2e[ff]]
        tt.linearToSpherical(override=False)

        trans.append(tt)

    # Read epochs
    dateTab = asciidata.open(root + '.date')
    numEpochs = dateTab.ncols
    years = [dateTab[i][0] for i in range(numEpochs)]

    p.clf()
    p.subplot(211)
    p.plot(scale - 1.0, 'ko')
    p.ylabel('Fract. Plate Scale Difference')
    if (years[0] != years[1]):
        thePlot = p.gca()
        thePlot.get_xaxis().set_major_locator(p.MultipleLocator(0.1))
        thePlot.get_xaxis().set_major_formatter(p.FormatStrFormatter('%8.3f'))

    p.subplot(212)
    p.plot(angle, 'ko')
    p.ylabel('Position Angle')
    if (years[0] != years[1]):
        thePlot = p.gca()
        thePlot.get_xaxis().set_major_locator(p.MultipleLocator(0.1))
        thePlot.get_xaxis().set_major_formatter(p.FormatStrFormatter('%8.3f'))
Esempio n. 4
0
def plot_all(x_outliers, y_outliers, x_model, y_model, data, counter):
    """Plotting the data. Outliers shown in red. Linear model shown as dotted
    line.

    :param x_outliers: list, outlier IDs (str)
    :param y_outliers: list, outlier IDs (str)
    :param x_model: array_like, linear model
    :param y_model: array_like, linear model
    :param data: np array, the data
    :param counter: int, counter keeping track of iterations
    :return: None
    """
    w, h = plt.figaspect(1.5)
    fig = plt.figure(figsize=(w, h))
    ax = fig.add_subplot(211)
    ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
    smooth_x = np.linspace(min(data["xval"]), max(data["xval"]), 1000)
    smooth_y = np.linspace(min(data["yval"]), max(data["yval"]), 1000)
    plt.plot(data["xval"], data["yval"], "ok", markersize=6)
    plt.plot(smooth_x, x_model(smooth_x), "--k", linewidth=2.5)
    for outlier in x_outliers:
        index = np.where(data["name"] == outlier)[0][0]
        plt.plot(data["xval"][index], data["yval"][index], "or", markersize=6)
    plt.tick_params(width=2, labelsize=14)
    plt.axis([0, 1.1 * max(data["xval"]), 0, 1.1 * max(data["yval"])])
    plt.xlabel("Independent Variables", fontsize=14)
    plt.ylabel("Dependent Variables", fontsize=14)
    ax = fig.add_subplot(212)
    ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
    plt.plot(data["yval"], data["xval"], "ok", markersize=6)
    plt.plot(smooth_y, y_model(smooth_y), "--k", linewidth=2.5)
    for outlier in y_outliers:
        index = np.where(data["name"] == outlier)[0][0]
        plt.plot(data["yval"][index], data["xval"][index], "or", markersize=6)
    plt.tick_params(width=2, labelsize=14)
    plt.axis([0, 1.1 * max(data["yval"]), 0, 1.1 * max(data["xval"])])
    plt.xlabel("Independent Variables", fontsize=14)
    plt.ylabel("Dependent Variables", fontsize=14)
    plt.subplots_adjust(left=0.2, hspace=0.5)
    sns.despine()
    plt.savefig(os.getcwd() + "/" + "swap_round" + str(counter) + ".png")
Esempio n. 5
0
def yAxis():
    ay = pylab.subplot(111)
    majLoc = pylab.MultipleLocator(50)
    majFmat = pylab.FormatStrFormatter(
        '%d')  # or some other format - this puts the numbers on
    ay.yaxis.set_major_locator(majLoc)
    ay.yaxis.set_major_formatter(majFmat)

    minLoc = pylab.MultipleLocator(10)
    ay.yaxis.set_minor_locator(
        minLoc)  #for the minor ticks, use no labels; default NullFormatter
Esempio n. 6
0
def xAxis():
    ax = pylab.subplot(111)
    majLoc = pylab.MultipleLocator(0.02)
    majFmat = pylab.FormatStrFormatter(
        '%f')  # or some other format - this puts the numbers on
    ax.xaxis.set_major_locator(majLoc)
    #    ax.xaxis.set_major_formatter(majFmat)

    minLoc = pylab.MultipleLocator(0.01)
    ax.xaxis.set_minor_locator(
        minLoc)  #for the minor ticks, use no labels; default NullFormatter
Esempio n. 7
0
def X_axis_label_format(format):
    """
  Define the X-axis label format
  """
    this_axes = py.gca()
    this_figure = py.gcf()
    this_image = py.gci()
    # Set a tick on every integer that is multiple of base in the view interval
    # which is 1 in this case
    majorLocator = py.MultipleLocator(1)
    majorFormatter = py.FormatStrFormatter(format)
    this_axes.xaxis.set_major_locator(majorLocator)
    this_axes.xaxis.set_major_formatter(majorFormatter)
Esempio n. 8
0
def plot_one(outliers, model, data, counter):
    """Plotting the data under the condition that axes are not swapped.

    :param outliers: list, outlier IDs (str)
    :param model: array_like, linear model
    :param data: np array, the data set
    :param counter: int, counter keeping track of iterations
    :return: None
    """
    fig, ax = plt.subplots()
    ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
    ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
    smooth_x = np.linspace(min(data["xval"]), max(data["xval"]), 1000)
    plt.plot(data["xval"], data["yval"], "ok", markersize=6)
    plt.plot(smooth_x, model(smooth_x), "--k", linewidth=2.5)
    for outlier in outliers:
        index = np.where(data["name"] == outlier)[0][0]
        plt.plot(data["xval"][index], data["yval"][index], "or", markersize=6)
    plt.tick_params(width=2, labelsize=14)
    plt.xlabel("Independent Variables", fontsize=14)
    plt.ylabel("Dependent Variables", fontsize=14)
    sns.despine()
    plt.savefig(os.getcwd() + "/" + "no_swap_round" + str(counter) + ".png")
    plt.clf()
Esempio n. 9
0
    def __init__(self,
                 nh,
                 nv,
                 brightnessunit,
                 direction_label,
                 direction_reference,
                 spectral_label,
                 spectral_unit,
                 ticksize,
                 title='',
                 separatepanel=True,
                 showaxislabel=False,
                 showtick=False,
                 showticklabel=False,
                 figsize=None,
                 clearpanel=True):
        self.nh = nh
        self.nv = nv
        self.ticksize = ticksize
        self.brightnessunit = brightnessunit
        self.numeric_formatter = pl.FormatStrFormatter('%.2f')
        self.direction_label = direction_label
        self.direction_reference = direction_reference
        self.separatepanel = separatepanel
        self.spectral_label = spectral_label
        self.spectral_unit = spectral_unit
        self.showaxislabel = showaxislabel
        self.showtick = showtick
        self.showticklabel = showticklabel
        self.title = title
        self.figsize = figsize
        casalog.post('figsize={figsize}'.format(figsize=self.figsize),
                     priority='DEBUG')

        self.normalization_factor = 1

        self._axes_spmap = None

        # to resize matplotlib window to specified size
        pl.figure(self.MATPLOTLIB_FIGURE_ID)
        pl.close()

        if self.figsize is None:
            pl.figure(self.MATPLOTLIB_FIGURE_ID)
        else:
            pl.figure(self.MATPLOTLIB_FIGURE_ID, figsize=self.figsize)
        if clearpanel:
            pl.clf()
Esempio n. 10
0
def draw_speedup_fig(x, y, fig_title, filename):
	set_figure_props()
	ax = pylab.subplot(111)
	
	pylab.semilogx(x, y, linestyle=':', marker='v', basex=2)

	pylab.xticks(x)
	frm = pylab.FormatStrFormatter("%d")
	ax.xaxis.set_major_formatter(frm)

	ax.xaxis.grid(True, which="minor")
	pylab.xlabel("Query length (bp - log scale)")
	pylab.ylabel("Speedup")
	pylab.title(fig_title, fontsize=9)

	pylab.savefig(filename)
	pylab.close()
Esempio n. 11
0
    def GraphUtilGaussianFitGraphs(self, name, x, y, error, xLabel, yLabel, whichGraph):
        """Generic plotting method that plots depending on which graph is being plotted.
        :param canvas: canvas for widget
        :param fig: figure for graph
        :param name: name of tab
        :param x: x-values
        :param y: y-values
        :param error: error values for gaussian fit graphs
        :param xLabel: x-axis label
        :param yLabel: y-axis label
        :param whichGraph: char that represents either gaussian or lattice fit
        """
        mainGraph = qtWidgets.QWidget()
        fig = plab.Figure((5.0, 4.0), dpi=100)
        canvas = FigureCanvas(fig)

        canvas.setParent(mainGraph)
        axes = fig.add_subplot(111)

        axes.plot(x, y)
        print(y)
        print("Fitted Data")
        print(name)
        if whichGraph == 'G':
            axes.errorbar(x, y, yerr=error, fmt='o')
        elif whichGraph == 'L':
            axes.plot(x, y, 'go')
            axes.yaxis.set_major_formatter(plab.FormatStrFormatter('%.4f'))

        axes.set_title(name)
        axes.set_xlabel(xLabel)
        axes.set_ylabel(yLabel)
        canvas.draw()

        tab = qtWidgets.QWidget()
        tab.setStatusTip(name)
        vbox = qtWidgets.QVBoxLayout()
        graphNavigationBar = NavigationToolbar(canvas, mainGraph)
        vbox.addWidget(graphNavigationBar)
        vbox.addWidget(canvas)
        tab.setLayout(vbox)

        self.myMainWindow.savingCanvasTabs(tab, name, canvas, fig)
Esempio n. 12
0
def draw_graph(times, output):
    for sub in times.keys():
        x = times[sub].keys()
        y = [times[sub][i] for i in x]
        z = zip(x, y)
        z.sort()
        x = [tup[0] for tup in z]
        y = [tup[1] for tup in z]
        print "%s:" % sub
        print "--> x = ", x
        print "--> y = ", y
        pylab.plot(x, y, label=sub)

    intFormatter = pylab.FormatStrFormatter('%d')
    a = pylab.gca()
    a.xaxis.set_major_formatter(intFormatter)
    a.yaxis.set_major_formatter(intFormatter)
    pylab.legend(loc='best')
    pylab.draw()
    pylab.xlabel("Revision number")
    pylab.ylabel("Time (s)")
    pylab.savefig(output)
Esempio n. 13
0
        sc = ax.pcolormesh(datX, datY, masked_datMesh, cmap='jet')
        plt.colorbar(sc, label=r'$\log\sqrt{\Delta\nu_x^2+\Delta\nu_y^2}$')
        #x = fnpData[:,[0]]
        #y = fnpData[:,[1]]
        #z = fnpData[:,[4]]
        #ix = z>-99.0
        #plt.scatter(x[ix], y[ix], c=z[ix], cmap='jet', verts=(verts), s=47.0, antialiased=None, edgecolors='none')
    else:
        print("Warning: No ADTS footprint data found.")


#fig = plt.figure(figsize=(10,10),dpi=125)
fig = plt.figure(figsize=(6, 6), dpi=125)
plt.subplots_adjust(left=0.15, right=0.95, top=0.9, bottom=0.1)
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%.3f'))
ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.3f'))

plt.gca().set_autoscale_on(True)

plt.xlabel('x (m)')
plt.ylabel('y (m)')

additionalItemsToPlot(ax)  #Plot additional items specified at top of this file

#plt.xlim(-0.010,0.010)
#plt.ylim(0.0,0.010)

plt.title('Raster with Frequency Map Coloring')
#plt.show()
#plt.savefig('raster.svg')
Esempio n. 14
0
def plot_points_plus_kde(xlist, labels, markx=False, lines=3, size=9, ax=None):
    """
    Accepts a list of one-dimensional densities and plots each as points on a line
    with a KDE on top.

    Parameters:
    -------------
    xlist : list of array-like objects
            data to produce density plot for

    labels : list of legend labels; len(labels) should equal len(xlist)

    markx : bool, optional
            put tick labels at the min/max values in x?

    lines : integer, optional
            line/marker edge thickness

    size  : integer, optional
            marker size

    color : string, optional
            color for points and kde

    ax    : pylab axes object, optional
    """
    if ax is None:
        ax = pylab.axes(frameon=False)

    # cycles through colors
    cw = color_wheel(lines=('-'), symbols=('o'))

    for i in xrange(0, len(xlist)):
        # spin the color wheel
        (c, s, l) = cw.next()

        # make the point plot
        ax.plot(xlist[i],
                zeros(xlist[i].shape),
                c + s,
                markersize=size,
                mew=lines,
                alpha=0.5)

        # kde
        kde = gaussian_kde(xlist[i])
        lpoint = min(xlist[i]) - 0.025 * abs(min(xlist[i]))
        rpoint = max(xlist[i]) + 0.025 * abs(max(xlist[i]))
        support = linspace(lpoint, rpoint, 512)
        mPDF = kde(support)
        ax.plot(support, mPDF, color=c, lw=lines, label=labels[i])

    # prtty things up
    ax.get_yaxis().set_visible(False)
    ax.set_ylim(bottom=-0.1)
    if markx:
        major_formatter = pylab.FormatStrFormatter('%1.2f')
        ax.get_xaxis().set_major_formatter(major_formatter)
        ax.get_xaxis().tick_bottom()
        minx = min([min(x) for x in xlist])
        maxx = max([max(x) for x in xlist])
        ax.get_xaxis().set_ticks([minx, maxx])
    else:
        ax.get_xaxis().set_ticks([])
    # legend
    ax.legend(loc='best')

    return ax
Esempio n. 15
0
def fit_trans_combined(filter):
    # First lets fit each star in each filter seperately.
    data = PhotometryData()

    if (filter == 'H'):
        m = data.mH
        m_err = data.mH_err
        X = data.XH
        M = data.H
        M_err = data.H_err
        c = data.cHKp
        c_err = data.cHKp_err
        xpos = data.pxH
        ypos = data.pyH

    if (filter == 'Kp'):
        m = data.mKp
        m_err = data.mKp_err
        X = data.XKp
        M = data.Kp
        M_err = data.Kp_err
        c = data.cHKp
        c_err = data.cHKp_err
        xpos = data.pxKp
        ypos = data.pyKp

    if (filter == 'Lp'):
        m = data.mLp
        m_err = data.mLp_err
        X = data.XLp
        M = data.Lp
        M_err = data.Lp_err
        c = data.cKpLp
        c_err = data.cKpLp_err
        xpos = data.pxLp
        ypos = data.pyLp

    # Get rid of nan values
    idx = np.isfinite(m)
    tmp = np.where(idx == True)[0]
    print 'Found %d (out of %d) NaN values.' % (len(m) - len(tmp), len(m))

    name = data.name[idx]
    m = m[idx]
    m_err = m_err[idx]
    X = X[idx]
    M = M[idx]
    M_err = M_err[idx]
    c = c[idx]
    c_err = c_err[idx]
    xpos = xpos[idx]
    ypos = ypos[idx]

    p, p_err, res, m_pred = run_fit(m, m_err, X, M, M_err, c, c_err)

    magFormatter = py.FormatStrFormatter('%.2f')
    magLocator = py.MultipleLocator(0.02)

    ##########
    # Plot Instrumental Magnitude vs. Airmass with Residuals
    ##########
    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.grid(True)
    py.scatter(X, m, c=res, s=30)
    py.plot(X, m_pred, 'k*', ms=10)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Residuals')
    py.legend(('Predicted', 'Observed'), scatterpoints=1, loc='lower right')
    py.xlabel('Airmass')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fit_airmass_vs_m_all_%s.png' % (filter))

    ##########
    # Plot Instrumental Magnitude vs. Airmass with Order
    ##########
    order = np.arange(len(m))

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.grid(True)
    py.scatter(X, m, c=order, s=30)
    py.plot(X, m_pred, 'k*', ms=10)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Order')
    py.legend(('Predicted', 'Observed'), loc='lower right')
    py.xlabel('Airmass')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fit_airmass_vs_m_order_all_%s.png' % (filter))

    ##########
    # Plot Instrumental Magnitude vs. Order with
    # Airmass information (colors) and
    # Position information (symbol sizes).
    ##########
    iiTopLeft = np.where((xpos < 400) & (ypos > 600))[0]
    iiTopRight = np.where((xpos > 600) & (ypos > 600))[0]
    iiBotRight = np.where((xpos > 600) & (ypos < 400))[0]
    iiCenter = np.where((xpos > 400) & (xpos < 600) & (ypos > 400)
                        & (ypos < 600))[0]

    order = np.arange(len(m))

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(order[iiCenter],
                    m[iiCenter],
                    c=X[iiCenter],
                    marker='>',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    s2 = py.scatter(order[iiTopLeft],
                    m[iiTopLeft],
                    c=X[iiTopLeft],
                    marker='o',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    s3 = py.scatter(order[iiTopRight],
                    m[iiTopRight],
                    c=X[iiTopRight],
                    marker='s',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    s4 = py.scatter(order[iiBotRight],
                    m[iiBotRight],
                    c=X[iiBotRight],
                    marker='d',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    # Legend is backwards for some reason
    py.legend((s1, s2, s3, s4),
              ('Center', 'Top Left', 'Top Right', 'Bottom Right'),
              scatterpoints=1,
              loc='lower right')

    py.grid(True)
    py.xlabel('Order')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.gca().yaxis.set_major_locator(magLocator)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Airmass')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fit_order_vs_m_airmass_position_all_%s.png' % (filter))

    ##########
    # Plot Airmass vs. Residuals with Instrumental Magnitude (color)
    ##########
    # Give different stars, different symbols
    fs140 = np.where(name == 'FS140')[0]
    fs147 = np.where(name == 'FS147')[0]
    fs148 = np.where(name == 'FS148')[0]

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(X[fs140], res[fs140], c=m[fs140], s=100, marker='o')
    s2 = py.scatter(X[fs147], res[fs147], c=m[fs147], s=100, marker='^')
    s3 = py.scatter(X[fs148], res[fs148], c=m[fs148], s=100, marker='s')
    py.legend((s1, s2, s3), ('FS140', 'FS147', 'FS148'),
              scatterpoints=1,
              loc='lower right')
    py.grid(True)
    py.xlabel('Airmass')
    py.ylabel('Residuals (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Instrumental Magnitude')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fit_airmass_vs_residuals_m_all_%s.png' % (filter))

    ##########
    # Plot Residuals vs. Color
    ##########
    # Give different stars, different symbols
    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(c[fs140], res[fs140], c=X[fs140], s=100, marker='o')
    s2 = py.scatter(c[fs147], res[fs147], c=X[fs147], s=100, marker='^')
    s3 = py.scatter(c[fs148], res[fs148], c=X[fs148], s=100, marker='s')
    py.legend((s1, s2, s3), ('FS140', 'FS147', 'FS148'),
              scatterpoints=1,
              loc='lower right')
    py.grid(True)
    py.xlabel('Color')
    py.ylabel('Residuals (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Airmass')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fit_color_vs_residuals_airmass_all_%s.png' % (filter))

    ##########
    # Plot Residuals vs. Color
    ##########
    # Give different stars, different symbols
    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    dm = M - m - p[0]
    s1 = py.scatter(X[fs140], dm[fs140], c=m[fs140], s=100, marker='o')
    s2 = py.scatter(X[fs147], dm[fs147], c=m[fs147], s=100, marker='^')
    s3 = py.scatter(X[fs148], dm[fs148], c=m[fs148], s=100, marker='s')
    py.legend((s1, s2, s3), ('FS140', 'FS147', 'FS148'),
              scatterpoints=1,
              loc='lower right')
    py.grid(True)
    py.xlabel('Airmass')
    py.ylabel('M - m - ZP (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Instrumental Magnitude')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fit_airmass_vs_magdiff_m_all_%s.png' % (filter))

    return p
Esempio n. 16
0
def test_fit_trans():
    data = PhotometryData(onlyStar='FS140')

    p, p_err, res, mH_pred = run_fit(data.mH, data.mH_err, data.XH, data.H,
                                     data.H_err, data.cHKp, data.cHKp_err)

    magFormatter = py.FormatStrFormatter('%.2f')
    magLocator = py.MultipleLocator(0.02)

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.grid(True)
    py.scatter(data.XH, data.mH, c=res, s=30)
    py.plot(data.XH, mH_pred, 'k*', ms=10)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Residuals')
    py.legend(('Predicted', 'Observed'))
    py.xlabel('Airmass')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.title('FS140')
    py.savefig('plots/test_fit_airmass_vs_mH.png')
    #     py.show()

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.grid(True)
    py.scatter(data.mH, res, c=data.XH, s=data.tH * 10.0)
    py.xlabel('Instrumental Magnitude')
    py.ylabel('Residuals')
    py.gca().xaxis.set_major_formatter(magFormatter)
    py.gca().xaxis.set_major_locator(magLocator)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Airmass')
    py.title('FS140')
    py.savefig('plots/test_fit_mH_vs_residuals_airmass.png')
    #     py.show()

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.scatter(data.XH, res, c=data.mH, s=100)
    py.grid(True)
    py.xlabel('Airmass')
    py.ylabel('Residuals (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Instrumental Magnitude')
    py.title('FS140')
    py.savefig('plots/test_fit_airmass_vs_residuals_mH.png')
    #     py.show()

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    symSize = (data.XH - data.XH.min()) / (data.XH.max() - data.XH.min())
    symSize = symSize * 100.0 + 20.0
    py.scatter(data.pxH, data.pyH, c=res, s=symSize)
    py.grid(True)
    py.xlabel('X Position')
    py.ylabel('Y Position')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Residuals')
    py.title('FS140 - Size ~ Airmass')
    py.savefig('plots/test_position_mH.png')
    #     py.show()

    iiTopLeft = np.where((data.pxH < 400) & (data.pyH > 600))[0]
    iiTopRight = np.where((data.pxH > 600) & (data.pyH > 600))[0]
    iiBotRight = np.where((data.pxH > 600) & (data.pyH < 400))[0]
    iiCenter = np.where((data.pxH > 400) & (data.pxH < 600) & (data.pyH > 400)
                        & (data.pyH < 600))[0]

    order = np.arange(len(data.mH))

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(order[iiCenter],
                    data.mH[iiCenter],
                    c=data.XH[iiCenter],
                    marker='>',
                    s=100,
                    vmin=data.XH.min(),
                    vmax=data.XH.max())
    s2 = py.scatter(order[iiTopLeft],
                    data.mH[iiTopLeft],
                    c=data.XH[iiTopLeft],
                    marker='o',
                    s=100,
                    vmin=data.XH.min(),
                    vmax=data.XH.max())
    s3 = py.scatter(order[iiTopRight],
                    data.mH[iiTopRight],
                    c=data.XH[iiTopRight],
                    marker='s',
                    s=100,
                    vmin=data.XH.min(),
                    vmax=data.XH.max())
    s4 = py.scatter(order[iiBotRight],
                    data.mH[iiBotRight],
                    c=data.XH[iiBotRight],
                    marker='d',
                    s=100,
                    vmin=data.XH.min(),
                    vmax=data.XH.max())
    # Legend is backwards for some reason
    py.legend((s1, s2, s3, s4),
              ('Center', 'Top Left', 'Top Right', 'Bottom Right'),
              scatterpoints=1)

    py.grid(True)
    py.xlabel('Order')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.gca().yaxis.set_major_locator(magLocator)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Airmass')
    py.title('FS140')
    py.savefig('plots/test_fit_order_vs_mH_airmass.png')
    py.show()
Esempio n. 17
0
def plot_fitparams(file, filter, suffix):
    transTable = asciidata.open(file)

    filters = transTable[0].tonumpy()
    rms = transTable[1].tonumpy()
    zp = transTable[2].tonumpy()
    zp_err = transTable[3].tonumpy()
    k = transTable[4].tonumpy()
    k_err = transTable[5].tonumpy()

    data = PhotometryData()
    name = data.name
    if (filter == 'H'):
        m = data.mH
        m_err = data.mH_err
        X = data.XH
        M = data.H
        M_err = data.H_err
        c = data.cHKp
        c_err = data.cHKp_err
        xpos = data.pxH
        ypos = data.pyH

    if (filter == 'Kp'):
        m = data.mKp
        m_err = data.mKp_err
        X = data.XKp
        M = data.Kp
        M_err = data.Kp_err
        c = data.cHKp
        c_err = data.cHKp_err
        xpos = data.pxKp
        ypos = data.pyKp

    if (filter == 'Lp'):
        m = data.mLp
        m_err = data.mLp_err
        X = data.XLp
        M = data.Lp
        M_err = data.Lp_err
        c = data.cKpLp
        c_err = data.cKpLp_err
        xpos = data.pxLp
        ypos = data.pyLp

    # Get rid of nan values
    idx = np.isfinite(m)
    tmp = np.where(idx == True)[0]
    print 'Found %d (out of %d) NaN values.' % (len(m) - len(tmp), len(m))

    name = name[idx]
    m = m[idx]
    m_err = m_err[idx]
    X = X[idx]
    M = M[idx]
    M_err = M_err[idx]
    c = c[idx]
    c_err = c_err[idx]
    xpos = xpos[idx]
    ypos = ypos[idx]

    idx = np.where(filters == filter)[0][0]
    p = np.array([zp[idx], k[idx]])

    # Get residuals
    res, res_err = func_residuals(p, m, m_err, X, M, M_err, c, c_err)

    # Get the predicted instrumental magnitude
    m_pred, m_pre_err = func_calc_mag_obs_predicted(p, M, M_err, X, c, c_err)
    # Print out some statistics
    print 'Total |Residuals|     = ', abs(res).sum()
    print 'Average |Residuals|   = ', abs(res).mean()
    print 'Stand. Dev. Residuals = ', res.std()

    # Now we can plot stuff
    magFormatter = py.FormatStrFormatter('%.2f')
    magLocator = py.MultipleLocator(0.02)

    ##########
    # Plot Instrumental Magnitude vs. Airmass with Residuals
    ##########
    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.grid(True)
    py.scatter(X, m, c=res, s=30)
    py.plot(X, m_pred, 'k*', ms=10)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Residuals')
    py.legend(('Predicted', 'Observed'), scatterpoints=1, loc='lower right')
    py.xlabel('Airmass')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fitp_X_vs_m_all_%s_%s.png' % (filter, suffix))

    ##########
    # Plot Instrumental Magnitude vs. Airmass with Order
    ##########
    order = np.arange(len(m))

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    py.grid(True)
    py.scatter(X, m, c=order, s=30)
    py.plot(X, m_pred, 'k*', ms=10)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Order')
    py.legend(('Predicted', 'Observed'), loc='lower right')
    py.xlabel('Airmass')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fitp_X_vs_m_order_all_%s_%s.png' % (filter, suffix))

    ##########
    # Plot Instrumental Magnitude vs. Order with
    # Airmass information (colors) and
    # Position information (symbol sizes).
    ##########
    iiTopLeft = np.where((xpos < 400) & (ypos > 600))[0]
    iiTopRight = np.where((xpos > 600) & (ypos > 600))[0]
    iiBotRight = np.where((xpos > 600) & (ypos < 400))[0]
    iiCenter = np.where((xpos > 400) & (xpos < 600) & (ypos > 400)
                        & (ypos < 600))[0]

    order = np.arange(len(m))

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(order[iiCenter],
                    m[iiCenter],
                    c=X[iiCenter],
                    marker='>',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    s2 = py.scatter(order[iiTopLeft],
                    m[iiTopLeft],
                    c=X[iiTopLeft],
                    marker='o',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    s3 = py.scatter(order[iiTopRight],
                    m[iiTopRight],
                    c=X[iiTopRight],
                    marker='s',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    s4 = py.scatter(order[iiBotRight],
                    m[iiBotRight],
                    c=X[iiBotRight],
                    marker='d',
                    s=100,
                    vmin=X.min(),
                    vmax=X.max())
    # Legend is backwards for some reason
    py.legend((s1, s2, s3, s4),
              ('Center', 'Top Left', 'Top Right', 'Bottom Right'),
              scatterpoints=1,
              loc='lower right')

    py.grid(True)
    py.xlabel('Order')
    py.ylabel('Instrumental Magnitude')
    py.gca().yaxis.set_major_formatter(magFormatter)
    py.gca().yaxis.set_major_locator(magLocator)
    cbar = py.colorbar(orientation='vertical', pad=0.01, fraction=0.05)
    cbar.ax.get_yaxis().get_label().set_text('Airmass')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fitp_order_vs_m_X_pos_all_%s_%s.png' % (filter, suffix))

    ##########
    # Plot Airmass vs. Residuals with Instrumental Magnitude (color)
    ##########
    # Give different stars, different symbols
    fs140 = np.where(name == 'FS140')[0]
    fs147 = np.where(name == 'FS147')[0]
    fs148 = np.where(name == 'FS148')[0]

    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(X[fs140], res[fs140], c=m[fs140], s=100, marker='o')
    s2 = py.scatter(X[fs147], res[fs147], c=m[fs147], s=100, marker='^')
    s3 = py.scatter(X[fs148], res[fs148], c=m[fs148], s=100, marker='s')
    py.legend((s1, s2, s3), ('FS140', 'FS147', 'FS148'),
              scatterpoints=1,
              loc='lower right')
    py.grid(True)
    py.xlabel('Airmass')
    py.ylabel('Residuals (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Instrumental Magnitude')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fitp_X_vs_res_m_all_%s_%s.png' % (filter, suffix))

    ##########
    # Plot Residuals vs. Color
    ##########
    # Give different stars, different symbols
    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    s1 = py.scatter(c[fs140], res[fs140], c=X[fs140], s=100, marker='o')
    s2 = py.scatter(c[fs147], res[fs147], c=X[fs147], s=100, marker='^')
    s3 = py.scatter(c[fs148], res[fs148], c=X[fs148], s=100, marker='s')
    py.legend((s1, s2, s3), ('FS140', 'FS147', 'FS148'),
              scatterpoints=1,
              loc='lower right')
    py.grid(True)
    py.xlabel('Color')
    py.ylabel('Residuals (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Airmass')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fitp_C_vs_res_X_all_%s_%s.png' % (filter, suffix))

    ##########
    # Plot Residuals vs. Color
    ##########
    # Give different stars, different symbols
    py.figure(2, figsize=(8, 6))
    py.clf()
    py.subplots_adjust(left=0.15, right=0.88)
    dm = M - m - p[0]
    s1 = py.scatter(X[fs140], dm[fs140], c=m[fs140], s=100, marker='o')
    s2 = py.scatter(X[fs147], dm[fs147], c=m[fs147], s=100, marker='^')
    s3 = py.scatter(X[fs148], dm[fs148], c=m[fs148], s=100, marker='s')
    py.legend((s1, s2, s3), ('FS140', 'FS147', 'FS148'),
              scatterpoints=1,
              loc='lower right')
    py.grid(True)
    py.xlabel('Airmass')
    py.ylabel('M - m - ZP (mag)')
    cbar = py.colorbar(orientation='vertical',
                       pad=0.01,
                       fraction=0.05,
                       format='%.3f')
    cbar.ax.get_yaxis().get_label().set_text('Instrumental Magnitude')
    py.title('All Stars, %s-band' % (filter))
    py.savefig('plots/fitp_X_vs_magdiff_m_all_%s_%s.png' % (filter, suffix))
  if fname == 'pairwise_integrated_inverse_distance': featureContainer.getContainer()[-1].cutoffDistance = 100.0

# Optimization options
valid_methods = ['ASLAM-RProp+','ASLAM-RProp-','ASLAM-iRProp-','ASLAM-iRProp+','ASLAM-BFGS', 'Nelder-Mead','Powell','CG','BFGS','Newton-CG','L-BFGS-B','TNC','COBYLA','SLSQP']
options = {'disp': True, 'maxiter': 500, 'xtol': 1e-6, 'ftol': 1e-3, 'gtol': 1e-3}
res = {}

# Setup plot
colors,_,markers = pplot.generateUniqueLinestyles(len(valid_methods), colormap='brg')
fig = pl.figure(figsize=(20,12))
fig.canvas.set_window_title('optimizer_comparison')
ax = fig.add_subplot(111)
ax.grid('on')
ax.set_yscale('log')
ax.tick_params(axis='y', which='both')
ax.yaxis.set_major_formatter(pl.FormatStrFormatter("%.1f"))
ax.yaxis.set_minor_formatter(pl.FormatStrFormatter("%.1f"))
ax.set_xlabel('number of gradient evaluations')
ax.set_ylabel('objective fcn')
pl.show(block=False)
callback = lambda x: popt.plot_convergence_callback(sceneOpt, lgrad, abscissa_type=ax.get_xlabel(), ordinate_type=ax.get_ylabel())

# Optimize
for cnt,method in enumerate(valid_methods):
  
  sm.logInfo("Runnig optimization with method {0}".format(method))
  lgrad, = ax.plot([],[], color=colors[cnt], marker=markers[cnt], linestyle='-', label='{0}'.format(method))
  sceneOpt = popt.SceneOptimizable(scene, featureContainer)
  
  res[method] = popt.optimize(sceneOpt, method=method, options=options, callback=callback)
  ax.legend(loc = 'upper right', numpoints = 1, fancybox = True, framealpha = 0.5)
Esempio n. 19
0
 def plot(self):
     pylab.close()
     pylab.plot(self.wave, self.current)
     pylab.show()
     self.axes = pylab.gca()
     self.axes.fmt_xdata = pylab.FormatStrFormatter("%4.2f")
Esempio n. 20
0
def mixing(flmlname):

    print("\n********** Calculating the mixing diagnostics\n")
    # warn user about assumptions
    print(
        "Background potential energy calculations makes two assumptions: \n i) domain height = 0.1m \n ii) initial temperature difference is 1.0 degC"
    )
    domainheight = 0.1
    rho_zero, T_zero, alpha, g = le_tools.Getconstantsfromflml(flmlname)

    # get mixing bin bounds and remove lower bound (=-\infty)
    bounds = le_tools.Getmixingbinboundsfromflml(flmlname)[1:]

    # find indicies of selected bounds for plotting
    index_plot = []
    for b in [-0.5, -0.25, 0.0, 0.25, 0.5]:
        index_plot.append(
            numpy.where(numpy.array([abs(val - b)
                                     for val in bounds]) < 1E-6)[0])

    time = []
    volume_fraction = []
    reference_state = []
    bpe = []

    # get stat files
    # time_index_end used to ensure don't repeat values
    stat_files, time_index_end = le_tools.GetstatFiles('./')
    for i in range(len(stat_files)):
        stat = stat_parser(stat_files[i])
        for j in range(time_index_end[i]):
            time.append(stat['ElapsedTime']['value'][j])
            bins = stat['fluid']['Temperature']['mixing_bins%cv_normalised'][:,
                                                                             j]
            # rearrange bins so have nobins = nobounds -1
            # amounts to including any undershoot or overshoots in lower/upper most bin
            # for discussion of impacts see H. Hiester, PhD thesis (2011), chapter 4.
            bins[1] = bins[0] + bins[1]
            bins[-2] = bins[-2] + bins[-1]
            bins = bins[1:-1]

            # sum up bins for plot
            volume_fraction.append(
                tuple([
                    sum(bins[index_plot[k]:index_plot[k + 1]])
                    for k in range(len(index_plot) - 1)
                ]))

            # get reference state using method of Tseng and Ferziger 2001
            Abins = sum([
                bins[k] * (bounds[k + 1] - bounds[k]) for k in range(len(bins))
            ])
            pdf = [val / Abins for val in bins]
            rs = [0]
            for k in range(len(pdf)):
                rs.append(rs[-1] + (domainheight * pdf[k] *
                                    (bounds[k + 1] - bounds[k])))
            reference_state.append(tuple(rs))

            # get background potential energy,
            # noting \rho = \rho_zero(1-\alpha(T-T_zero))
            # and reference state is based on temperature
            # bpe_bckgd = 0.5*(g*rho_zero*(1.0+(alpha*T_zero)))*(domainheight**2)
            # but don't include this as will look at difference over time
            bpe.append(-rho_zero * alpha * g * scipy.integrate.trapz(
                x=reference_state[-1],
                y=[
                    bounds[j] * reference_state[-1][j]
                    for j in range(len(reference_state[-1]))
                ]))

    volume_fraction = numpy.array(volume_fraction)
    reference_state = numpy.array(reference_state)

    bpe_zero = bpe[0]
    bpe = [val - bpe_zero for val in bpe]

    # plot
    fs = 18
    pylab.figure(num=2, figsize=(16.5, 11.5))
    pylab.suptitle('Mixing', fontsize=fs)

    # volume fraction
    pylab.subplot(221)
    pylab.plot(time, volume_fraction[:, 0], label='$T < -0.25$', color='k')
    pylab.plot(time,
               volume_fraction[:, 1],
               label='$-0.25 < T < 0.0$',
               color='g')
    pylab.plot(time,
               volume_fraction[:, 2],
               label='$0.0 < T < 0.25$',
               color='b')
    pylab.plot(time, volume_fraction[:, 3], label='$0.25 < T$', color='0.5')

    pylab.axis([0, time[-1], 0, 0.5])
    pylab.legend(loc=0)
    pylab.grid('on')
    pylab.xlabel('$t$ (s)', fontsize=fs)
    pylab.ylabel('$V/|\\Omega|$', fontsize=fs)
    pylab.title('Volume fraction', fontsize=fs)

    # reference state contours
    pylab.subplot(222)
    for i in index_plot:
        pylab.plot(time, reference_state[:, i], color='k')
    pylab.text(
        time[-1] / 100,
        1.5E-3,
        'From bottom to top contours correspond to values \n $T = -0.5, \, -0.25, \, 0.0, \, 0.25, \, 0.5$ \nwhere the values for $T=-0.5$ and $0.5$ take the values\n$z_* = 0.0$ and $0.1$ respectively',
        bbox=dict(facecolor='white', edgecolor='black'))
    pylab.axis([0, time[-1], 0, domainheight])
    pylab.grid('on')
    pylab.xlabel('$t$ (s)', fontsize=fs)
    pylab.ylabel('$z_*$ (m)', fontsize=fs)
    pylab.title('Reference state', fontsize=fs)

    pylab.subplot(223)
    pylab.plot(bounds, reference_state[-1], color='k')
    pylab.grid('on')
    pylab.axis([-0.5, 0.5, 0, domainheight])
    pylab.xlabel('$T$ ($^\\circ$C)', fontsize=fs)
    pylab.ylabel('$z_*$ (m)', fontsize=fs)
    pylab.title('Reference state at $t=' + str(time[-1]) + '\\,$s',
                fontsize=fs)

    pylab.subplot(224)
    pylab.plot(time, bpe, color='k')
    pylab.grid('on')
    pylab.gca().get_xaxis().get_axes().set_xlim(0.0, time[-1])
    pylab.xlabel('$t$ (s)', fontsize=fs)
    pylab.ylabel('$\\Delta E_b$', fontsize=fs - 2)
    pylab.gca().get_yaxis().set_major_formatter(
        pylab.FormatStrFormatter('%1.1e'))
    pylab.title('Background potential energy', fontsize=fs)

    pylab.savefig('diagnostics/plots/mixing.png')
    return
Esempio n. 21
0
def compareDARstar(pwDARfixOn, pwDARfixOff, src, outdir='./'):
    """
    Pass in either the filename to a pickle file containing a
    Pairwise object or pass in the Pairwise object itself for both
    a DAR corrected and uncorrected data set. This way we can plot up
    both and compare them. Also plot the model DAR correction which
    is the average separation of the pre-DAR + model-DAR values
    for all frames with strehl > 0.30.
    """
    # Rename variables for brevity
    if (type(pwDARfixOn) == type('')):
        pw1 = pickle.load(open(pwDARfixOn))
    else:
        pw1 = pwDARfixOn

    if (type(pwDARfixOff) == type('')):
        pw2 = pickle.load(open(pwDARfixOff))
    else:
        pw2 = pwDARfixOff
        
    ndx1 = pw1.names.index(src)
    ndx2 = pw2.names.index(src)

    idx1 = np.where(pw1.hasData[ndx1] == 1)[0]
    idx2 = np.where(pw2.hasData[ndx2] == 1)[0]

    # Calculate predicted change in separation due to DAR for this star
    parang1 = pw1.parang[idx1]
    parang2 = pw2.parang[idx2]

    strehl1 = pw1.strehl[idx1]
    strehl2 = pw2.strehl[idx2]

    scale = 0.00996
    dzObs1 = pw1.posz[ndx1,idx1] / scale
    dhObs1 = pw1.posh[ndx1,idx1] / scale
    dR1 = pw1.dar[ndx1,idx1] / scale

    dzObs2 = pw2.posz[ndx2,idx2] / scale
    dhObs2 = pw2.posh[ndx2,idx2] / scale
    dR2 = pw2.dar[ndx2,idx2] / scale

    sepObs1 = np.hypot(dzObs1, dhObs1)
    sepObs2 = np.hypot(dzObs2, dhObs2)

    sepTrue1 = np.hypot(dzObs1, dhObs1)
    sepTrue2 = np.hypot(dzObs2 + dR2, dhObs2)

    # Figure out the highest strehl data
    sdx = np.where(strehl2 > 0.30)[0]
    sepTrueAvg = sepTrue2[sdx].mean()

    py.clf()
    py.subplots_adjust(left=0.15)
    # tick formatting
    yformatter = py.FormatStrFormatter('%5.1f')
    ax = py.gca()
    ax.yaxis.set_major_formatter(yformatter)

    # Plot pre-DAR corrected
    py.plot(parang2, sepObs2, 'r.')

    # Plot model DAR corrected
    rng = py.axis()
    py.plot([rng[0], rng[1]], [sepTrueAvg, sepTrueAvg], 'k-')

    # Plot post-DAR corrected
    py.plot(parang1, sepObs1, 'k.')

    py.title(src)
    py.xlabel('Parallactic Angle (deg)')
    py.ylabel('Distance from %s (pixels)' % (pw1.refSrc))
    py.legend(('Pre-DAR', 'Model DAR',
               'Post-DAR'), numpoints=3)

    py.savefig(outdir + 'plots/compare_dar_%s.eps' % src)
    py.savefig(outdir + 'plots/compare_dar_%s.png' % src)
Esempio n. 22
0
def get_response(image, model, regions):
    model = numpy.loadtxt(model)
    mwave = model[:, 0]
    mspec = model[:, 1]

    model = interpolate.splrep(mwave, mspec, k=3, s=0)

    hdu = pyfits.open(image)
    if len(hdu) == 4:
        spec = hdu[1].data.copy()
        wave = st.wavelength(image, 1)
    else:
        spec = hdu[0].data.copy()
        wave = st.wavelength(image)

    outmodel = interpolate.splev(wave, model)

    ratio = outmodel / spec

    badregions = []
    cond = ~numpy.isnan(ratio)
    cond = cond & (~numpy.isinf(ratio))
    for lo, hi in regions:
        badregions.append([lo, hi])
        cond = cond & (~((wave > lo) & (wave < hi)))
    scurrent = 2. * wave[cond].size**0.5
    smod = ratio[cond].mean()**2
    spmodel = interpolate.splrep(wave[cond],
                                 ratio[cond],
                                 k=3,
                                 s=scurrent * smod)
    resp = None
    while resp != 'q' and resp != 'Q':
        import pylab
        current = interpolate.splev(wave, spmodel)
        pylab.plot(wave, current)
        pylab.plot(wave, ratio)
        pylab.gca().fmt_xdata = pylab.FormatStrFormatter('%7.2f')
        pylab.show()
        resp = raw_input("Enter command (q, m, s, w, h): ")
        if resp == 'm':
            region = raw_input("Enter region to mask (eg, 6530,6580): ").split(
                ',')
            while len(region) != 2:
                region = raw_input(
                    "Please input wavelengths joined by a comma: ").split(',')
            lo, hi = float(region[0]), float(region[1])
            badregions.append([lo, hi])
            cond = cond & (~((wave > lo) & (wave < hi)))
            spmodel = interpolate.splrep(wave[cond],
                                         ratio[cond],
                                         k=3,
                                         s=scurrent * smod)
        elif resp == 's':
            scurrent = float(
                raw_input(
                    "Current smoothing factor is %4.2f, enter new smoothing factor: "
                    % scurrent))
            spmodel = interpolate.splrep(wave[cond],
                                         ratio[cond],
                                         k=3,
                                         s=scurrent * smod)
        elif resp == 'h':
            print "Use q to quit, m to mask, s to set smoothing scale, w to write model to disk"
        elif resp == 'w':
            import cPickle
            outname = raw_input("Name of file to write to: ")
            f = open(outname, 'wb')
            cPickle.dump(spmodel, f)
            f.close()

    print "Regions masked:", badregions
    return spmodel
Esempio n. 23
0
def main():
    "see __doc__"
    args = sys.argv[1:]
    fields = []
    xtime = True
    xfmt = None
    sep = ","
    title = ""
    right_label = ""
    left_label = ""
    x_label = ""
    plot_file = ""
    dims = (8, 6)
    bkgds = []
    x_min_max = []
    y_min_max = []
    do_legend = True
    backend = None
    use_xkcd = False
    verbose = False
    opts, args = getopt.getopt(args, "B:F:LT:X:Y:b:d:f:hl:p:r:s:vx:", [
        "backend=",
        "format=",
        "skip_legend",
        "title=",
        "xkcd",
        "x_range=",
        "y_range=",
        "background=",
        "dimension=",
        "field=",
        "help",
        "left_label=",
        "plot_file=",
        "right_label=",
        "separator=",
        "verbose=",
        "x_label",
    ])
    for opt, arg in opts:
        if opt in ("-B", "--backend"):
            backend = arg
        elif opt in ("-f", "--field"):
            if "'" in arg:
                quotechar = "'"
            else:
                quotechar = '"'
            plarg = io.StringIO(arg)
            plarg = next(csv.reader(plarg, quotechar=quotechar))
            if len(plarg) == 2:
                # plot using left y axis by default
                plarg.append("l")
            if len(plarg) == 3:
                # plot using blue by default
                plarg.append("b")
            if len(plarg) == 4:
                # use the Y column name as the default legend name.
                plarg.append(plarg[1])
            if len(plarg) == 5:
                # plot with '-' line style by default
                plarg.append("-")
            if len(plarg) == 6:
                # no marker by default
                plarg.append("")
            try:
                fields.append([int(x.strip())
                               for x in plarg[0:2]] + [plarg[2][0].lower()] +
                              [plarg[3].lower()] + plarg[4:])
                reader = csv.reader
            except ValueError:
                # Assume first two fields name column headers.
                fields.append(plarg[0:2] + [plarg[2][0].lower()] +
                              [plarg[3].lower()] + plarg[4:])
                reader = csv.DictReader

        elif opt in ("-b", "--background"):
            bg_spec = arg.split(",")
            try:
                bg_spec[0] = int(bg_spec[0])
                bg_spec[1] = int(bg_spec[1])
                reader = csv.reader
            except ValueError:
                bg_spec[0] = bg_spec[0].strip()
                bg_spec[1] = bg_spec[1].strip()
                reader = csv.DictReader
            if ":" in bg_spec[2]:
                low, high = [float(x) for x in bg_spec[2].split(":")]
            else:
                low = high = float(bg_spec[2])
            bkgds.append((bg_spec[0], bg_spec[1], low, high, bg_spec[3]))
        elif opt in ("-F", "--format"):
            xtime = "%H" in arg or "%M" in arg or "%m" in arg or "%d" in arg
            xfmt = arg
        elif opt in ("-d", "--dimension"):
            dims = tuple([float(v.strip()) for v in re.split("[x,]", arg)])
        elif opt in ("-L", "--skip_legend"):
            do_legend = False
        elif opt in ("-p", "--plot_file"):
            plot_file = arg
        elif opt in ("-l", "--left_label"):
            left_label = arg
        elif opt in ("-r", "--right_label"):
            right_label = arg
        elif opt in ("-x", "--x_label"):
            x_label = arg
        elif opt == "--xkcd":
            use_xkcd = True
        elif opt in ("-v", "--verbose"):
            verbose = True
        elif opt in ("-Y", "--y_range"):
            if "," in arg:
                left, right = arg.split(",")
                y_min_max = [[float(x) for x in left.split(":")],
                             [float(x) for x in right.split(":")]]
            else:
                y_min_max = [[float(x) for x in arg.split(":")]]
        elif opt in ("-X", "--x_range"):
            # First try splitting at colon (assuming a pair of floats). If
            # that produces too many values, try a comma (assuming
            # timestamps).
            if len(arg.split(":")) == 2:
                x_min_max = [[float(x) for x in arg.split(":")]]
            else:
                min_dt, max_dt = arg.split(",")
                x_min = dateutil.parser.parse(min_dt)
                try:
                    x_max = dateutil.parser.parse(max_dt)
                except dateutil.parser.ParserError:
                    if max_dt == "today":
                        x_max = datetime.datetime.now()
                    elif max_dt == "yesterday":
                        x_max = datetime.datetime.now() - datetime.timedelta(
                            days=1)
                    else:
                        raise
                x_min_max = [x_min, x_max]
        elif opt in ("-s", "--separator"):
            sep = arg
        elif opt in ("-T", "--title"):
            title = arg
        elif opt in ("-h", "--help"):
            usage()
            raise SystemExit

    if backend is None:
        if not os.environ.get("DISPLAY"):
            # Allow non-interactive use (e.g. running with -p from cron)
            matplotlib.use("Agg")
    else:
        matplotlib.use(backend)

    if verbose:
        print("Using", matplotlib.get_backend(), file=sys.stderr)

    if use_xkcd:
        from matplotlib import pyplot
        try:
            pyplot.xkcd()
        except AttributeError:
            print("XKCD style not available.", file=sys.stderr)
        else:
            if verbose:
                print("Using XKCD style.", file=sys.stderr)

    if not fields:
        fields = [(0, 2, "l", "b", "2", "-", "")]
        reader = csv.reader

    min_y = 1e99
    max_y = -1e99
    if xtime:
        min_x = datetime.datetime(9999, 12, 31, 23, 59, 59)
        max_x = datetime.datetime(1970, 1, 1, 0, 0, 0)

        def parse_x(x_val):
            try:
                return dateutil.parser.parse(x_val)
            except ValueError:
                print(f"Can't parse {x_val!r} as a timestamp.",
                      file=sys.stderr)
                raise

        def fmt_date(tick_val, _=None, xfmt=xfmt):
            date = matplotlib.dates.num2date(tick_val)
            if xfmt is None:
                # Calculate X format dynamically based on the visible
                # range.
                left, right = [
                    matplotlib.dates.num2date(x) for x in pylab.xlim()
                ]
                x_delta = right - left
                if x_delta > int(5 * 365) * ONE_DAY:
                    xfmt = "%Y"
                elif x_delta > int(2 * 365) * ONE_DAY:
                    xfmt = "%Y-%m"
                elif x_delta > int(1.5 * 365) * ONE_DAY:
                    xfmt = "%Y-%m-%d"
                elif x_delta > 2 * ONE_DAY:
                    xfmt = "%m/%d\n%H:%M"
                elif x_delta < 10 * ONE_MINUTE:
                    xfmt = "%H:%M\n%S.%f"
                elif x_delta < 2 * ONE_HOUR:
                    xfmt = "%H:%M:%S"
                else:
                    xfmt = "%H:%M"
            return date.strftime(xfmt)

        formatter = matplotlib.ticker.FuncFormatter(fmt_date)
    else:
        min_x = 1e99
        max_x = -1e99

        def parse_x(x_val):
            return float(x_val)

        def fmt_float(x_val, _=None):
            return xfmt % x_val

        formatter = matplotlib.ticker.FuncFormatter(fmt_float)

    if reader == csv.DictReader:
        fieldnames = next(csv.reader(sys.stdin, delimiter=sep))
        rdr = reader(sys.stdin, fieldnames=fieldnames, delimiter=sep)
    else:
        rdr = reader(sys.stdin, delimiter=sep)

    raw = list(rdr)
    left = []
    right = []
    lt_y_range = [min_y, max_y]
    rt_y_range = [min_y, max_y]
    x_range = [min_x, max_x]
    for (col1, col2, side, color, legend, style, marker) in fields:
        if "/" in style:
            style, width = style.split("/", 1)
            width = float(width)
        else:
            width = 1.0
        if "/" in marker:
            marker, m_scale = marker.split("/", 1)
            m_scale = float(m_scale)
        else:
            m_scale = 1.0
        if marker == ";":
            marker = ","
        data = ([], color, legend, (style, width), (marker, m_scale))
        if side == "l":
            left.append(data)
            y_range = lt_y_range
        else:
            right.append(data)
            y_range = rt_y_range
        for values in raw:
            try:
                _, _ = (values[col1], values[col2])
            except IndexError:
                # Rows don't need to be completely filled.
                continue
            x_val = values[col1]
            y_val = values[col2]
            if x_val and y_val:
                try:
                    x_val = parse_x(x_val)
                except ValueError as err:
                    print(err, values, file=sys.stderr)
                    raise
                y_val = float(values[col2])
                # If we get inputs with timezone info, convert. This
                # is likely only to be executed once, as if one
                # timestamp has tzinfo, all are likely to.
                if xtime and x_range[0].tzinfo != x_val.tzinfo:
                    zone = x_val.tzinfo
                    x_range = [dt.replace(tzinfo=zone) for dt in x_range]
                y_range[:] = [min(y_range[0], y_val), max(y_range[1], y_val)]
                data[0].append((x_val, y_val))
        if data[0]:
            x_range = [
                min([x for (x, _y) in data[0]] + [x_range[0]]),
                max([x for (x, _y) in data[0]] + [x_range[1]])
            ]
        else:
            print("No data for x range!", file=sys.stderr)
    if (sum([len(x) for x in left]) == 0
            and sum([len(x) for x in right]) == 0):
        print("No points to plot!", file=sys.stderr)
        return 1

    figure = pylab.figure(figsize=dims)
    if xtime:
        figure.autofmt_xdate()

    left_plot = figure.add_subplot(111)
    left_plot.set_title(title)
    left_plot.set_axisbelow(True)
    left_plot.yaxis.set_major_formatter(pylab.FormatStrFormatter('%g'))
    left_plot.xaxis.set_major_formatter(formatter)
    # Use a light, but solid, grid for the X axis and the left Y
    # axis. No grid for right Y axis.
    left_plot.xaxis.grid(True,
                         linestyle='solid',
                         which='major',
                         color='lightgrey',
                         alpha=0.5)
    left_plot.yaxis.grid(True,
                         linestyle='solid',
                         which='major',
                         color='lightgrey',
                         alpha=0.5)

    lines = []
    if left:
        if left_label:
            left_plot.set_ylabel(left_label, color=left[0][1])
        if x_label:
            left_plot.set_xlabel(x_label, color=left[0][1])
        for data in left:
            points, color, legend, style, marker = data
            lines.extend(
                left_plot.plot([x for x, y in points], [y for x, y in points],
                               color=color,
                               linestyle=style[0],
                               linewidth=style[1],
                               label=legend,
                               marker=marker[0],
                               markersize=marker[1]))
        for tick_label in left_plot.get_yticklabels():
            tick_label.set_color(left[0][1])

        extra = 0.02 * (lt_y_range[1] - lt_y_range[0])
        lt_y_range = [lt_y_range[0] - extra, lt_y_range[1] + extra]
        if y_min_max:
            left_plot.set_ylim(y_min_max[0])
        else:
            left_plot.set_ylim(lt_y_range)

    if right:
        right_plot = left_plot.twinx()
        right_plot.set_axisbelow(True)
        right_plot.yaxis.set_major_formatter(pylab.FormatStrFormatter('%g'))
        right_plot.xaxis.set_major_formatter(formatter)
        if right_label:
            right_plot.set_ylabel(right_label, color=right[0][1])
        if x_label and not left:
            right_plot.set_xlabel(x_label, color=left[0][1])

        for data in right:
            points, color, legend, style, marker = data
            lines.extend(
                right_plot.plot([x for x, y in points], [y for x, y in points],
                                color=color,
                                linestyle=style[0],
                                linewidth=style[1],
                                label=legend,
                                marker=marker[0],
                                markersize=marker[1]))
        for tick_label in right_plot.get_yticklabels():
            tick_label.set_color(right[0][1])

        extra = 0.02 * (rt_y_range[1] - rt_y_range[0])
        rt_y_range = [rt_y_range[0] - extra, rt_y_range[1] + extra]
        if len(y_min_max) == 2:
            right_plot.set_ylim(y_min_max[1])
        else:
            right_plot.set_ylim(rt_y_range)

    color_bkgd(bkgds, left and left_plot or right_plot, left and lt_y_range
               or rt_y_range, raw, parse_x)

    if x_min_max:
        left_plot.set_xlim(x_min_max[0])
    else:
        extra = (x_range[1] - x_range[0]) * 2 // 100
        try:
            x_range = [x_range[0] - extra, x_range[1] + extra]
        except OverflowError:
            print("overflow:", x_range, extra, file=sys.stderr)
            raise
        left_plot.set_xlim(x_range)

    if do_legend:
        labels = [line.get_label() for line in lines]
        if right:
            right_plot.legend(lines, labels, loc='best').set_draggable(True)
        else:
            left_plot.legend(lines, labels, loc='best').set_draggable(True)

    figure.tight_layout()
    if plot_file:
        pylab.savefig(plot_file)
    else:
        pylab.show()

    return 0
Esempio n. 24
0
               adts_fnpData[:, 3],
               c='green',
               label=r'ADTS along $\pm$x')
    #pylab.plot(adts_fnpData[-1,2],adts_fnpData[-1,3],'o',c='green')
    #pylab.plot(cross_adts_fnpData[:,2],cross_adts_fnpData[:,3])


#--------------------------------------------
#Plot horizontal data, then plot vertical data
#--------------------------------------------

#fig = pylab.figure(figsize=(10,10),dpi=125)
fig = pylab.figure(figsize=(6, 6), dpi=125)
pylab.subplots_adjust(left=0.15, right=0.95, top=0.9, bottom=0.1)
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(pylab.FormatStrFormatter('%.2f'))
ax.xaxis.set_major_formatter(pylab.FormatStrFormatter('%.2f'))

pylab.gca().set_autoscale_on(False)

#pylab.xlabel(r'Q$_\mathrm{x}$')
#pylab.ylabel(r'Q$_\mathrm{y}$')
pylab.xlabel(r'$\mathregular{Q_x}$')
pylab.ylabel(r'$\mathregular{Q_y}$')

sloppymidQx = fnpData[int(len(fnpData[:, 1]) / 2), 1]
sloppymidQy = fnpData[int(len(fnpData[:, 1]) / 2), 2]
(Qxmin, Qxmax, Qymin,
 Qymax) = analytic_tune_plane.make_min_max(sloppymidQx, sloppymidQy)
# CANDLE
#Qxmin = 24.45
Esempio n. 25
0
    def __init__(self, file):
        f = pyfits.open(file)
        self.filename = file
        """
        Test to see if data are in MWA format (ie ext0=meta, ext1=sci,
          ext2=smooth, ext3=var). If not, set smooth and variance data
          to science data.
        """
        self.ismwa = True
        try:
            self.position = f[0].header['center']
        except:
            self.ismwa = False
        if self.ismwa:
            self.pos = self.position
            self.width = f[0].header['width']
            self.rawdata = f[1].data.astype(scipy.float64)
            self.current = f[2].data.astype(scipy.float64)
            self.varspec = f[3].data.astype(scipy.float64)
            f.close()
            self.wave = wavelength(file, 1)
        else:
            self.rawdata = f[0].data.astype(scipy.float64)
            self.current = f[0].data.astype(scipy.float64)
            self.varspec = f[0].data.astype(scipy.float64)
            f.close()
            self.wave = wavelength(file)

            self.rawdata = self.rawdata.reshape(self.rawdata.size)
            self.current = self.current.reshape(self.current.size)
            self.varspec = self.varspec.reshape(self.varspec.size)
        """
        Trim bad edges.
        """
        tmp = scipy.where((self.rawdata != 0) & ~scipy.isnan(self.rawdata))[0]
        left = tmp.min()
        right = tmp.max() + 1
        self.current = self.current[left:right]
        self.varspec = self.varspec[left:right]
        self.wave = self.wave[left:right]
        self.rawdata = self.rawdata[left:right]
        """
        Linelist for galaxies.
        """
        self.linelist = [
            2344, 2374, 2383, 2587, 2599.4, 2750.3, 2795., 2802.7, 2852,
            3726.03, 3728.82, 3835.38, 3889.05, 3933.66, 3968.47, 4101.74,
            4305., 4340.47, 4861.33, 4962., 5007., 5177., 5270., 5328., 5341.,
            5371.5, 5891.9, 6562.8, 6583.5, 6716.4, 6730.8, 8498., 8542., 8662.
        ]
        self.linename = [
            'Fe', '', 'Fe', 'Fe', '', 'FeII', '', 'MgII', 'MgI', "[OII]", "",
            'Heta', '', 'CaK', 'CaH', 'H-delta', 'Gband', 'H-gamma', 'H-beta',
            'OIII', 'OIII', 'Mgb', 'Fe', 'Fe', '', 'Fe', 'NaII', 'H-alpha',
            'N', 'S', '', 'CaT', 'CaT', 'CaT'
        ]
        """
        Linelist for high-z quasars.
        """
        self.qso = False
        self.qsolist = [
            1215.24, 1239.4, 1305.53, 1335.52, 1397.61, 1399.8, 1545.86,
            1637.85, 1665.85, 1857.4, 1908.27, 2326.0, 2439.5, 2800.32
        ]
        self.qsoname = [
            'Lya', 'Nv', 'Oi', 'Cii', 'SiIV', 'Oiv', 'Civ', 'HeII', 'Oiii',
            'AlIII', 'Ciii', 'Cii', 'NeIV', 'MgII'
        ]

        self.collect = []  # Stores ID'd lines

        self.skyid = None
        self.snid = None

        self.z = 0.

        self.axes = None
        self.redraw()
        self.axes.fmt_xdata = pylab.FormatStrFormatter("%4.2f")
def linkAnnotationFinders(afs):
    for i in range(len(afs)):
        allButSelfAfs = afs[:i] + afs[i + 1:]
        afs[i].links.extend(allButSelfAfs)


#--------------------------------------------
#Plot horizontal data, then plot vertical data
#--------------------------------------------

fig = pylab.figure(figsize=(32, 14.22), dpi=75)
pylab.subplots_adjust(left=0.05, right=1.00, top=0.9, bottom=0.1)

#make Qx-Qy plot
ax_QxQy = fig.add_subplot(121)
ax_QxQy.yaxis.set_major_formatter(pylab.FormatStrFormatter('%.3f'))

Annotes = numpy.chararray(len(Qx), itemsize=8)
for i in range(len(Qx)):
    Annotes[i] = str(i)

pylab.scatter(Qx,
              Qy,
              marker='o',
              c=metric,
              s=10,
              edgecolors='none',
              cmap='jet')
af1 = AnnoteFinder(Qx, Qy, Annotes, xtol=0.0005, ytol=0.0005, axis=ax_QxQy)
pylab.connect('button_press_event', af1)
pylab.xlabel('Qx')
Esempio n. 27
0
def plot(opts):
    """ Plot data """

    print "Generating plots"

    nbeams = opts.nbeams
    nchans = opts.nchans

    f = open(args[0], 'rb')
    data = f.read()
    data = np.array(struct.unpack('f' * (len(data) / 4), data), dtype=float)
    nsamp = len(data) / (nbeams * nchans)
    data = np.reshape(data, (nsamp, nchans, nbeams))

    time = np.arange(0, opts.tsamp * data.shape[0], opts.tsamp)
    frequency = (np.arange(opts.fch1 * 1e6, opts.fch1 * 1e6 + opts.foff *
                           (data.shape[1]), opts.foff)) * 1e-6
    formatter = pylab.FormatStrFormatter('%2.3f')

    # Process only one beam
    if opts.beam != -1:

        fig = plt.figure(figsize=(8, 8))

        ax = fig.add_subplot(1, 2, 1)
        ax.set_title("Beam %d" % opts.beam)
        ax.imshow(np.log10(data[:, :, opts.beam]),
                  aspect='auto',
                  origin='lower',
                  extent=[frequency[0], frequency[-1], 0, time[-1]])
        ax.xaxis.set_major_formatter(formatter)
        ax.set_xlabel("Channel (kHz)")
        ax.set_ylabel("Time (s)")

        ax = fig.add_subplot(2, 2, 2)
        toplot = np.log10(np.sum(data[:, :, opts.beam], axis=0))
        ax.plot(frequency[:len(toplot)], toplot)
        ax.xaxis.set_major_formatter(formatter)
        ax.set_xlabel("Channel (MHz)")
        ax.set_ylabel("Log Power (Arbitrary)")
        ax.set_xlim((frequency[0], frequency[-1]))

        ax = fig.add_subplot(2, 2, 4)
        toplot = np.sum(data[:, :, opts.beam] / nchans, axis=1)
        ax.plot(time[:len(toplot)], toplot)
        ax.xaxis.set_major_formatter(pylab.FormatStrFormatter('%2.1f'))
        ax.set_xlabel("Time (s)")
        ax.set_ylabel("Power (Arbitrary)")
        ax.set_xlim((time[0], time[-1]))

        fig.tight_layout()
        plt.show()
        f.close()

        return

    # Plot each beam separately
    fig = plt.figure(figsize=(8, 8))
    num_rows = math.ceil(math.sqrt(nbeams))
    for i in range(nbeams):

        ax = fig.add_subplot(num_rows, num_rows, i + 1)
        ax.set_title("Beam %d" % i)

        # Show beam
        if opts.waterfall:
            ax.imshow(np.log10(data[:, :, i]),
                      aspect='auto',
                      origin='lower',
                      extent=[frequency[0], frequency[-1], 0, time[-1]])
            ax.xaxis.set_major_formatter(pylab.FormatStrFormatter('%2.2f'))
            ax.set_xlabel("Channel (kHz)")
            ax.set_ylabel("Time (s)")

        # Plot bandpass
        if opts.bandpass:
            ax.plot(frequency, np.log10(np.sum(data[:, :, i], axis=0)))
            ax.xaxis.set_major_formatter(pylab.FormatStrFormatter('%2.2f'))
            ax.set_xlabel("Channel (MHz)")
            ax.set_ylabel("Log Power (Arbitrary)")
            ax.set_xlim((frequency[0], frequency[-1]))

        # Plot time series
        if opts.time:
            ax.plot(time, np.sum(data[:, :, i] / nchans, axis=1))
            ax.xaxis.set_major_formatter(pylab.FormatStrFormatter('%2.1f'))
            ax.set_xlabel("Time (s)")
            ax.set_ylabel("Power (Arbitrary)")
            ax.set_xlim((time[0], time[-1]))

    fig.tight_layout()
    plt.show()
    f.close()