def writelinepars(fitpars, fiterrors, parinfo, specfile, outfilename, linecmts=None): ''' Write fit parameters out to file. Parameters ---------- fitpars : list of lists Parameters for fit ready for fitter! fiterrors : array of numpy vectors Error array for the fitting initialized to '0' for each param parinfo : array of arrays Flags to be used in fit specfile : str Name of the input file containing the spectrum outfilename : str Parameter output filename linecmts : list of lists, optional Reliability flags and comments, e.g., from igmguesses ''' import os ### Set outputs and open files bigfiletowrite = cfg.largeVPparfile filetowrite = outfilename if os.path.isfile(filetowrite): VPparfile = open(filetowrite, 'wb') bigparfile = open(bigfiletowrite, 'ab') # Append to the running list else: VPparfile = open(filetowrite, 'wb') bigparfile = open(bigfiletowrite, 'wb') ### Prep header of line parameter file if linecmts is not None: header = b'specfile|restwave|zsys|col|sigcol|bval|sigbval|vel|sigvel|nflag|bflag|vflag|vlim1|vlim2|wobs1|wobs2|pix1|pix2|z_comp|trans|rely|comment \n' else: header = b'specfile|restwave|zsys|col|sigcol|bval|sigbval|vel|sigvel|nflag|bflag|vflag|vlim1|vlim2|wobs1|wobs2|pix1|pix2|z_comp|trans \n' VPparfile.write(header) bigparfile.write(header) ### Grab parameters/info for each line for i in range(len(fitpars[0])): zline = fitpars[3][i] vlim1 = fitpars[5][i] vlim2 = fitpars[6][i] restwave = fitpars[0][i] wobs1 = restwave * (1 + zline + vlim1 / 299792.458) wobs2 = restwave * (1 + zline + vlim2 / 299792.458) pix1 = jbg.closest(cfg.wave, wobs1) pix2 = jbg.closest(cfg.wave, wobs2) trans = atomicdata.lam2ion(fitpars[0][i]) z_comp = ltu.z_from_dv(fitpars[4][i] * u.km / u.s, zline) if linecmts is not None: towrite = jbg.pipedelimrow([ specfile, restwave, round(zline, 5), round(fitpars[1][i], 3), round(fiterrors[1][i], 3), round(fitpars[2][i], 3), round(fiterrors[2][i], 3), round(fitpars[4][i], 3), round(fiterrors[4][i], 3), parinfo[1][i], parinfo[2][i], parinfo[4][i], vlim1, vlim2, wobs1, wobs2, pix1, pix2, round(z_comp, 5), trans, linecmts[0][i], linecmts[1][i] ]) else: towrite = jbg.pipedelimrow([ specfile, restwave, round(zline, 5), round(fitpars[1][i], 3), round(fiterrors[1][i], 3), round(fitpars[2][i], 3), round(fiterrors[2][i], 3), round(fitpars[4][i], 3), round(fiterrors[4][i], 3), parinfo[1][i], parinfo[2][i], parinfo[4][i], vlim1, vlim2, wobs1, wobs2, pix1, pix2, round(z_comp, 5), trans ]) VPparfile.write(towrite.encode()) bigparfile.write(towrite.encode()) VPparfile.close() bigparfile.close() print('Line parameters written to:') print(filetowrite)
def writelinepars(fitpars,fiterrors,parinfo, specfile, outfilename, linecmts=None): ''' Write fit parameters out to file. Parameters ---------- fitpars : list of lists Parameters for fit ready for fitter! fiterrors : array of numpy vectors Error array for the fitting initialized to '0' for each param parinfo : array of arrays Flags to be used in fit specfile : str Name of the input file containing the spectrum outfilename : str Parameter output filename linecmts : list of lists, optional Reliability flags and comments, e.g., from igmguesses ''' import os ### Set outputs and open files bigfiletowrite = cfg.largeVPparfile filetowrite = outfilename if os.path.isfile(filetowrite): VPparfile = open(filetowrite, 'wb') bigparfile = open(bigfiletowrite, 'ab') # Append to the running list else: VPparfile = open(filetowrite, 'wb') bigparfile = open(bigfiletowrite, 'wb') ### Prep header of line parameter file if linecmts is not None: header = 'specfile|restwave|zsys|col|sigcol|bval|sigbval|vel|sigvel|nflag|bflag|vflag|vlim1|vlim2|wobs1|wobs2|pix1|pix2|z_comp|trans|rely|comment \n' else: header = 'specfile|restwave|zsys|col|sigcol|bval|sigbval|vel|sigvel|nflag|bflag|vflag|vlim1|vlim2|wobs1|wobs2|pix1|pix2|z_comp|trans \n' VPparfile.write(header) bigparfile.write(header) ### Grab parameters/info for each line for i in range(len(fitpars[0])): zline = fitpars[3][i] vlim1 = fitpars[5][i] vlim2 = fitpars[6][i] restwave = fitpars[0][i] wobs1 = restwave * (1 + zline + vlim1 / 299792.458) wobs2 = restwave * (1 + zline + vlim2 / 299792.458) pix1 = jbg.closest(cfg.wave, wobs1) pix2 = jbg.closest(cfg.wave, wobs2) trans = atomicdata.lam2ion(fitpars[0][i]) z_comp = ltu.z_from_dv(fitpars[4][i]*u.km/u.s, zline) if linecmts is not None: towrite = jbg.pipedelimrow( [specfile, restwave, round(zline, 5), round(fitpars[1][i], 3), round(fiterrors[1][i], 3), round(fitpars[2][i], 3), round(fiterrors[2][i], 3), round(fitpars[4][i], 3), round(fiterrors[4][i], 3), parinfo[1][i], parinfo[2][i], parinfo[4][i], vlim1, vlim2, wobs1, wobs2, pix1, pix2,round(z_comp, 5), trans, linecmts[0][i],linecmts[1][i]]) else: towrite = jbg.pipedelimrow( [specfile, restwave, round(zline, 5), round(fitpars[1][i], 3), round(fiterrors[1][i], 3), round(fitpars[2][i], 3), round(fiterrors[2][i], 3), round(fitpars[4][i], 3), round(fiterrors[4][i], 3), parinfo[1][i], parinfo[2][i], parinfo[4][i], vlim1, vlim2, wobs1, wobs2, pix1, pix2, round(z_comp, 5),trans]) VPparfile.write(towrite) bigparfile.write(towrite) VPparfile.close() bigparfile.close() print('Line parameters written to:') print(filetowrite)