def __init__(self, wrest, z=0., N=0., fill=True, spec_file=None): # Test for Unit raise ValueError('DEPRECATED!! Use AbsLine in lines_utils.py') #xdb.set_trace() # DEPRECATED try: unit = wrest.unit except AttributeError: raise ValueError('wrest needs to be a Quantity with a Unit, e.g. Ang') self.wrest = wrest self.z = z # Fill in atomic data from Table (default) # Dict : fval, gamma, A, Elow, Eup, Ex, j, name, wrest if fill is True: self.atomic = abs_line_data(self.wrest) # Dict self.name = self.atomic['name'] else: self.name = '' # Attribute dict self.attrib = {'N': 0., 'Nsig': 0., 'flgN': 0, 'b': 0., 'bsig': 0., 'vmin': 0., 'vmax': 0., 'EW': 0., 'EWsig': 0., 'flgEW': 0} # Spectrum info (optional) if spec_file is None: self.spec = None else: import xastropy.spec.readwrite as xspec_rw self.spec = xspec_rw.readspec(spec_file)
def x_contifit(specfil, outfil=None, savfil=None, redshift=0., divmult=1, forest_divmult=1): import os import barak.fitcont as bf from barak.spec import read from barak.io import saveobj, loadobj import xastropy.spec.readwrite as xsr reload(xsr) reload(bf) # Initialize if savfil == None: savfil = 'conti.sav' if outfil == None: outfil = 'conti.fits' # Read spectrum + convert to Barak format sp = xsr.readspec(specfil) # Fit spline continuum: if os.path.lexists(savfil): #'contfit_' + name + '.sav'): option = raw_input('Adjust old continuum? (y)/n: ') if option.lower() != 'n': co_old, knots_old = loadobj(savfil) #'contfit_' + name + '.sav') co, knots = bf.fitqsocont(sp.wa, sp.fl, sp.er, redshift, oldco=co_old, knots=knots_old, divmult=divmult, forest_divmult=forest_divmult) else: co, knots = bf.fitqsocont(sp.wa, sp.fl, sp.er, redshift, divmult=divmult, forest_divmult=forest_divmult) else: co, knots = bf.fitqsocont(sp.wa, sp.fl, sp.er, redshift, divmult=divmult, forest_divmult=forest_divmult) os.remove('_knots.sav') # Save continuum: saveobj(savfil, (co, knots), overwrite=1) # Check continuum: print('Plotting new continuum') plt.clf() plt.plot(sp.wa, sp.fl, drawstyle='steps-mid') plt.plot(sp.wa, sp.co, color='r') plt.show() # Repeat? confirm = raw_input('Keep continuum? (y)/n: ') if confirm == 'y': fits.writeto(outfil, sp, clobber=True) else: print('Writing to tmp.fits anyhow!') fits.writeto('tmp.fits', sp, clobber=True)
def spec_plot(spec_fil, ID_path=None, ambig_fil=None, dwv=25., outfil='tmp.pdf'): mpl.rcParams['font.family'] = 'stixgeneral' from matplotlib.backends.backend_pdf import PdfPages import matplotlib.gridspec as gridspec ''' spec_fil: string Filename of spectrum outfil: string ('tmp.pdf') Filename for output dwv: float (25.) Ang per window ''' npx = 1 npy = 4 # Read spectrum spec = xsr.readspec(spec_file) # Start plot pp = PdfPages(outfil)
# ################ if __name__ == "__main__": flg_test = 0 #flg_test += 2**0 # Test write (simple) #flg_test += 2**1 # Test write with 3 arrays #flg_test += 2**2 # Test boxcar flg_test += 2**3 # Test rebin from xastropy.spec import readwrite as xsr if (flg_test % 2**1) >= 2**0: # Standard log-linear read + write (MagE) fil = '~/PROGETTI/LLSZ3/data/normalize/UM669_nF.fits' myspec = xsr.readspec(fil) # Write myspec.write_to_fits('tmp.fits') if (flg_test % 2**2) >= 2**1: # Now 2D fil = '/Users/xavier/Dropbox/QSOPairs/data/LRIS_redux/SDSSJ231254.65-025403.1_b400_F.fits.gz' myspec = xsr.readspec(fil) myspec.write_to_fits('tmp.fits') if (flg_test % 2**3) >= 2**2: # Boxcar fil = '~/PROGETTI/LLSZ3/data/normalize/UM669_nF.fits' myspec = xsr.readspec(fil) newspec = myspec.box_smooth(3) # newspec2 = myspec.box_smooth(3, preserve=True)
flg_test += 2**1 # AODM #flg_test += 2**2 # EW # Test Absorption Line creation if (flg_test % 2**1) >= 2**0: print('-------------------------') aline = AbsLine(1215.6701*u.AA) print(aline) # Test AODM if (flg_test % 2**2) >= 2**1: print('------------ AODM -------------') # Spectrum fil = '~/PROGETTI/LLSZ3/data/normalize/UM669_nF.fits' aline = AbsLine(1302.1685*u.AA) aline.spec = xsr.readspec(fil) # Line info aline.analy['z'] = 2.92652 aline.analy['VLIM'] = const.c.to('km/s') * ( ( np.array([5110.668, 5116.305])*u.AA/( 1+aline.analy['z']) - aline.wrest) / aline.wrest ) # Evaluate N,sigN = aline.aodm(conti=np.ones(len(aline.spec.flux))) logN, sig_logN = xsb.lin_to_log(N,sigN) print('logN = {:g}, sig_logN = {:g}'.format(logN, sig_logN)) # Test EW if (flg_test % 2**3) >= 2**2: print('------------ EW -------------') # Spectrum fil = '~/PROGETTI/LLSZ3/data/normalize/UM669_nF.fits'