Exemple #1
0
    def plot_spec_templ(self, twa, tfl):
        """ Initiate plots of the spectrum and a template, scaled to
        matched the spectrum.
        """
        sp = self.spec

        ax2 = self.ax[2]
        ax2.axhline(0, color='0.7')
        if self.smoothed:
            self.art_spec2, = ax2.plot(sp.wa, convolve_psf(sp.fl,5), 'k',lw=0.5,ls='steps-mid')
        else:
            self.art_spec2, = ax2.plot(sp.wa, sp.fl, 'k', lw=0.5, ls='steps-mid')
        ax2.plot(sp.wa, sp.er, 'k', lw=0.25)
        good = sp.er > 0
        if (~good).any():
            ax2.plot(sp.wa[~good], sp.er[~good], 'k.', ms=4)
        mult = scale_by_median(twa, tfl, sp.wa, sp.fl, mask=MASKATMOS)
        if mult is None:
            self.art_templ2, = ax2.plot([], [], color='r', alpha=0.7)
        else:
            self.art_templ2, = ax2.plot(twa, mult*tfl, color='r', alpha=0.7)

        ymax = np.abs(np.percentile(sp.fl[good & (sp.wa>5700)], 98))
        offset = 0.15 * ymax
        temp = max(np.median(sp.fl), np.median(sp.er))
        sky = 0.15 * temp / np.median(sp.sky)*sp.sky - offset
        axvfill(MASKATMOS, ax=ax2, color='y', alpha=0.3)
        ax2.fill_between(sp.wa, sky, y2=-offset, color='g', lw=0, alpha=0.3, zorder=1)
        #pdb.set_trace()
        if self.msky is not None:
            s = self.msky
            msky = s * np.median(sky + offset) / np.median(s)
            ax2.plot(sp.wa, msky - offset, color='g', lw=1.5, zorder=1)

        ax2.set_ylim(-ymax*0.15, 1.5*ymax)
    def plot_spec_templ(self, twa, tfl):
        """ Initiate plots of the spectrum and a template, scaled to
        matched the spectrum.
        """
        sp = self.spec

        ax2 = self.ax[2]
        ax2.axhline(0, color='0.7')
        if self.smoothed:
            self.art_spec2, = ax2.plot(sp.wa,
                                       convolve_psf(sp.fl, 5),
                                       'k',
                                       lw=0.5,
                                       ls='steps-mid')
        else:
            self.art_spec2, = ax2.plot(sp.wa,
                                       sp.fl,
                                       'k',
                                       lw=0.5,
                                       ls='steps-mid')
        ax2.plot(sp.wa, sp.er, 'k', lw=0.25)
        good = sp.er > 0
        if (~good).any():
            ax2.plot(sp.wa[~good], sp.er[~good], 'k.', ms=4)
        mult = scale_by_median(twa, tfl, sp.wa, sp.fl, mask=MASKATMOS)
        if mult is None:
            self.art_templ2, = ax2.plot([], [], color='r', alpha=0.7)
        else:
            self.art_templ2, = ax2.plot(twa, mult * tfl, color='r', alpha=0.7)

        ymax = np.abs(np.percentile(sp.fl[good & (sp.wa > 5700)], 98))
        offset = 0.15 * ymax
        temp = max(np.median(sp.fl), np.median(sp.er))
        sky = 0.15 * temp / np.median(sp.sky) * sp.sky - offset
        axvfill(MASKATMOS, ax=ax2, color='y', alpha=0.3)
        ax2.fill_between(sp.wa,
                         sky,
                         y2=-offset,
                         color='g',
                         lw=0,
                         alpha=0.3,
                         zorder=1)
        #pdb.set_trace()
        if self.msky is not None:
            s = self.msky
            msky = s * np.median(sky + offset) / np.median(s)
            ax2.plot(sp.wa, msky - offset, color='g', lw=1.5, zorder=1)

        ax2.set_ylim(-ymax * 0.15, 1.5 * ymax)
    def update(self, fitpeak=True):
        """ Update the figure after changing either the template
        (self.i) or template redshift (self.z).
        """
        i, z = self.i, self.z

        self.art_highlight.set_data(i, self.valsmax[i])
        self.art_zline.set_xdata(z)
        self.fig.canvas.draw()

        if len(self.vals[i]) > 1:
            if fitpeak:
                self.z = self.find_xcorr_peak(z)
                self.art_zline.set_xdata(self.z)

            ymax = self.vals[i].max()
            self.ax[1].set_ylim(-0.5 * ymax, 1.5 * ymax)
        else:
            self.ax[1].set_ylim(-0.5, 1.5)

        self.plotlines(self.z + 1)

        # plot the new template (or same template at different z)
        t = self.templ[i]
        twa = 10**t.logwa * (1 + self.z)
        sp = self.spec

        mult = scale_by_median(twa, t.fl, sp.wa, sp.fl, mask=MASKATMOS)
        if mult is None:
            tfl = []
            twa = []
        else:
            tfl = t.fl * mult

        #nchi2 = measure_nchi2(twa, tfl, sp.wa, sp.fl, sp.er)
        self.art_templ2.set_data(twa, tfl)

        self.title.set_text('%s, z=%.4f, %s' %
                            (self.objname, z, self.templ[i].label))
        self.art_vals.set_data([self.redshifts[i], self.vals[i]])

        #nchi = np.log10(self.nchi2[i])
        #self.art_nchi.set_data([self.redshifts[i], nchi])

        z0, z1 = self.redshifts[i][0], self.redshifts[i][-1]
        self.ax[1].set_xlim(z0 - 0.01, z1 + 0.01)
        self.ax[2].set_xlim(WMIN_PLOT, WMAX_PLOT)
Exemple #4
0
    def update(self, fitpeak=True):
        """ Update the figure after changing either the template
        (self.i) or template redshift (self.z).
        """
        i, z = self.i, self.z
        
        self.art_highlight.set_data(i, self.valsmax[i])
        self.art_zline.set_xdata(z)
        self.fig.canvas.draw()

        if len(self.vals[i]) > 1:
            if fitpeak:
                self.z = self.find_xcorr_peak(z)
                self.art_zline.set_xdata(self.z)

            ymax = self.vals[i].max()
            self.ax[1].set_ylim(-0.5*ymax, 1.5*ymax)
        else:
            self.ax[1].set_ylim(-0.5, 1.5)

        self.plotlines(self.z+1)

        # plot the new template (or same template at different z)
        t = self.templ[i]
        twa = 10**t.logwa * (1 + self.z)
        sp = self.spec
        
        mult = scale_by_median(twa, t.fl, sp.wa, sp.fl, mask=MASKATMOS)
        if mult is None:
            tfl = []
            twa = []
        else:
            tfl = t.fl * mult
        
        #nchi2 = measure_nchi2(twa, tfl, sp.wa, sp.fl, sp.er)
        self.art_templ2.set_data(twa, tfl)
    
        self.title.set_text('%s, z=%.4f, %s' % (self.objname, z, self.templ[i].label))
        self.art_vals.set_data([self.redshifts[i], self.vals[i]])

        #nchi = np.log10(self.nchi2[i])
        #self.art_nchi.set_data([self.redshifts[i], nchi])


        z0, z1 = self.redshifts[i][0], self.redshifts[i][-1]
        self.ax[1].set_xlim(z0 - 0.01, z1 + 0.01)
        self.ax[2].set_xlim(WMIN_PLOT, WMAX_PLOT)