Пример #1
0
def phxFit(star='gj832', ax=None):
    if ax is None: ax = plt.gca()
    ax.autoscale(axis='x', tight=True)
    ax.set_yscale('log')

    pan = io.readpan(star)
    bolo = utils.bolo_integral(star)
    xf = db.findfiles('ir', 'phx', star, fullpaths=True)
    phx = io.read(xf)[0]
    phx['flux'] *= pan['normfac'][-1]
    pan = pan[pan['instrument'] != pan['instrument'][-1]]
    fmin = np.min(pan['error'][pan['error'] > 0]) / bolo
    rng = [phx['w0'][0], 6000.]
    phx, pan = [
        utils.keepranges(spec, rng, ends='loose') for spec in [phx, pan]
    ]
    phx, pan = [utils.fancyBin(s, mindw=10.0) for s in [phx, pan]]
    pan['flux'][pan['flux'] < pan['error'] / 2.0] = np.nan
    pan['normflux'] = pan['flux'] / bolo
    phx['normflux'] = phx['flux'] / bolo
    ymax = 10**np.ceil(np.log10(np.max(phx['normflux'])))
    ymin = 10**np.floor(np.log10(fmin) - 3)
    ax.set_ylim(ymin, ymax)

    pline = plot.specstep(pan, ax=ax, color='k', err=False, key='normflux')
    xline = plot.specstep(phx, ax=ax, color='gray', err=False, key='normflux')
    ax.legend((pline, xline), ('$HST$ Data', 'PHOENIX Model'),
              loc='lower right')
Пример #2
0
def plotnorm(spec_or_star, ax=plt.gca(), clip=1e-10):
    if type(spec_or_star) is str:
        spec = io.read(db.Rpanpath(spec_or_star, 10000))[0]
    else:
        spec = spec_or_star
    spec = utils.add_normflux(spec)
    bad = spec['normflux'] < 1e-10
    spec['normflux'][bad] = np.nan
    plot.specstep(spec, ax=ax)
Пример #3
0
def cyclespec(files):
    plt.ioff()
    for f in files:
        specs = io.read(f)
        for spec in specs:
            specstep(spec)
        plt.title(path.basename(f))
        plt.xlabel('Wavelength [$\AA$]')
        plt.ylabel('Flux [erg/s/cm$^2$/$\AA$]')
        plt.show()
    plt.ion()
Пример #4
0
def vetcoadd(star, config):
    """Plot the components of a coadded spectrum to check that the coadd agrees."""
    coaddfile = db.coaddfile(star, config)
    coadd = io.read(coaddfile)
    assert len(coadd) == 1
    coadd = coadd[0]

    sourcefiles = coadd.meta['SOURCESPECS']
    sourcespecs = io.read(sourcefiles)
    for spec in sourcespecs:
        specstep(spec)

    specstep(coadd, lw=2.0, c='k', alpha=0.5)
    plt.title(path.basename(coadd.meta['FILENAME']))
Пример #5
0
def examinedates(star):
    """Plot the min and max obs dates to make sure everything looks peachy."""
    pans = io.readpans(star)
    mindate = min([np.min(p['minobsdate'][p['minobsdate'] > 0]) for p in pans])
    maxdate = max([np.max(p['maxobsdate'][p['maxobsdate'] > 0]) for p in pans])
    d = (maxdate - mindate)

    los = [specstep(p, key='minobsdate', linestyle='--') for p in pans]
    colors = [l.get_color() for l in los]
    his = [
        specstep(p, key='maxobsdate', linestyle=':', color=c)
        for p, c in zip(pans, colors)
    ]
    plt.ylim(mindate - d / 10.0, maxdate + d / 10.0)
    labels = [db.parse_paninfo(p.meta['FILENAME']) for p in pans]
    plt.legend(los, labels)
