def calc_model(self): lines = lines_from_f26(self.opt.f26) wa = self.spec[self.i].wa dw = np.median(np.diff(wa)) print 'finding tau' if self.opt.wadiv is not None: dw1 = dw / self.opt.wadiv wa1 = np.arange(wa[0], wa[-1] + 0.5 * dw1, dw1) tau, ticks = find_tau(wa1, lines, self.opt.atom, logNthresh_LL=self.opt.logNthresh_LL) else: tau, ticks = find_tau(wa, lines, self.opt.atom, logNthresh_LL=self.opt.logNthresh_LL) model = np.exp(-tau) # if we want to calculate the optical depth per line, # do it here. if self.opt.wadiv is not None: model, _ = process_Rfwhm(self.opt.Rfwhm, wa1, model, []) else: model, _ = process_Rfwhm(self.opt.Rfwhm, wa, model, []) if self.opt.wadiv is not None: model = np.interp(wa, wa1, model) self.models[self.i] = model self.ticks = ticks self.model = model
def calc_model(self): lines = lines_from_f26(self.opt.f26) lines = [l for l in lines if l[0] not in ('__', '<>')] wa = self.spec[self.i].wa dw = np.median(np.diff(wa)) print('finding tau') if self.opt.wadiv is not None: dw1 = dw / self.opt.wadiv wa1 = np.arange(wa[0], wa[-1] + 0.5 * dw1, dw1) tau, ticks = find_tau(wa1, lines, self.opt.atom, logNthresh_LL=self.opt.logNthresh_LL) else: tau, ticks = find_tau(wa, lines, self.opt.atom, logNthresh_LL=self.opt.logNthresh_LL) model = np.exp(-tau) # if we want to calculate the optical depth per line, # do it here. if self.opt.wadiv is not None: model, _ = process_Rfwhm(self.opt.Rfwhm, wa1, model, []) else: model, _ = process_Rfwhm(self.opt.Rfwhm, wa, model, []) if self.opt.wadiv is not None: model = np.interp(wa, wa1, model) #self.apply_zero_offsets() self.models[self.i] = model self.ticks = ticks self.model = model
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
'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) #print i0, i1 #import pdb; pdb.set_trace()
if 1: linelist = read_transitions(trfilename) ntrans = len(linelist) sp = barak.spec.read(spfilename) wa = sp.wa nfl = sp.fl / sp.co ner = sp.fl / sp.co edges = barak.spec.find_wa_edges(wa) # pixel edges dwa = edges[1:] - edges[:-1] # width per pixel dw = np.median(dwa) if wadiv is not None: dw1 = dw / wadiv wa1 = np.arange(wa[0], wa[-1]+0.5*dw1, dw1) tau, ticks = find_tau(wa1, f26.lines, atomdat) else: tau, ticks = find_tau(wa, f26.lines, atomdat) model = np.exp(-tau) models = [] #models = [np.exp(-t) for t in taus] if wadiv is not None: model, models = process_Rfwhm(Rfwhm, wa1, model, models) else: model, models = process_Rfwhm(Rfwhm, wa, model, models) if wadiv is not None: model = np.interp(wa, wa1, model)
'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) #print i0, i1
pl.rc('font', size=12.5) if 1: sp = barak.spec.read('fos_colo2.txt') sp.fl *= 1e16 sp.co *= 1e16 sp.er *= 1e16 #sp = barak.spec.read('../vpfit_COS/qsoc_G190H.txt') wa = sp.wa + 0.2 dw = np.median(np.diff(sp.wa)) # resolution seems to be 0.8 expected value? Or sign of lower N # comoponents in wings? npix = 1.39 / dw * 0.8 tau, ticks = find_tau(wa, lines, atom) taulo, ticks = find_tau(wa, lineslo, atom) tauhi, ticks = find_tau(wa, lineshi, atom) fig = pl.figure(figsize=(4.3, 3)) fig.subplots_adjust(bottom=0.16, left=0.16, right=0.98, top=0.96) ax = fig.add_subplot(111) ax.plot(wa, sp.fl,color='0.3', lw=0.5,drawstyle='steps-mid') ax.plot(wa, sp.co, '0.7', ls='dashed') ax.plot(wa, sp.co*convolve_psf(np.exp(-taulo), npix), 'r', lw=0.3) ax.plot(wa, sp.co*convolve_psf(np.exp(-tau), npix), 'r') ax.plot(wa, sp.co*convolve_psf(np.exp(-tauhi), npix), 'r', lw=0.3) ax.axhline(0, color='k', lw=0.3)