Exemple #1
0
Fichier : model.py Projet : nhmc/H2
def readf26file(filename):
    """ Read a f26 style file, and return with regions sorted by
    minimum wavelength.
    """
    vpin = readf26(filename)
    isort = np.argsort([r.wmin for r in vpin.regions])
    vpin.regions = vpin.regions[isort]
    return vpin
Exemple #2
0
def make_models(opt, path=None):
    if opt.f26name is not None:
        n = (path + opt.f26name if path is not None else opt.f26name)
        f26 = readf26(n)

    n = (path + opt.trfilename if path is not None else opt.trfilename)
    transitions = read_transitions(n, atomdat)
    ntrans = len(transitions)
    if isinstance(opt.spfilename, basestring):
        n = (path + opt.spfilename if path is not None else opt.spfilename)
        sp = barak.spec.read(n)
    else:
        sp = opt.spfilename
    wa = sp.wa
    edges = barak.spec.find_bin_edges(wa)     # pixel edges
    dwa = edges[1:] - edges[:-1]             # width per pixel
    ticks = []
    model = None
    models = []

    if opt.f26name is not None:
        dw = np.median(dwa)
        lines = []
        for l in f26.lines:
            lines.append((l['name'].replace(' ',''),l['z'],l['b'],l['logN']))

        if opt.wadiv is not None:
            dw1 = dw / opt.wadiv
            wa1 = np.arange(wa[0], wa[-1]+0.5*dw1, dw1)
            tau, ticks = find_tau(wa1, lines, atomdat)
        else:
            tau, ticks = find_tau(wa, lines, atomdat)

        model = np.exp(-tau)
        models = []
         
        #models = [np.exp(-t) for t in taus]
         
        if opt.wadiv is not None:
            model, models = process_Rfwhm(opt.Rfwhm, wa1, model, models)
        else:
            model, models = process_Rfwhm(opt.Rfwhm, wa, model, models)
         
        if opt.wadiv is not None:
            model = np.interp(wa, wa1, model)
            models = [np.interp(wa, wa1, m) for m in models]

    return sp, transitions, model, models, ticks
from barak.pyvpfit import readf26
from astro.io import writetxt

q0107a = readf26('/home/ntejos/catalogs/Q0107/A.f26')
q0107b = readf26('/home/ntejos/catalogs/Q0107/B.f26')
q0107c = readf26('/home/ntejos/catalogs/Q0107/C.f26')

cond = q0107a.lines.name == 'H I   '
a = q0107a.lines[cond]
cond = q0107b.lines.name == 'H I   '
b = q0107b.lines[cond]
cond = q0107c.lines.name == 'H I   '
c = q0107c.lines[cond]

a.name[:] = 'HI'
b.name[:] = 'HI'
c.name[:] = 'HI'

writetxt('/home/ntejos/catalogs/Q0107/A_HI.txt',[a.name,a.z,a.zsig,a.b,a.bsig,a.logN,a.logNsig])
writetxt('/home/ntejos/catalogs/Q0107/B_HI.txt',[b.name,b.z,b.zsig,b.b,b.bsig,b.logN,b.logNsig])
writetxt('/home/ntejos/catalogs/Q0107/C_HI.txt',[c.name,c.z,c.zsig,c.b,c.bsig,c.logN,c.logNsig])
Exemple #4
0
def process_options(args):
    opt = adict()
    filename = os.path.abspath(__file__).rsplit('/', 1)[0] + '/default.cfg'
    opt = parse_config(filename)
    if os.path.lexists('./plot.cfg'):
        opt = parse_config('./plot.cfg', opt)

    opt.atom = readatom(molecules=True)

    if opt.Rfwhm is not None:
        if isinstance(opt.Rfwhm, basestring):
            if opt.Rfwhm == 'convolve_with_COS_FOS':
                if convolve_with_COS_FOS is None:
                    raise ValueError('convolve_with_COS_FOS() not available')
                print('Using tailored FWHM for COS/FOS data')
                opt.Rfwhm = 'convolve_with_COS_FOS'
            elif opt.Rfwhm.endswith('fits'):
                print('Reading Resolution FWHM from', opt.Rfwhm)
                res = readtabfits(opt.Rfwhm)
                opt.Rfwhm = res.res / 2.354
            else:
                print('Reading Resolution FWHM from', opt.Rfwhm)
                fh = open(opt.Rfwhm)
                opt.Rfwhm = 1 / 2.354 * np.array([float(r) for r in fh])
                fh.close()
        else:
            opt.Rfwhm = float(opt.Rfwhm)

    if opt.features is not None:
        print('Reading feature list from', opt.features)
        opt.features = readtabfits(opt.features)

    if opt.f26 is not None:
        name = opt.f26
        print('Reading ions and fitting regions from', name)
        opt.f26 = readf26(name)
        opt.f26.filename = name

    if opt.transitions is not None:
        print('Reading transitions from', opt.transitions)
        fh = open(opt.transitions)
        trans = list(fh)
        fh.close()
        temp = []
        for tr in trans:
            tr = tr.strip()
            if tr and not tr.startswith('#'):
                junk = tr.split()
                tr = junk[0] + ' ' + junk[1]
                t = findtrans(tr, atomdat=opt.atom)
                temp.append(dict(name=t[0], wa=t[1][0], tr=t[1]))
        opt.linelist = temp
    else:
        opt.linelist = readtxt(get_data_path() + 'linelists/qsoabs_lines',
                               names='wa,name,select')

    if opt.f26 is None and opt.taulines is not None:
        print('Reading ions from', opt.taulines)
        fh = open(opt.taulines)
        lines = []
        for row in fh:
            if row.lstrip().startswith('#'):
                continue
            items = row.split()
            lines.append([items[0]] + list(map(float, items[1:])))
        fh.close()
        opt.lines = lines

    if opt.show_regions is None:
        opt.show_regions = True

    if hasattr(opt, 'aodname'):
        opt.aod = Table.read(opt.aodname)

    return opt
