def dissoc_spec(star_or_spec, species_list, dissoc_only=True): if not hasattr(species_list, '__iter__'): species_list = [species_list] if type(star_or_spec) is str: star = star_or_spec spec = io.readpan(star) else: spec = star_or_spec star = spec.meta['STAR'] spec = utils.add_photonflux(spec) bolo = utils.bolo_integral(spec) if 'pan' in spec.meta['NAME'] else utils.bolo_integral(star) # erg s-1 cm-2 result = [] for species in species_list: xtbl = io.read_xsections(species, dissoc_only=dissoc_only) w0, w1 = utils.wbins(spec).T w = (w0 + w1) / 2.0 xsum = sumdissoc(xtbl) xsumi = np.interp(w, xtbl['w'], xsum, np.nan, np.nan) xspec_bolo = spec['flux_photon'] * xsumi / bolo dw = w1 - w0 dissoc_bolo = np.nansum(dw * xspec_bolo) # cm2 erg-1 dtbl = Table(data=[w0, w1, xspec_bolo], names=['w0', 'w1', 'diss']) dtbl['diss'].units = u.cm**2 / u.AA / u.erg dtbl['w0'].units = dtbl['w1'].units = u.AA result.append([dtbl, dissoc_bolo]) return result
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')
def fluxall(band=rc.fuv): Is = [] for star in rc.observed: spec = io.readpan(star) I = utils.flux_integral(spec, *band) Is.append(I) return zip(*Is)
def fuv_cont_stats(star): """ Get stats on FUV continuum flux: - avg flux - avg flux error - raito of FUV continuum to total flux in the FUV assuming flat continuum - error on ratio """ pan = io.readpan(star) cont = utils.keepranges(pan, rc.contbands, ends='exact') dw = cont['w1'] - cont['w0'] # assume flat continuum # Fcont_avg = np.sum(cont['flux'] * dw)/np.sum(dw) # Fcont_avg_err = mnp.quadsum(cont['error'] * dw)/np.sum(dw) # dw_fuv = rc.fuv[1] - rc.fuv[0] # Fall_FUV, Fall_FUV_err = utils.flux_integral(pan, *rc.fuv) # ratio = Fcont_avg * dw_fuv / Fall_FUV # ratio_err = abs(ratio)*np.sqrt((Fall_FUV_err/Fall_FUV)**2 + (Fcont_avg_err/Fcont_avg)**2) # just do continuum actual measured, ignore "in-between" continuumFcont_avg Fcont = np.sum(cont['flux'] * dw) Fcont_err = mnp.quadsum(cont['error'] * dw) Fall_FUV, Fall_FUV_err = utils.flux_integral(pan, cont['w0'][0], cont['w1'][-1]) ratio = Fcont / Fall_FUV ratio_err = abs(ratio)*np.sqrt((Fall_FUV_err/Fall_FUV)**2 + (Fcont_err/Fcont)**2) return Fcont, Fcont_err, ratio, ratio_err
def lya_splices(stars='all'): if stars == 'all': stars = rc.stars[:11] stars.remove('gj551') dw = 0.05 for star in stars: pan = io.readpan(star) pan = utils.keepranges(pan, 1100, 1300) pan = utils.evenbin(pan, dw) sf = db.findfiles('u', star, 'coadd', 'cos_g130m') spec, = io.read(sf) spec = utils.evenbin(spec, dw) lf = db.findfiles('u', star, 'mod', 'lya') lya, = io.read(lf) plt.figure() [ss(s, err=False) for s in [pan, spec, lya]] plt.xlim(1210, 1222) up, _ = utils.flux_integral(spec, 1217, 1220) plt.ylim(0, up * 4) plt.legend(['pan', 'cos', 'lya'], loc='best') plt.savefig( os.path.join(rc.scratchpath, 'lya splices', '{} linear.pdf'.format(star))) mx = spec['flux'].max() plt.ylim(mx / 1e7, mx) plt.yscale('log') plt.savefig( os.path.join(rc.scratchpath, 'lya splices', '{} log.pdf'.format(star)))
def compare_v20_v10(stars=None, plot=False): if stars is None: stars = mlstars oldfile_template = '/Users/rolo7566/Datasets/MUSCLES/products/archive/panspecs v10/p_msl_pan_-----_{}_panspec_native_resolution.fits' hlspfile_template = '/Users/rolo7566/Google Drive/Grad School/PhD Work/muscles/share/hlsp/archive/hlsp_muscles_multi_multi_{}_broadband_v10_var-res-sed.fits' compare_template = '/Users/rolo7566/Google Drive/Grad School/PhD Work/muscles/scratchwork/v10 - v20 comparisons/{' \ '} v20 vs v10 ratio.fits' for star in stars: p = io.readpan(star) op, = io.read(oldfile_template.format(star)) hp, = io.read(hlspfile_template.format(star)) op = red.splice(op, utils.keepranges(hp, 100., 1169.)) p, op = [utils.keepranges(spec, 0, 10000.) for spec in [p, op]] cs = utils.compare_specs(p, op, savetxt=compare_template.format(star)) cf = compare_template.format(star) cs.write(cf, overwrite=True) if plot: plt.figure() ss(cs, key='ratio') plt.title(star) plt.xlabel('Wavelength $\AA$') plt.ylabel('Ratio of v20 to v10 SED')
def phx_norm_compare(): oldfile_template = '/Users/rolo7566/Datasets/MUSCLES/products/archive/panspecs v10/p_msl_pan_-----_{}_panspec_native_resolution.fits' for star in mlstars: op, = io.read(oldfile_template.format(star)) ofac = op['normfac'][-1] p = io.readpan(star) fac = p['normfac'][-1] chng = abs(fac / ofac - 1) * 100. name = rc.starprops['name txt'][star] print '{:8s} | {:6.1f}'.format(name, chng)
def lya_galex_ratio(star): import numpy as np nuv = np.loadtxt( '/Users/rolo7566/Datasets/shared/filter response curves/galexNUV.txt', skiprows=1).T fuv = np.loadtxt( '/Users/rolo7566/Datasets/shared/filter response curves/galexFUV.txt', skiprows=1).T pan = io.readpan(star) lya, = io.read(db.findfiles('u', star, 'mod_lya')) lya = utils.flux_integral(lya)[0] w = (pan['w0'] + pan['w1']) / 2.0 f = pan['flux'] twf = lambda bp: np.trapz(np.interp(bp[0], w, f) * bp[1], bp[0]) NUV, FUV = map(twf, [nuv, fuv]) print star print 'Lya/NUV ratio = {:.2g}'.format(lya / NUV) print 'Lya/FUV ratio = {:.2g}'.format(lya / FUV)
def fuv_cont_spec(star): """Get just the continuum flux regions of a star's panspec.""" spec = io.readpan(star) return utils.keepranges(spec, rc.contbands, ends='exact')