def readLSF(grating, dw_new=None): """ Read the COS line spread function, optionally interpolated to a new pixel width. Parameters ---------- grating : str, {'G130M', 'G160M', 'NUV'} Either 'NUV' for all near UV gratings, or the name of the far UV COS grating. dw_new : float The new pixel width in Angstroms. Default is `None`, which returns the original LSF. Returns ------- LSF, wa : ndarrays of shape (N,) The new LSF and the wavelength offsets from the line centre. """ # see if we've already calculated it try: #print grating, dw, 'cached!' return cacheLSF[grating, dw_new] except KeyError: pass oldLSF = readtxt(datapath + '/LSF/%s.txt' % grating, readnames=1) dw_orig = dict(G130M=0.00997, G160M=0.01223, NUV=0.390) wa0 = oldLSF.relpix * dw_orig[grating] if dw_new is None: return oldLSF, wa0 t = np.arange(0, wa0[-1], dw_new) wa1 = np.concatenate([-t[::-1][:-1], t]) wavs = oldLSF.dtype.names[1:] newLSF = [] for w in wavs: newLSF.append(interp_spline(wa1, wa0, oldLSF[w])) t = np.arange(len(wa1) // 2 + 1) newpix = np.concatenate([-t[::-1][:-1], t]) #import pdb; pdb.set_trace() newLSF = np.rec.fromarrays([newpix] + newLSF, names=oldLSF.dtype.names) cacheLSF[grating, dw_new] = newLSF, wa1 return newLSF, wa1
def readLSF(grating, dw_new=None): """ Read the COS line spread function, optionally interpolated to a new pixel width. Parameters ---------- grating : str, {'G130M', 'G160M', 'NUV'} Either 'NUV' for all near UV gratings, or the name of the far UV COS grating. dw_new : float The new pixel width in Angstroms. Default is `None`, which returns the original LSF. Returns ------- LSF, wa : ndarrays of shape (N,) The new LSF and the wavelength offsets from the line centre. """ # see if we've already calculated it try: #print grating, dw, 'cached!' return cacheLSF[grating, dw_new] except KeyError: pass oldLSF = readtxt(datapath + '/LSF/%s.txt' % grating, readnames=1) dw_orig = dict(G130M=0.00997, G160M=0.01223, NUV=0.390) wa0 = oldLSF.relpix * dw_orig[grating] if dw_new is None: return oldLSF, wa0 t = np.arange(0, wa0[-1], dw_new) wa1 = np.concatenate([-t[::-1][:-1], t]) wavs = oldLSF.dtype.names[1:] newLSF = [] for w in wavs: newLSF.append(interp_spline(wa1, wa0, oldLSF[w])) t = np.arange(len(wa1)//2 + 1) newpix = np.concatenate([-t[::-1][:-1], t]) #import pdb; pdb.set_trace() newLSF = np.rec.fromarrays([newpix] + newLSF, names=oldLSF.dtype.names) cacheLSF[grating, dw_new] = newLSF, wa1 return newLSF, wa1
def read_cuba(filename): """ Parse a Haart & Madau CUBA file. return jnu as a function of wavelength and redshift. Removes duplicate wavelength points. Returns ------- redshifts : array of floats with shape (N,) wa : array of floats with shape (M,) Wavelengths in Angstroms. jnu : array of floats with shape (N, M) Flux in erg/s/Hz/cm^2/sr. """ # first read the redshifts fh = open(filename) for row in fh: r = row.strip() if not r or r.startswith('#'): continue redshifts = np.array(map(float, r.split())) break # then the wavelenths and fnu values cols = readtxt(filename, skip=1) assert len(cols) == len(redshifts) + 1 wa = cols[0] jnu = np.array(cols[1:]) # remove duplicates _, iuniq = np.unique(wa, return_index=True) wa1 = wa[iuniq] jnu1 = jnu[:, iuniq] return redshifts, wa1, jnu1
from barak.io import readtxt from .io import readtxt from collections import OrderedDict datapath = get_data_path() Asolar = OrderedDict( (t['el'], t['A']) for t in ascii.read(datapath + 'abundances/SolarAbundance.txt')) Asolar_c13 = OrderedDict( (t['el'], t['A']) for t in ascii.read(datapath + 'abundances/SolarAbundance_c13.02.txt')) cond_temp = readtxt(datapath + 'abundances/CondensationTemperatures.txt', readnames=1, sep='|') # Mass fractions of H (X), He (Y) and metals (Z) below are from Asplund et # al. 2009ARA&A..47..481A, table 4. protosolar = dict(X=0.7381, Y=0.2485, Z=0.0134, ZonX=0.0181) photosphere = dict(X=0.7154, Y=0.2703, Z=0.0142, ZonX=0.0199) def calc_abund(X, Y, logNX, logNY, ref='Lodders03'): """ Find the abundance relative to solar given two elements and their column densities. Parameters ---------- X, Y : str
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
def read_Danforth14(filename, keywords=['RA_TARG', 'DEC_TARG']): """Reads the special format of Danforth+14 on IGM ('igm-systems' style) catalos from HST/COS. Inputs: filename: name of the file keywords: list of keywords to retrieve appart from data. e.g. ['RA_TARG','DEC_TARG'] Return: Astropy Table with original data + new columns having the given keywords. Example of file content from Danforth+14 IGM catalogs: #SIMPLE = T #XTENSION= 'BINTABLE' #BITPIX = 8 / 8-bit bytes. #NAXIS = 2 / 2-dimensional table. #NAXIS1 = 64 / Width of table in bytes. #NAXIS2 = 62 / Number of rows in table. #PCOUNT = 0 /Random parameter count #GCOUNT = 1 /Group count #TELESCOP= 'HST' / Observatory name. #INSTRUME= 'COS' / Instrument name. #RADESYS = 'FK5' / Astrometric reference system. #EQUINOX = 2000. / Equinox of the coordinates. #TARGNAME = '1ES1028+511' / Sight line name. #TARGROOT = '1es1028' / 7-character sight line id. #RA_TARG = 157.82708333 / RA of the target [deg]. #DEC_TARG = 50.89333333 / DEC of the target [deg]. #TARG_ZEM = 0.36040300 / Nominal emission redshift. #DATE-OBS = '2011-05-01' / Approximate date of first observation [YYYY-MM-DD]. #HLSPLEAD = 'Charles Danforth' / HLSP Lead. #CITATION = 'Danforth, et al. 2014, ApJ, XXX:XXX' / Reference for HLSP methodology. #PR_INV_L = 'Danforth' / PI Last Name. #PR_INV_F = 'Charles' / PI First Name. #AIRORVAC = 'VAC ' / Are wavelengths in air or vacuum? #FILTER01 = 'G130M' / Filter used in coadd. #FILTER02 = 'G160M' / Filter used in coadd. #EXPTIME1 = 14651 / Max exposure time in Filter 1 [sec]. #EXPTIME2 = 14606 / Max exposure time in Filter 2 [sec]. #SN_RES_1 = 20 / Median S/N per 7-pixel resel in Filter 1. #SN_RES_2 = 12 / Median S/N per 7-pixel resel in Filter 2. #TFIELDS = 16 / Number of fields in each row. #TTYPE1 = 'Z_SYS' / 1: system redshift #TFORM1 = '1E' #TTYPE2 = 'DELTAV_SYS' / 2: system velocity half-width #TFORM2 = '1E' #TUNIT2 = 'km/s' #TTYPE3 = 'WAVELENGTH' / 3: Observed wavelength #TFORM3 = '1E' #TUNIT3 = 'Ang' #TTYPE4 = 'LINE_ID' / 4: Line ID #TFORM4 = '10A' #TTYPE5 = 'z_ABS' / 5: Line redshift #TFORM5 = '1E' #TTYPE6 = 'SIGLEVEL ' / 6: Line Significance Level #TFORM6 = '1E' #TUNIT6 = 'SIGMA' #TTYPE7 = 'S/N ' / 7: Local S/N per resel #TFORM7 = '1E' #TTYPE8 = 'EQW ' / 8: Line Equiv. Width #TFORM8 = '1J' #TUNIT8 = 'mAA' #TTYPE9 = 'EQW_ERR' / 9: Equiv Width error #TFORM9 = '1J' #TUNIT9 = 'mAA' #TTYPE10 = 'BVALUE' / 10: Line b-value #TFORM10 = '1E' #TUNIT10 = 'km/s' #TTYPE11 = 'BVALUE_ERR' / 11: b-value error #TFORM11 = '1E' #TUNIT11 = 'km/s' #TTYPE12 = 'LOGN' / 12: line log column density #TFORM12 = '1E' #TUNIT12 = 'log cm^-2' #TTYPE13 = 'LOGN_ERR' / 13: log column density error #TFORM13 = '1E' #TUNIT13 = 'log cm^-2' #TTYPE14 = 'FLAG_FIT' / 14: line fit quality concerns? #TFORM14 = '1I' #TTYPE15 = 'NUM_SYS_LINES' / 15: number of lines in system #TFORM15 = '1I' #TTYPE16 = 'NUM_METAL_LINES' / 16: number of metal lines in system #TFORM16 = '1I' #COMMENT #COMMENT 'Generated Fri Jan 17 15:09:22 2014' #COMMENT 'Delivered to MAST from the COS Sight Lines HLSP project' #END 0.002435 40.0 1218.61 "Lya 1215" 0.002435 3.2 3.0 81 2 22.1 1.0 13.27 0.01 1 1 0 0.003204 65.0 1219.57 "Lya 1215" 0.003225 10.3 3.0 266 3 23.4 1.0 14.18 0.01 1 2 1 0.003204 65.0 1553.07 "CIV 1548" 0.003141 3.9 6.0 88 14 36.9 10.9 13.39 0.09 1 2 1 0.021890 39.0 1242.26 "Lya 1215" 0.021890 8.7 10.0 83 23 27.0 4.2 13.26 0.10 0 1 0 0.022580 39.0 1243.10 "Lya 1215" 0.022580 6.7 10.0 86 11 50.6 8.3 13.24 0.05 0 1 0 0.044865 39.0 1270.19 "Lya 1215" 0.044865 11.3 10.0 157 36 57.1 5.1 13.52 0.09 1 1 0 0.050985 48.0 1277.63 "Lya 1215" 0.050985 23.0 9.0 206 13 23.1 1.5 13.89 0.03 0 1 0 0.051399 38.0 1278.13 "Lya 1215" 0.051399 3.5 9.0 32 17 18.1 8.0 12.82 0.10 1 1 0 0.080392 37.0 1313.38 "Lya 1215" 0.080392 4.3 7.0 41 23 9.6 23.5 13.00 0.20 0 1 0 0.083274 37.0 1316.88 "Lya 1215" 0.083274 4.5 7.0 126 68 100.0 1.0 13.40 0.23 1 1 0 0.088340 37.0 1323.04 "Lya 1215" 0.088340 6.5 7.0 105 46 36.6 6.0 13.36 0.16 0 1 0 0.094355 37.0 1330.35 "Lya 1215" 0.094355 9.6 8.0 124 28 29.8 3.1 13.47 0.09 1 1 0 """ # import convinience from barak.io import readtxt #open file f = open(filename) #to store keyword values values = dict() #to store column names colnames = [] while True: line = f.readline() words = line.split() if (words[0][0] != '#') or (len(keywords) == 0): break #read keyword values for keyword in keywords: if words[0][1:] == keyword: try: values[keyword] = float( words[2]) #store the value of keyword except: values[keyword] = words[2][1: -1] #store the value of keyword #read colnames if words[0][1:].startswith('TTYPE'): name = words[2][1:-1] if name == 'S/': name = 'SN' elif name == 'EQ': name = 'EQW' elif name == 'SIGLEVE': name = 'SIGLEVEL' colnames = colnames + [name] #store colname if name == 'LINE_ID': #this is to account for the #fact that "Lya 1215" is #read as two columns later: #'"Lya' and '1215"' colnames = colnames + ['LINE_ID_WAVELENGTH'] f.close() #read content data = readtxt(filename, comment='#', names=colnames) #clean excess of " in data accosiated to 'LINE_ID' and #'LINE_ID_WAVELENGTH' try: aux = data['LINE_ID'] aux = np.array([aux[i][1:] for i in range(len(aux))]) data['LINE_ID'] = aux aux = data['LINE_ID_WAVELENGTH'] aux = np.array([aux[i][:-1] for i in range(len(aux))]) data['LINE_ID_WAVELENGTH'] = aux except: pass #use data in astropy.table Table format data = Table(data) #add columns for each keyword for key in values.keys(): aux = [values[key] for i in range(len(data))] aux = Column(name=key, data=aux) data.add_column(aux) return data
import numpy as np from barak.io import readtxt from StringIO import StringIO """ z1 0.5571716 3.3328989e-06 2.9235276e-06 6.1819434e-06 5.8875732e-06 z2 0.55731413 6.9815339e-06 5.6234853e-07 1.0778247e-05 3.907031e-06 """ vals = readtxt(StringIO("""\ N1 15.980229 0.051283581 0.44173713 0.25458389 0.78321895 b1 7.1385398 1.0740454 0.099691753 1.6881329 0.62992256 N2 15.401429 0.15744999 0.61836035 0.28957997 1.4460613 b2 4.4966749 0.88646246 0.50331688 2.491544 1.4914935 N3 16.86705 0.093238909 0.46774437 0.31209545 0.72591071 N4 16.467646 0.45228955 0.35720928 0.66221697 0.96223281 N5 16.184167 0.18668953 0.19701228 0.24673393 0.54682153 N6 15.640367 0.2410867 0.25817481 0.31882251 1.6768936 N7 15.686983 0.030926233 0.19910952 0.11180025 0.39515113 N8 15.398693 0.10942594 0.24660601 0.18772311 1.7104885 """), names='name,logN,siglo,sighi,sig2lo,sig2hi') # old # vals = readtxt(StringIO("""\ # N1 16.92 0.6101 0.07884 0.9654 0.3432 # b1 4.314 0.1769 0.7664 0.4878 1.713 # N2 15.26 0.1464 0.3157 0.3125 1.7 # b2 7.421 1.328 0.004784 4.99 0.5069 # N3 17.52 0.6729 0.042 1.078 0.1888 # N4 16.22 0.1401 0.6071 0.2793 1.8
rmin = 0 rmax = 20. rwidth = 0.5 rbinedges = np.arange(rmin, rmax+0.5*rwidth, rwidth) rcbins = 0.5*(rbinedges[:-1] + rbinedges[1:]) # for transverse bins tmin = 0 tmax = 30. twidth = 0.5 tbinedges = np.arange(tmin, tmax+0.5*twidth, twidth) tcbins = 0.5*(tbinedges[:-1] + tbinedges[1:]) #read absorbers names = 'ION,ZABS,ZABS_ERR,B,B_ERR,LOGN,LOGN_ERR' q1005 = readtxt('/home/ntejos/catalogs/Finn_2012/q1005_fuv_HI.sort',names=names) q0209 = readtxt('/home/ntejos/catalogs/Finn_2012/q0209_fuv_HI.sort',names=names) q1357 = readtxt('/home/ntejos/catalogs/Finn_2012/q1357_fuv_HI.sort',names=names) q0107a = readtxt('/home/ntejos/catalogs/Q0107/A_HI.txt',names=names) q0107b = readtxt('/home/ntejos/catalogs/Q0107/B_HI.txt',names=names) q0107c = readtxt('/home/ntejos/catalogs/Q0107/C_HI.txt',names=names) q1022 = readtxt('/home/ntejos/catalogs/J1022/HI.txt',names=names) #read spectrum names = 'wa,fl,er,norm' q1005_fuv = readtxt('/home/ntejos/COS/q1005/FUV/q1005_fuv_norm.txt',names=names) #append RA and DEC fields to QSO sightlines radec = s2dec('10 05 35.24','01 34 45.7') q1005 = rf.rec_append_fields(q1005,'RA' ,radec[0]*np.ones(len(q1005)))
# The use of IGMtransmission should be acknowledged using a statement # like This paper computed IGM transmission values using # IGMtransmissiona (Harrison, Meiksin & Stock 2011), based on the # transmission curves of Meiksin (2006). aAvailable for download from # http://code.google.com/p/igmtransmission If the LLS distribution # from Inoue & Iwata (2008) is used, a reference to their work should # be added as well. from barak.io import readtxt import numpy as np # z=2.76, Inoue LLS code. Diffuse IGM normalisation 0.07553 T = readtxt("averageTransmission.dat", names="wa,tr") WA = np.arange(3180, 8000, 1.0) TR = np.interp(WA, T.wa, T.tr) TR[WA > 4543.0] = 1 from barak.sed import get_bands u, g = get_bands("sdss", ["u", "g"]) utr = np.interp(WA, u.wa, u.tr) av_utr = (utr * TR).sum() / utr.sum() print "u bandpass-weighted transmission", av_utr print "mag extinct", -2.5 * np.log10(av_utr) gtr = np.interp(WA, g.wa, g.tr) av_gtr = (gtr * TR).sum() / gtr.sum() print "g bandpass-weighted transmission", av_gtr print "mag extinct", -2.5 * np.log10(av_gtr)
# The use of IGMtransmission should be acknowledged using a statement # like This paper computed IGM transmission values using # IGMtransmissiona (Harrison, Meiksin & Stock 2011), based on the # transmission curves of Meiksin (2006). aAvailable for download from # http://code.google.com/p/igmtransmission If the LLS distribution # from Inoue & Iwata (2008) is used, a reference to their work should # be added as well. from barak.io import readtxt import numpy as np # z=2.76, Inoue LLS code. Diffuse IGM normalisation 0.07553 T = readtxt('averageTransmission.dat', names='wa,tr') WA = np.arange(3180, 8000, 1.) TR = np.interp(WA, T.wa, T.tr) TR[WA > 4543.] = 1 from barak.sed import get_bands u, g = get_bands('sdss', ['u', 'g']) utr = np.interp(WA, u.wa, u.tr) av_utr = (utr * TR).sum() / utr.sum() print 'u bandpass-weighted transmission', av_utr print 'mag extinct', -2.5 * np.log10(av_utr) gtr = np.interp(WA, g.wa, g.tr) av_gtr = (gtr * TR).sum() / gtr.sum() print 'g bandpass-weighted transmission', av_gtr print 'mag extinct', -2.5 * np.log10(av_gtr)
def read_Danforth14(filename,keywords=['RA_TARG','DEC_TARG']): """Reads the special format of Danforth+14 on IGM ('igm-systems' style) catalos from HST/COS. Inputs: filename: name of the file keywords: list of keywords to retrieve appart from data. e.g. ['RA_TARG','DEC_TARG'] Return: Astropy Table with original data + new columns having the given keywords. Example of file content from Danforth+14 IGM catalogs: #SIMPLE = T #XTENSION= 'BINTABLE' #BITPIX = 8 / 8-bit bytes. #NAXIS = 2 / 2-dimensional table. #NAXIS1 = 64 / Width of table in bytes. #NAXIS2 = 62 / Number of rows in table. #PCOUNT = 0 /Random parameter count #GCOUNT = 1 /Group count #TELESCOP= 'HST' / Observatory name. #INSTRUME= 'COS' / Instrument name. #RADESYS = 'FK5' / Astrometric reference system. #EQUINOX = 2000. / Equinox of the coordinates. #TARGNAME = '1ES1028+511' / Sight line name. #TARGROOT = '1es1028' / 7-character sight line id. #RA_TARG = 157.82708333 / RA of the target [deg]. #DEC_TARG = 50.89333333 / DEC of the target [deg]. #TARG_ZEM = 0.36040300 / Nominal emission redshift. #DATE-OBS = '2011-05-01' / Approximate date of first observation [YYYY-MM-DD]. #HLSPLEAD = 'Charles Danforth' / HLSP Lead. #CITATION = 'Danforth, et al. 2014, ApJ, XXX:XXX' / Reference for HLSP methodology. #PR_INV_L = 'Danforth' / PI Last Name. #PR_INV_F = 'Charles' / PI First Name. #AIRORVAC = 'VAC ' / Are wavelengths in air or vacuum? #FILTER01 = 'G130M' / Filter used in coadd. #FILTER02 = 'G160M' / Filter used in coadd. #EXPTIME1 = 14651 / Max exposure time in Filter 1 [sec]. #EXPTIME2 = 14606 / Max exposure time in Filter 2 [sec]. #SN_RES_1 = 20 / Median S/N per 7-pixel resel in Filter 1. #SN_RES_2 = 12 / Median S/N per 7-pixel resel in Filter 2. #TFIELDS = 16 / Number of fields in each row. #TTYPE1 = 'Z_SYS' / 1: system redshift #TFORM1 = '1E' #TTYPE2 = 'DELTAV_SYS' / 2: system velocity half-width #TFORM2 = '1E' #TUNIT2 = 'km/s' #TTYPE3 = 'WAVELENGTH' / 3: Observed wavelength #TFORM3 = '1E' #TUNIT3 = 'Ang' #TTYPE4 = 'LINE_ID' / 4: Line ID #TFORM4 = '10A' #TTYPE5 = 'z_ABS' / 5: Line redshift #TFORM5 = '1E' #TTYPE6 = 'SIGLEVEL ' / 6: Line Significance Level #TFORM6 = '1E' #TUNIT6 = 'SIGMA' #TTYPE7 = 'S/N ' / 7: Local S/N per resel #TFORM7 = '1E' #TTYPE8 = 'EQW ' / 8: Line Equiv. Width #TFORM8 = '1J' #TUNIT8 = 'mAA' #TTYPE9 = 'EQW_ERR' / 9: Equiv Width error #TFORM9 = '1J' #TUNIT9 = 'mAA' #TTYPE10 = 'BVALUE' / 10: Line b-value #TFORM10 = '1E' #TUNIT10 = 'km/s' #TTYPE11 = 'BVALUE_ERR' / 11: b-value error #TFORM11 = '1E' #TUNIT11 = 'km/s' #TTYPE12 = 'LOGN' / 12: line log column density #TFORM12 = '1E' #TUNIT12 = 'log cm^-2' #TTYPE13 = 'LOGN_ERR' / 13: log column density error #TFORM13 = '1E' #TUNIT13 = 'log cm^-2' #TTYPE14 = 'FLAG_FIT' / 14: line fit quality concerns? #TFORM14 = '1I' #TTYPE15 = 'NUM_SYS_LINES' / 15: number of lines in system #TFORM15 = '1I' #TTYPE16 = 'NUM_METAL_LINES' / 16: number of metal lines in system #TFORM16 = '1I' #COMMENT #COMMENT 'Generated Fri Jan 17 15:09:22 2014' #COMMENT 'Delivered to MAST from the COS Sight Lines HLSP project' #END 0.002435 40.0 1218.61 "Lya 1215" 0.002435 3.2 3.0 81 2 22.1 1.0 13.27 0.01 1 1 0 0.003204 65.0 1219.57 "Lya 1215" 0.003225 10.3 3.0 266 3 23.4 1.0 14.18 0.01 1 2 1 0.003204 65.0 1553.07 "CIV 1548" 0.003141 3.9 6.0 88 14 36.9 10.9 13.39 0.09 1 2 1 0.021890 39.0 1242.26 "Lya 1215" 0.021890 8.7 10.0 83 23 27.0 4.2 13.26 0.10 0 1 0 0.022580 39.0 1243.10 "Lya 1215" 0.022580 6.7 10.0 86 11 50.6 8.3 13.24 0.05 0 1 0 0.044865 39.0 1270.19 "Lya 1215" 0.044865 11.3 10.0 157 36 57.1 5.1 13.52 0.09 1 1 0 0.050985 48.0 1277.63 "Lya 1215" 0.050985 23.0 9.0 206 13 23.1 1.5 13.89 0.03 0 1 0 0.051399 38.0 1278.13 "Lya 1215" 0.051399 3.5 9.0 32 17 18.1 8.0 12.82 0.10 1 1 0 0.080392 37.0 1313.38 "Lya 1215" 0.080392 4.3 7.0 41 23 9.6 23.5 13.00 0.20 0 1 0 0.083274 37.0 1316.88 "Lya 1215" 0.083274 4.5 7.0 126 68 100.0 1.0 13.40 0.23 1 1 0 0.088340 37.0 1323.04 "Lya 1215" 0.088340 6.5 7.0 105 46 36.6 6.0 13.36 0.16 0 1 0 0.094355 37.0 1330.35 "Lya 1215" 0.094355 9.6 8.0 124 28 29.8 3.1 13.47 0.09 1 1 0 """ #open file f = open(filename) #to store keyword values values = dict() #to store column names colnames = [] while True: line = f.readline() words = line.split() if (words[0][0] != '#') or (len(keywords)==0): break #read keyword values for keyword in keywords: if words[0][1:]==keyword: try: values[keyword] = float(words[2]) #store the value of keyword except: values[keyword] = words[2][1:-1] #store the value of keyword #read colnames if words[0][1:].startswith('TTYPE'): name = words[2][1:-1] if name == 'S/': name = 'SN' elif name == 'EQ': name = 'EQW' elif name == 'SIGLEVE': name = 'SIGLEVEL' colnames = colnames + [name] #store colname if name == 'LINE_ID': #this is to account for the #fact that "Lya 1215" is #read as two columns later: #'"Lya' and '1215"' colnames = colnames + ['LINE_ID_WAVELENGTH'] f.close() #read content data = readtxt(filename,comment='#',names=colnames) #clean excess of " in data accosiated to 'LINE_ID' and #'LINE_ID_WAVELENGTH' try: aux = data['LINE_ID'] aux = np.array([aux[i][1:] for i in range(len(aux))]) data['LINE_ID'] = aux aux = data['LINE_ID_WAVELENGTH'] aux = np.array([aux[i][:-1] for i in range(len(aux))]) data['LINE_ID_WAVELENGTH'] = aux except: pass #use data in astropy.table Table format data = Table(data) #add columns for each keyword for key in values.keys(): aux = [values[key] for i in range(len(data)) ] aux = Column(name=key,data=aux) data.add_column(aux) return data
1 & -112 &$-0.70\pm0.14$ &$-1.14\pm0.31$ &$-2.14\pm0.12$ &$\mathbf{14.88\pm0.01}$ &$18.18\pm0.16$ &$4.19\pm0.03$ &$-2.85\pm0.33(0.14)$&$1.33\pm0.32(0.12)$ &$-0.46\pm0.42(0.30)$ &$3.55\pm0.96(0.75)$ 2 & -84 &$-0.39\pm0.12$ &$-0.15\pm0.27$ &$-2.54\pm0.09$ &$\mathbf{15.23\pm0.01}$ &$18.02\pm0.14$ &$4.14\pm0.02$ &$-2.37\pm0.32(0.12)$&$1.78\pm0.32(0.10)$ &$-1.10\pm0.39(0.25)$ &$2.07\pm0.88(0.64)$ 3 & -30 &$-0.34\pm0.37$ &$\mathbf{-0.35\pm0.42}$ &$-1.83\pm0.19$ &$\mathbf{14.47\pm0.26}$ &$17.96\pm0.40$ &$4.24\pm0.10$ &$-3.10\pm0.38(0.23)$&$1.06\pm0.37(0.22)$ &$-0.45\pm0.65(0.57)$ &$3.40\pm1.64(1.53)$ 4 & 51 &$-0.35\pm0.11$ &$0.30\pm0.15$ &$-2.73\pm0.12$ &$\mathbf{16.43\pm0.09}$ &$18.97\pm0.17$ &$4.14\pm0.03$ &$-2.11\pm0.33(0.13)$&$2.03\pm0.32(0.12)$ &$-0.40\pm0.41(0.28)$ &$4.45\pm0.94(0.72)$ 5 & 72 &$-0.21\pm0.11$ &$0.37\pm0.14$ &$-2.70\pm0.11$ &$\mathbf{16.37\pm0.09}$ &$18.90\pm0.16$ &$4.11\pm0.03$ &$-2.15\pm0.32(0.12)$&$1.97\pm0.32(0.12)$ &$-0.42\pm0.39(0.26)$ &$4.34\pm0.89(0.66)$ 6 & 92 &$-0.26\pm0.11$ &$0.20\pm0.18$ &$-2.66\pm0.10$ &$\mathbf{16.02\pm0.10}$ &$18.62\pm0.13$ &$4.12\pm0.03$ &$-2.21\pm0.32(0.11)$&$1.91\pm0.32(0.12)$ &$-0.65\pm0.36(0.21)$ &$3.59\pm0.80(0.53)$ 7 & 235 &$-0.69\pm0.23$ &$\mathbf{0.01\pm0.38}$ &$-2.43\pm0.17$ &$\mathbf{14.70\pm0.01}$ &$17.64\pm0.25$ &$4.27\pm0.04$ &$-2.46\pm0.37(0.21)$&$1.80\pm0.35(0.17)$ &$-1.38\pm0.55(0.46)$ &$1.17\pm1.31(1.16)$ 8 & 324 &$-1.07\pm0.42$ &$\mathbf{-0.24\pm0.48}$ &$-1.63\pm0.44$ &$\mathbf{13.59\pm0.01}$ &$17.76\pm0.57$ &$4.49\pm0.12$ &$-3.34\pm0.55(0.46)$&$1.09\pm0.45(0.34)$ &$-0.22\pm1.08(1.04)$ &$3.60\pm2.71(2.64)$ """ fh = StringIO(tab) #T = readtxt(fh, sep='&', names=['comp', 'nH', 'Z', 'aUV', 'NHI', # 'U', 'T', 'NH', 'D', 'Pk']) T = readtxt(fh, sep='&', names=['comp', 'vel', 'Z', 'aUV', 'U', 'NHI', 'NH', 'T', 'nH', 'Pk', 'D', 'M']) from barak.utilities import adict V = adict() for n in ('nH', 'Z', 'aUV','NHI','NH', 'U','T','D','Pk', 'M'): V[n] = readcol(T[n]) if n == 'T': v = V[n]['val'] V[n]['erlo'] = (10**v - 10**(v - V[n]['erlo'])) / 1e3 V[n]['erhi'] = (10**(v + V[n]['erhi']) - 10**v)/ 1e3 V[n]['val'] = 10**v / 1e3 len(V.nH) # make plots dv = np.array(T['vel'])