示例#1
0
    def on_keypress_custom(self, event):
        if event.key == 'right':
            if self.i == self.n - 1:
                print 'At the last spectrum.'
                return
            self.artists['zlines'] = []
            self.get_new_spec(self.i + 1)
            self.update()

        elif event.key == 'left':
            if self.i == 0:
                print 'At the first spectrum.'
                return
            self.artists['zlines'] = []
            self.get_new_spec(self.i - 1)
            self.update()
        elif event.key == '?':
            print help
        elif event.key == 'T':
            if self.opt.ticklabels:
                for t in self.artists['ticklabels']:
                    t.set_visible(False)
                self.opt.ticklabels = False
            else:
                self.opt.ticklabels = True
                x0, x1 = self.ax.get_xlim()
                for t in self.artists['ticklabels']:
                    if x0 < t.get_position()[0] < x1:
                        t.set_visible(True)
            self.fig.canvas.draw()
        elif event.key == ' ' and event.inaxes is not None:
            print '%.4f  %.4f %i' % (
                event.xdata, event.ydata,
                indexnear(self.spec[self.i].wa, event.xdata))
        elif event.key == 'm' and event.inaxes is not None:
            if self.wlim1 is not None:
                self.artists['mlines'].append(plt.gca().axvline(
                    event.xdata, color='k', alpha=0.3))
                plt.draw()
                w0, w1 = self.wlim1, event.xdata
                if w0 > w1:
                    w0, w1 = w1, w0
                sp = self.spec[self.i]
                good = between(sp.wa, w0, w1) & (sp.er > 0) & ~np.isnan(sp.fl)

                fmt1 = 'Median flux {:.3g}, rms {:.2g}, er {:.2g}. {:.2g} A/pix'
                fmt2 = ('SNR {:.2g}/pix, {:.2g}/A (RMS), {:.2g}/pix, {:.2g}/A '
                       '(er)')
                if good.sum() < 2:
                    print 'Too few good pixels in range'
                    self.wlim1 = None
                    return
                medfl = np.median(sp.fl[good])
                stdfl = sp.fl[good].std()
                meder = np.median(sp.er[good])
                pixwidth = np.mean(sp.wa[good][1:] - sp.wa[good][:-1])
                mult = sqrt(1. / pixwidth)
                snr1 = medfl / stdfl
                snr2 = medfl / meder
                print fmt1.format(medfl, stdfl, meder, pixwidth)
                print fmt2.format(snr1, snr1 * mult, snr2, snr2 * mult)
                self.wlim1 = None
            else:
                for l in self.artists['mlines']:
                    try:
                        l.remove()
                    except ValueError:
                        # plot has been removed
                        pass
                self.artists['mlines'].append(plt.gca().axvline(
                    event.xdata,  color='k', alpha=0.3))
                plt.draw()
                self.wlim1 = event.xdata
                print "press 'm' again..."

        elif event.key == 'C':
            # fit dodgy continuum
            sp = self.spec[self.i]
            co = barak.spec.find_cont(sp.fl)
            temp, = plt.gca().plot(sp.wa, co, 'm')
            plt.draw()
            c = raw_input('Accept continuum? (y) ')
            if (c + ' ').lower()[0] != 'n':
                print 'Accepted'
                sp.co = co
                self.update()
            else:
                temp.remove()

        elif event.key == 'B' and event.inaxes is not None:
            # print fitting region
            wa = event.xdata
            if self.prev_wa != None:
                wmin = self.prev_wa
                wmax = wa
                if wmin > wmax:
                    wmin, wmax = wmax, wmin
                print '%%%% %s 1 %.3f %.3f vsig=x.x' % (self.filenames[self.i], wmin, wmax)
                self.prev_wa = None
            else:
                self.prev_wa = wa

        elif event.key == 'h' and event.inaxes is not None:
            # print HI line
            wa = event.xdata
            z = wa / 1215.6701 - 1
            print '%-6s %8.6f 0.0 %3.0f 0.0 %4.1f 0.0' % ('HI', z, 20, 14.0)

        elif event.key == 'E':
            # overplot a template
            c = '0'
            while c not in '1234':
                c = raw_input("""\
1: LBG
2: QSO
3: LRG
4: Starburst galaxy
""")
            temp = get_SEDs('LBG', 'lbg_em.dat')
            temp.redshift_to(self.zp1 - 1)
            self.twa = temp.wa
            self.tfl = temp.fl
            self.update()
示例#2
0
文件: sed.py 项目: ntejos/Barak
from barak.sed import get_bands, get_SEDs
import pylab as pl
import numpy as np

fors_u, fors_g, fors_r = get_bands('FORS','u,g,r',ccd='blue')
sdss_u, sdss_g, sdss_r = get_bands('SDSS','u,g,r')
pl.figure()
for b in fors_u, fors_g, fors_r, sdss_u, sdss_g, sdss_r:
    b.plot()

pickles = get_SEDs('pickles')
fig = pl.figure()
fig.subplots_adjust(left=0.18)
for p in pickles:
    p.plot(log=1)
pl.title('Pickles stellar library')

p_umg = [p.calc_colour(sdss_u, sdss_g, 'AB') for p in pickles]
p_gmr = [p.calc_colour(sdss_g, sdss_r, 'AB') for p in pickles]