Пример #6
0
def vetnormfacs(spec, panspec, normfac, normranges):
    """Check the normalization of files by plotting normalized and unnormalieze
    versions. Called from reduce.panspec"""
    name = spec.meta['NAME']
    oranges = utils.overlap_ranges(spec, panspec)
    if normranges is None:
        normranges = oranges
    else:
        normranges = mnp.rangeset_intersect(normranges, oranges)

    # construct bins from lower res in each normrange
    overbins = []
    for normrange in normranges:
        getbins = lambda s: utils.wbins(utils.keepranges(s, normrange))
        possible_bins = map(getbins, [spec, panspec])
        bins = min(possible_bins, key=lambda b: len(b))
        overbins.append(bins)
    overbins = np.vstack(overbins)

    # rebin each spec to the lowest res within the overlap
    def coarsebin(s):
        overspec = utils.rebin(s, overbins)
        return red.splice(s, overspec)

    spec, panspec = map(coarsebin, [spec, panspec])

    # plot the spectrum being normalized, highlighting the normranges
    plt.figure()
    #    ax = plt.axes()
    inranges, _ = utils.argoverlap(spec, normranges)
    specin = spec[inranges]
    specout = spec[~inranges]
    kwargs = {'err': False}
    line1 = specstep(specout, alpha=0.3, linestyle='--', **kwargs)
    kwargs['color'] = line1.get_color()
    line2 = specstep(specin, alpha=0.3, **kwargs)
    specin['flux'] *= normfac
    specout['flux'] *= normfac
    line3 = specstep(specout, linestyle='--', **kwargs)
    line4 = specstep(specin, **kwargs)
    plt.legend((line2, line4), ('original', 'normalized'))

    # plot panspec
    fullrange = spec['w0'][0], spec['w1'][-1]
    panspec = utils.keepranges(panspec, fullrange)
    #    ymax = np.max(panspec['flux'])
    piecespec(panspec, err=False)
    normed = panspec['normfac'] != 1.0
    if np.any(normed):
        normspec = panspec[normed]
        normspec['flux'] /= normspec['normfac']
        specstep(normspec, color='k', linestyle='--', alpha=0.5, err=False)


#    ax.set_ylim(-0.05 * ymax, 1.05 * ymax)
    plt.title('{} normalization'.format(name))
Пример #7
0
def splitSpec(spec, ax=None, wsplit=3000., scale_fac=50.):
    ax1 = plt.gca() if ax is None else ax

    ax2 = ax1.twinx()
    leftspec = utils.keepranges(spec, 0.0, wsplit)
    rightspec = utils.keepranges(spec, wsplit, np.inf)
    step = lambda spec, ax: plot.specstep(
        spec, err=False, ax=ax, color='k', autolabel=False)
    leftline = step(leftspec, ax1)
    rightline = step(rightspec, ax2)
    ax2.set_ylim(0.0, None)
    ax1.set_ylim(0.0, ax2.get_ylim()[1] / scale_fac)

    ax1.axvline(wsplit, ls=':')

    return (ax1, leftline), (ax2, rightline)
Пример #8
0
def piecespec(spec, err=True):
    """Plot a spectrum color-coded by source instrument."""
    insts = np.unique(spec['instrument'])
    insts = filter(lambda i: np.log2(i) % 1 == 0, insts)
    for i in insts:
        keep = (spec['instrument'] == i)
        thisspec = spec[keep]

        configs_i = np.nonzero(np.array(rc.instvals) & i)[0]
        configs = [rc.instruments[j] for j in configs_i]
        configstr = ' + '.join(configs)

        lines = specstep(thisspec, err=err)
        color = lines[0].get_color() if err else lines.get_color()
        w, f = [np.nanmean(thisspec[s]) for s in ['w0', 'flux']]
        txtprops = dict(facecolor='white', alpha=0.5, color=color)
        plt.text(w, f, configstr, bbox=txtprops, ha='center')
Пример #9
0
def lyavsdata(star):
    data, = io.read(db.lyafile(star))
    mod, = io.read(db.findfiles('u', 'lya', star, fullpaths=True)[0])
    specstep(data)
    specstep(mod)
    plt.xlim(1208, 1222)
Пример #10
0
 def plotfun(spec, **kwargs):
     s = utils.rebin(spec, wbins)
     return specstep(s, **kwargs)