from barak.pyvpfit import readf26
from astro.io import writetxt

q1022 = readf26('/home/ntejos/COS/q1022/FUV/q1022_fuv_all.f26')

cond = q1022.lines.name == 'H I   '
a = q1022.lines[cond]

a.name[:] = 'HI'

writetxt('/home/ntejos/catalogs/Q1022/HI.txt',
         [a.name, a.z, a.zsig, a.b, a.bsig, a.logN, a.logNsig])
Exemple #6
0
 def refresh_f26(self):
     name = self.opt.f26.filename
     print 're-reading from', name
     self.opt.f26 = readf26(name)
     self.opt.f26.filename = name
Exemple #7
0
             'NV 1238': [(90+vzero,200+vzero),(280+vzero, 403+vzero)],
             'OVI 1031': [(-500,-360),(-100, -20),(45,200)],
             'OVI 1037': [(-500,-290), (-100, +45), (70,200)],
             }

cfg = parse_config(config)
transitions = read_transitions(cfg.trfilename, ATOMDAT)

if 1:
    sp = barak.spec.read(cfg.spfilename)
    ndiv = 4.
    wa_dv = make_constant_dv_wa_scale(sp.wa[0], sp.wa[-1], cfg.Rfwhm / ndiv)

    expand_cont_adjustment = 5

    vp = readf26(cfg.f26name)
    lines = vp.lines[vp.lines.name != '<>']
    tau, ticks, alltau = find_tau(sp.wa, lines, ATOMDAT, per_trans=1)
    model = convolve_constant_dv(sp.wa, np.exp(-tau), wa_dv, ndiv)
    models = [convolve_constant_dv(sp.wa, np.exp(-t), wa_dv, ndiv) for t in
              alltau]
    adjust = [l for l in vp.lines if l['name'].strip() == '<>']
    print 'Nadjust', adjust
    if len(adjust) > 0:
        regions = vp.regions
        isort = regions.wmin.argsort()
        print 'Applying continuum adjustments for', len(adjust), 'regions'
        for val in adjust:
            wav0 = ATOMDAT['<>'].wa[0] * (1 + val['z'])
            i0 = regions.wmin[isort].searchsorted(wav0)
            i1 = regions.wmax[isort].searchsorted(wav0)
from barak.pyvpfit import readf26
from astro.io import writetxt

q1022 = readf26('/home/ntejos/COS/q1022/FUV/q1022_fuv_all.f26')

cond = q1022.lines.name == 'H I   '
a = q1022.lines[cond]

a.name[:] = 'HI'

writetxt('/home/ntejos/catalogs/Q1022/HI.txt',[a.name,a.z,a.zsig,a.b,a.bsig,a.logN,a.logNsig])
Exemple #9
0
def process_options(args):
    opt = adict()
    filename = os.path.abspath(__file__).rsplit('/', 1)[0] + '/default.cfg'
    opt = parse_config(filename)
    if os.path.lexists('./plot.cfg'):
        opt = parse_config('./plot.cfg', opt)

    opt.atom = readatom(molecules=True)

    if opt.Rfwhm is not None:
        if isinstance(opt.Rfwhm, basestring):
            if opt.Rfwhm == 'convolve_with_COS_FOS':
                if convolve_with_COS_FOS is None:
                    raise ValueError('convolve_with_COS_FOS() not available')
                print('Using tailored FWHM for COS/FOS data')
                opt.Rfwhm = 'convolve_with_COS_FOS'
            elif opt.Rfwhm.endswith('fits'):
                print('Reading Resolution FWHM from', opt.Rfwhm)
                res = readtabfits(opt.Rfwhm)
                opt.Rfwhm = res.res / 2.354
            else:
                print('Reading Resolution FWHM from', opt.Rfwhm)
                fh = open(opt.Rfwhm)
                opt.Rfwhm = 1 / 2.354 * np.array([float(r) for r in fh])
                fh.close()
        else:
            opt.Rfwhm = float(opt.Rfwhm)

    if opt.features is not None:
        print('Reading feature list from', opt.features)
        opt.features = readtabfits(opt.features)

    if opt.f26 is not None:
        name = opt.f26
        print('Reading ions and fitting regions from', name)
        opt.f26 = readf26(name)
        opt.f26.filename = name

    if opt.transitions is not None:
        print('Reading transitions from', opt.transitions)
        fh = open(opt.transitions)
        trans = list(fh)
        fh.close()
        temp = []
        for tr in trans:
            tr = tr.strip()
            if tr and not tr.startswith('#'):
                junk = tr.split()
                tr = junk[0] + ' ' + junk[1]
                t = findtrans(tr, atomdat=opt.atom)
                temp.append(dict(name=t[0], wa=t[1][0], tr=t[1]))
        opt.linelist = temp
    else:
        opt.linelist = readtxt(get_data_path() + 'linelists/qsoabs_lines',
                        names='wa,name,select')

    if opt.f26 is None and opt.taulines is not None:
        print('Reading ions from', opt.taulines)
        fh = open(opt.taulines)
        lines = []
        for row in fh:
            if row.lstrip().startswith('#'):
                continue
            items = row.split()
            lines.append([items[0]] + list(map(float, items[1:])))
        fh.close()
        opt.lines = lines

    if opt.show_regions is None:
        opt.show_regions = True

    if hasattr(opt, 'aodname'):
        opt.aod = Table.read(opt.aodname)

    return opt