tLBG = get_SEDs('LBG', 'lbg_em.dat')
tLBGa = get_SEDs('LBG', 'lbg_abs.dat')
tLBG_umg, tLBG_gmr = [], []
tLBGa_umg, tLBGa_gmr = [], []
zlabels = []
for z in np.arange(2.2, 3.7, 0.2):
    zlabels.append(str(z))
    tLBG.redshift_to(z)
    tLBGa.redshift_to(z)
    tLBG_umg.append(tLBG.calc_colour(sdss_u,sdss_g, 'AB'))
    tLBG_gmr.append(tLBG.calc_colour(sdss_g,sdss_r, 'AB'))
示例#3
0
    def on_keypress_custom(self, event):
        if event.key == 'pagedown':
            if self.i == self.n - 1:
                print('At the last spectrum.')
                return
            self.artists['zlines'] = []
            self.get_new_spec(self.i + 1)
            self.update()

        elif event.key == 'pageup':
            if self.i == 0:
                print('At the first spectrum.')
                return
            self.artists['zlines'] = []
            self.get_new_spec(self.i - 1)
            self.update()
        elif event.key == '?':
            print(help)
        elif event.key == 'T':
            if self.opt.ticklabels:
                for t in self.artists['ticklabels']:
                    t.set_visible(False)
                self.opt.ticklabels = False
            else:
                self.opt.ticklabels = True
                x0, x1 = self.ax.get_xlim()
                for t in self.artists['ticklabels']:
                    if x0 < t.get_position()[0] < x1:
                        t.set_visible(True)
            self.fig.canvas.draw()
        elif event.key == ' ' and event.inaxes is not None:
            print('%.4f  %.4f %i' % (
                event.xdata, event.ydata,
                indexnear(self.spec[self.i].wa, event.xdata)))
        elif event.key == 'm' and event.inaxes is not None:
            if self.wlim1 is not None:
                self.artists['mlines'].append(plt.gca().axvline(
                    event.xdata, color='k', alpha=0.3))
                plt.draw()
                w0, w1 = self.wlim1, event.xdata
                if w0 > w1:
                    w0, w1 = w1, w0
                sp = self.spec[self.i]
                good = between(sp.wa, w0, w1) & (sp.er > 0) & ~np.isnan(sp.fl)

                fmt1 = 'Median flux {:.3g}, rms {:.2g}, er {:.2g}. {:.2g} A/pix'
                fmt2 = ('SNR {:.3g}/pix, {:.3g}/A (RMS), {:.3g}/pix, {:.3g}/A '
                       '(er)')
                if good.sum() < 2:
                    print('Too few good pixels in range')
                    self.wlim1 = None
                    return
                medfl = np.median(sp.fl[good])
                stdfl = sp.fl[good].std()
                meder = np.median(sp.er[good])
                pixwidth = np.mean(sp.wa[good][1:] - sp.wa[good][:-1])
                mult = sqrt(1. / pixwidth)
                snr1 = medfl / stdfl
                snr2 = medfl / meder
                print(fmt1.format(medfl, stdfl, meder, pixwidth))
                print(fmt2.format(snr1, snr1 * mult, snr2, snr2 * mult))
                self.wlim1 = None
            else:
                for l in self.artists['mlines']:
                    try:
                        l.remove()
                    except ValueError:
                        # plot has been removed
                        pass
                self.artists['mlines'].append(plt.gca().axvline(
                    event.xdata,  color='k', alpha=0.3))
                plt.draw()
                self.wlim1 = event.xdata
                print("press 'm' again...")

        elif event.key == 'C':
            # fit dodgy continuum
            sp = self.spec[self.i]
            co = barak.spec.find_cont(sp.fl)
            temp, = plt.gca().plot(sp.wa, co, 'm')
            plt.draw()
            c = raw_input('Accept continuum? (y) ')
            if (c + ' ').lower()[0] != 'n':
                print('Accepted')
                sp.co = co
                self.update()
            else:
                temp.remove()

        elif event.key == 'B' and event.inaxes is not None:
            # print fitting region
            wa = event.xdata
            if self.prev_wa != None:
                wmin = self.prev_wa
                wmax = wa
                if wmin > wmax:
                    wmin, wmax = wmax, wmin
                print('%%%% %s 1 %.3f %.3f vsig=x.x' % (
                    self.filenames[self.i], wmin, wmax))
                self.prev_wa = None
            else:
                self.prev_wa = wa

        elif event.key == 'h' and event.inaxes is not None:
            # print HI line
            wa = event.xdata
            z = wa / 1215.6701 - 1
            print('%-6s %8.6f 0.0 %3.0f 0.0 %4.1f 0.0' % ('HI', z, 20, 14.0))

        elif event.key == 'E':
            # overplot a template
            c = '0'
            while c not in '1234':
                c = raw_input("""\
1: LBG
2: QSO
3: LRG
4: Starburst galaxy
""")
            temp = get_SEDs('LBG', 'lbg_em.dat')
            temp.redshift_to(self.zp1 - 1)
            self.twa = temp.wa
            self.tfl = temp.fl
            self.update()

        elif event.key == ')':
            self.ax.set_xlabel('$\mathrm{Wavelength\ (\AA)}$')
            self.ax.set_ylabel('$F_\lambda\ \mathrm{(arbitrary)}$')
            self.update()