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 prepare_templates(templates, convolve_pix=None, plot=0): """ Add continua to templates and interpolate to log-linear wav scale. Returns a new set of templates. """ tnew = [] for t in templates: # fudge to remove bad template areas print t.label wgood = t.wa[t.fl > 1e-99] w0, w1 = wgood[0], wgood[-1] cond = between(t.wa, w0, w1) wa0, fl0 = t.wa[cond], t.fl[cond] if plot: ax = pl.gca() ax.cla() pl.plot(wa0, fl0, 'b') # rebin to a log-linear wavelength scale. To shift wavescale # to redshift z, add log10(1+z) to wa or twa. dw = (np.log10(wa0[-1]) - np.log10(wa0[0])) / (len(wa0) - 1) logtwa = np.log10(wa0[0]) + dw * np.arange(len(wa0)) twa = 10**logtwa tfl = np.interp(twa, wa0, fl0) if t.label.startswith('sdss') and convolve_pix is not None: # convolve to VIMOS resolution tfl = convolve_psf(tfl, convolve_pix) fwhm1 = len(wa0) // 7 fwhm2 = len(wa0) // 9 #print fwhm1, fwhm2 tco = find_cont(tfl, fwhm1=fwhm1, fwhm2=fwhm2) if plot: pl.plot(twa, tfl, 'r') pl.plot(twa, tco, 'r--') pl.show() raw_input() t1 = adict(logwa=logtwa, fl=tfl, co=tco, label=t.label) tnew.append(t1) return tnew
def prepare_templates(templates, convolve_pix=None, plot=0): """ Add continua to templates and interpolate to log-linear wav scale. Returns a new set of templates. """ tnew = [] for t in templates: # fudge to remove bad template areas print t.label wgood = t.wa[t.fl > 1e-99] w0,w1 = wgood[0], wgood[-1] cond = between(t.wa, w0, w1) wa0, fl0 = t.wa[cond], t.fl[cond] if plot: ax = pl.gca() ax.cla() pl.plot(wa0, fl0, 'b') # rebin to a log-linear wavelength scale. To shift wavescale # to redshift z, add log10(1+z) to wa or twa. dw = (np.log10(wa0[-1]) - np.log10(wa0[0])) / (len(wa0) - 1) logtwa = np.log10(wa0[0]) + dw * np.arange(len(wa0)) twa = 10**logtwa tfl = np.interp(twa, wa0, fl0) if t.label.startswith('sdss') and convolve_pix is not None: # convolve to VIMOS resolution tfl = convolve_psf(tfl, convolve_pix) fwhm1 = len(wa0) // 7 fwhm2 = len(wa0) // 9 #print fwhm1, fwhm2 tco = find_cont(tfl, fwhm1=fwhm1, fwhm2=fwhm2) if plot: pl.plot(twa, tfl, 'r') pl.plot(twa, tco, 'r--') pl.show() raw_input() t1 = adict(logwa=logtwa, fl=tfl, co=tco, label=t.label) tnew.append(t1) return tnew
def on_keypress(self, event): if event.key == '?': print self.help elif event.key == 'y': print 'Redshift = %.3f' % self.z self.zgood = self.z self.zconf = 'a' self.disconnect() elif event.key == 'm': print 'Maybe redshift = %.3f' % self.z self.zgood = self.z self.zconf = 'b' self.disconnect() elif event.key == 'n': print 'Rejecting, z set to -1' self.zgood = -1. self.zconf = 'c' self.disconnect() elif event.key == 'f': # NT code print 'Rejecting fake object, z set to -1' self.zgood = -1. self.zconf = 'f' self.disconnect() elif event.key == 'k': print 'Skipping, not writing anything' self.zconf = 'k' self.disconnect() elif event.key == 's': if self.smoothed: self.art_spec2.set_data(self.spec.wa, self.spec.fl) self.smoothed = False else: fl = convolve_psf(self.spec.fl, 5) self.art_spec2.set_data(self.spec.wa, fl) self.smoothed = True self.fig.canvas.draw() elif event.inaxes == self.ax[1]: if event.key == ' ': self.z = event.xdata self.update() self.fig.canvas.draw() elif event.key == 'x': self.z = event.xdata self.update(fitpeak=False) self.fig.canvas.draw() elif event.inaxes == self.ax[0]: if event.key == ' ': i = int(np.round(event.xdata)) self.i = min(max(i, 0), len(self.zatmax) - 1) self.z = self.zatmax[self.i] self.update() self.fig.canvas.draw() elif event.inaxes == self.ax[2]: try: j = self.keys.index(event.key) except ValueError: return line = self.lines_sel[j] zp1 = event.xdata / line['wa'] #print 'z=%.3f, %s %f' % (zp1 - 1, line['name'], line['wa']) self.z = zp1 - 1 self.update(fitpeak=False) self.fig.canvas.draw()
def on_keypress(self, event): if event.key == '?': print self.help elif event.key == 'y': print 'Redshift = %.3f' % self.z self.zgood = self.z self.zconf = 'a' self.disconnect() elif event.key == 'm': print 'Maybe redshift = %.3f' % self.z self.zgood = self.z self.zconf = 'b' self.disconnect() elif event.key == 'n': print 'Rejecting, z set to -1' self.zgood = -1. self.zconf = 'c' self.disconnect() elif event.key == 'f': # NT code print 'Rejecting fake object, z set to -1' self.zgood = -1. self.zconf = 'f' self.disconnect() elif event.key == 'k': print 'Skipping, not writing anything' self.zconf = 'k' self.disconnect() elif event.key == 's': if self.smoothed: self.art_spec2.set_data(self.spec.wa, self.spec.fl) self.smoothed = False else: fl = convolve_psf(self.spec.fl, 5) self.art_spec2.set_data(self.spec.wa, fl) self.smoothed = True self.fig.canvas.draw() elif event.inaxes == self.ax[1]: if event.key == ' ': self.z = event.xdata self.update() self.fig.canvas.draw() elif event.key == 'x': self.z = event.xdata self.update(fitpeak=False) self.fig.canvas.draw() elif event.inaxes == self.ax[0]: if event.key == ' ': i = int(np.round(event.xdata)) self.i = min(max(i, 0), len(self.zatmax)-1) self.z = self.zatmax[self.i] self.update() self.fig.canvas.draw() elif event.inaxes == self.ax[2]: try: j = self.keys.index(event.key) except ValueError: return line = self.lines_sel[j] zp1 = event.xdata / line['wa'] #print 'z=%.3f, %s %f' % (zp1 - 1, line['name'], line['wa']) self.z = zp1 - 1 self.update(fitpeak=False) self.fig.canvas.draw()