Exemple #10
0
 def refresh_f26(self):
     name = self.opt.f26.filename
     print 're-reading from', name
     self.opt.f26 = readf26(name)
     self.opt.f26.filename = name
Exemple #11
0
from barak.pyvpfit import readf26
from barak.absorb import findtrans, readatom, find_tau
from barak.constants import c_kms
from barak.spec import make_constant_dv_wa_scale, convolve_constant_dv
from barak.convolve import convolve_psf

import pylab as pl
import numpy as np

f26 = readf26(f26name)
atomdat = readatom(molecules=1)
spfilename = ''
trfilename = ''
vmin = vmax = 399
wadiv = None
Rfwhm = 6.6
osc = False
residuals = True
redshift = 0.56

unrelated = []
#         ( 3863.451, 3865.529), 
#         ( 3855.399, 3859.330), 
#         ( 4075.662, 4076.668), 
#         ( 4079.430, 4082.960), 
#         ( 3906.116, 3908.287), 
#         ( 3898.097, 3899.218), 
#         ( 4509.955, 4512.281), 
#         ( 4503.099, 4507.387), 
#         ( 4532.218, 4544.106), 
#         ( 4314.625, 4315.922), 
from barak.pyvpfit import readf26
from astro.io import writetxt

q0107a = readf26('/home/ntejos/catalogs/Q0107/A.f26')
q0107b = readf26('/home/ntejos/catalogs/Q0107/B.f26')
q0107c = readf26('/home/ntejos/catalogs/Q0107/C.f26')

cond = q0107a.lines.name == 'H I   '
a = q0107a.lines[cond]
cond = q0107b.lines.name == 'H I   '
b = q0107b.lines[cond]
cond = q0107c.lines.name == 'H I   '
c = q0107c.lines[cond]

a.name[:] = 'HI'
b.name[:] = 'HI'
c.name[:] = 'HI'

writetxt('/home/ntejos/catalogs/Q0107/A_HI.txt',
         [a.name, a.z, a.zsig, a.b, a.bsig, a.logN, a.logNsig])
writetxt('/home/ntejos/catalogs/Q0107/B_HI.txt',
         [b.name, b.z, b.zsig, b.b, b.bsig, b.logN, b.logNsig])
writetxt('/home/ntejos/catalogs/Q0107/C_HI.txt',
         [c.name, c.z, c.zsig, c.b, c.bsig, c.logN, c.logNsig])
Exemple #13
0
    'NV 1238': [(90 + vzero, 200 + vzero), (280 + vzero, 403 + vzero)],
    'OVI 1031': [(-500, -360), (-100, -20), (45, 200)],
    'OVI 1037': [(-500, -290), (-100, +45), (70, 200)],
}

cfg = parse_config(config)
transitions = read_transitions(cfg.trfilename, ATOMDAT)

if 1:
    sp = barak.spec.read(cfg.spfilename)
    ndiv = 4.
    wa_dv = make_constant_dv_wa_scale(sp.wa[0], sp.wa[-1], cfg.Rfwhm / ndiv)

    expand_cont_adjustment = 5

    vp = readf26(cfg.f26name)
    lines = vp.lines[vp.lines.name != '<>']
    tau, ticks, alltau = find_tau(sp.wa, lines, ATOMDAT, per_trans=1)
    model = convolve_constant_dv(sp.wa, np.exp(-tau), wa_dv, ndiv)
    models = [
        convolve_constant_dv(sp.wa, np.exp(-t), wa_dv, ndiv) for t in alltau
    ]
    adjust = [l for l in vp.lines if l['name'].strip() == '<>']
    print 'Nadjust', adjust
    if len(adjust) > 0:
        regions = vp.regions
        isort = regions.wmin.argsort()
        print 'Applying continuum adjustments for', len(adjust), 'regions'
        for val in adjust:
            wav0 = ATOMDAT['<>'].wa[0] * (1 + val['z'])
            i0 = regions.wmin[isort].searchsorted(wav0)