def spectraresolution3(img0, ww=25): import pyfits import os, string, re, sys import lickshane from numpy import arange, mean, compress, array, median from numpy import interp as ninterp from pyraf import iraf iraf.onedspec(_doprint=0) img = re.sub('arc_', '', img0) data, hdr = pyfits.getdata(img0, 0, header=True) crvals = lickshane.util.readkey3(hdr, 'CRVAL1') cds = lickshane.util.readkey3(hdr, 'CD1_1') xx = arange(len(data)) yy = data aa = crvals + (xx) * cds maxtab, mintab = lickshane.util.peakdet(yy, median(yy) * 10) if len(maxtab) <= 0: maxtab, mintab = lickshane.util.peakdet(yy, median(yy)) if len(maxtab) <= 0: lines = [] else: lines0, b = zip(*maxtab) lines = crvals + (array(lines0)) * cds if len(lines) > 0: lines = compress((aa[0] < array(lines)) & (array(lines) < aa[-1]), array(lines)) cursor = '' yym = ninterp(lines - ww, aa, yy) yyp = ninterp(lines + ww, aa, yy) for i in range(0, len(lines)): cursor = cursor + str(lines[i] - ww) + ' ' + str( yym[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str( yyp[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 q\n' ff = open('_cursor', 'w') ff.write(cursor) ff.close() from pyraf import iraf aaa = iraf.noao.onedspec.bplot(img0, cursor='_cursor', spec2='', new_ima='', overwri='yes', Stdout=1) fw = [] for i in aaa[1:]: fw.append(float(string.split(string.split(i, '=')[-1], 'k')[0])) lickshane.util.delete('_cursor') res = (aa[0] + ((aa[-1] - aa[0]) / 2)) / mean(fw) else: res = 9999 return res
def fluxcalib2d(img2d, sensfun): # flux calibrate 2d images import pyfits import re, string from pyfits import open as popen from numpy import arange, array, float32 from numpy import interp as ninterp import floyds from floyds.util import readhdr, readkey3, delete _tel = floyds.util.readkey3(floyds.util.readhdr(re.sub('\n', '', img2d)), 'TELID') if _tel == 'fts': _extinction = 'ssoextinct.dat' _observatory = 'sso' elif _tel == 'ftn': _extinction = 'maua.dat' _observatory = 'cfht' else: sys.exit('ERROR: observatory not recognised') data2d, hdr2d = pyfits.getdata(img2d, 0, header=True) if 'GRISM' in hdr2d: _arm = hdr2d['GRISM'] else: _arm = '' xxd = arange(len(data2d[0, :])) crvald = popen(img2d)[0].header.get('CRVAL1') cdd = popen(img2d)[0].header.get('CD1_1') _exptime, _airmass = readkey3(readhdr(img2d), 'exptime'), readkey3(readhdr(img2d), 'airmass') # read sensfunction and interpole pixel of 2D image yys = popen(sensfun)[0].data crvals = popen(sensfun)[0].header.get('CRVAL1') cds = popen(sensfun)[0].header.get('CD1_1') yys = (10**(yys / 2.5)) * cds # from sens iraf in sens flux xxs = arange(len(yys)) aasens = crvals + (xxs) * cds xxs2 = (aasens - crvald) / cdd aasens2 = ninterp(xxd, xxs2, yys) # read atmosferic function and interpole pixel of 2D image aae, yye = floyds.util.ReadAscii2(floyds.__path__[0] + '/standard/extinction/' + _extinction) aae, yye = array(aae, float), array(yye, float) xxe = (aae - crvald) / cdd atm_xx = ninterp(xxd, xxe, yye) aircorr = 10**(0.4 * array(atm_xx) * _airmass) img2df = re.sub('.fits', '_2df.fits', img2d) for i in range(len(data2d[:, 0])): data2d[i, :] = ( (array(data2d[i, :] / _exptime) * array(aircorr)) / aasens2) * 1e20 floyds.util.delete(img2df) pyfits.writeto(img2df, float32(data2d), hdr2d) floyds.util.updateheader( img2df, 0, {'SENSFUN' + _arm[0]: [string.split(sensfun, '/')[-1], '']}) floyds.util.updateheader( img2df, 0, {'BUNIT': ['erg/cm2/s/A 10^20', 'Physical unit of array values']}) return img2df
def spectraresolution2(img0, ww=25): from astropy.io import fits import os, string, re, sys import floyds from numpy import arange, mean, compress, array from numpy import interp as ninterp from pyraf import iraf iraf.onedspec(_doprint=0) id = 'database/id' + re.sub('.fits', '', img0) img = re.sub('arc_', '', img0) data, hdr = fits.getdata(img0, 0, header=True) crvals = floyds.util.readkey3(hdr, 'CRVAL1') cds = floyds.util.readkey3(hdr, 'CD1_1') xx = arange(len(data)) yy = data aa = crvals + (xx) * cds # read identified lines from id file f = open(id, 'r') ss = f.readlines() f.close() indices = [i for i, x in enumerate(ss) if "begin" in x] if len(indices) <= 1: dd = ss[indices[0]:len(ss)] else: dd = ss[indices[0]:indices[1]] # dd=ss[indices[-1]:len(ss)] start = [i for i, x in enumerate(dd) if "features" in x][0] + 1 stop = [i for i, x in enumerate(dd) if "function" in x][0] ff = dd[start:stop] lines = [] if len(ff) > 0: for i in ff: lines.append(float(string.split(i)[2])) print lines lines = compress((aa[0] < array(lines)) & (array(lines) < aa[-1]), array(lines)) cursor = '' yym = ninterp(lines - ww, aa, yy) yyp = ninterp(lines + ww, aa, yy) for i in range(0, len(lines)): cursor = cursor + str(lines[i] - ww) + ' ' + str(yym[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 q\n' ff = open('_cursor', 'w') ff.write(cursor) ff.close() from pyraf import iraf aaa = iraf.noao.onedspec.bplot(img0, cursor='_cursor', spec2='', new_ima='', overwri='yes', Stdout=1) fw = [] for i in aaa[1:]: fw.append(float(string.split(string.split(i, '=')[-1], 'k')[0])) floyds.util.delete('_cursor') res = (aa[0] + ((aa[-1] - aa[0]) / 2)) / mean(fw) else: res = 9999 return res
def spectraresolution2(img0, ww=25): import pyfits import os, string, re, sys import floyds from numpy import arange, mean, compress, array from numpy import interp as ninterp from pyraf import iraf iraf.onedspec(_doprint=0) id = 'database/id' + re.sub('.fits', '', img0) img = re.sub('arc_', '', img0) data, hdr = pyfits.getdata(img0, 0, header=True) crvals = floyds.util.readkey3(hdr, 'CRVAL1') cds = floyds.util.readkey3(hdr, 'CD1_1') xx = arange(len(data)) yy = data aa = crvals + (xx) * cds # read identified lines from id file f = open(id, 'r') ss = f.readlines() f.close() indices = [i for i, x in enumerate(ss) if "begin" in x] if len(indices) <= 1: dd = ss[indices[0]:len(ss)] else: dd = ss[indices[0]:indices[1]] # dd=ss[indices[-1]:len(ss)] start = [i for i, x in enumerate(dd) if "features" in x][0] + 1 stop = [i for i, x in enumerate(dd) if "function" in x][0] ff = dd[start:stop] lines = [] if len(ff) > 0: for i in ff: lines.append(float(string.split(i)[2])) print lines lines = compress((aa[0] < array(lines)) & (array(lines) < aa[-1]), array(lines)) cursor = '' yym = ninterp(lines - ww, aa, yy) yyp = ninterp(lines + ww, aa, yy) for i in range(0, len(lines)): cursor = cursor + str(lines[i] - ww) + ' ' + str(yym[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 q\n' ff = open('_cursor', 'w') ff.write(cursor) ff.close() from pyraf import iraf aaa = iraf.noao.onedspec.bplot(img0, cursor='_cursor', spec2='', new_ima='', overwri='yes', Stdout=1) fw = [] for i in aaa[1:]: fw.append(float(string.split(string.split(i, '=')[-1], 'k')[0])) floyds.util.delete('_cursor') res = (aa[0] + ((aa[-1] - aa[0]) / 2)) / mean(fw) else: res = 9999 return res
def fluxcalib2d(img2d,sensfun): # flux calibrate 2d images import pyfits import re,string from pyfits import open as popen from numpy import arange, array, float32 from numpy import interp as ninterp import floyds from floyds.util import readhdr,readkey3,delete _tel=floyds.util.readkey3(floyds.util.readhdr(re.sub('\n','',img2d)),'TELID') if _tel=='fts': _extinction='ssoextinct.dat' _observatory='sso' elif _tel=='ftn': _extinction='maua.dat' _observatory='cfht' else: sys.exit('ERROR: observatory not recognised') data2d, hdr2d = pyfits.getdata(img2d, 0, header=True) if 'GRISM' in hdr2d: _arm=hdr2d['GRISM'] else: _arm='' xxd=arange(len(data2d[0,:])) crvald=popen(img2d)[0].header.get('CRVAL1') cdd=popen(img2d)[0].header.get('CD1_1') _exptime,_airmass=readkey3(readhdr(img2d),'exptime'),readkey3(readhdr(img2d),'airmass') # read sensfunction and interpole pixel of 2D image yys=popen(sensfun)[0].data crvals=popen(sensfun)[0].header.get('CRVAL1') cds=popen(sensfun)[0].header.get('CD1_1') yys=(10**(yys/2.5))*cds # from sens iraf in sens flux xxs=arange(len(yys)) aasens=crvals+(xxs)*cds xxs2=(aasens-crvald)/cdd aasens2=ninterp(xxd,xxs2,yys) # read atmosferic function and interpole pixel of 2D image aae,yye=floyds.util.ReadAscii2(floyds.__path__[0]+'/standard/extinction/'+_extinction) aae,yye=array(aae,float),array(yye,float) xxe=(aae-crvald)/cdd atm_xx=ninterp(xxd,xxe,yye) aircorr=10**(0.4*array(atm_xx)*_airmass) img2df=re.sub('.fits','_2df.fits',img2d) for i in range(len(data2d[:,0])): data2d[i,:]=((array(data2d[i,:]/_exptime)*array(aircorr))/aasens2)*1e20 floyds.util.delete(img2df) pyfits.writeto(img2df, float32(data2d), hdr2d) floyds.util.updateheader(img2df,0,{'SENSFUN'+_arm[0]:[string.split(sensfun,'/')[-1],'']}) floyds.util.updateheader(img2df,0,{'BUNIT':['erg/cm2/s/A 10^20','Physical unit of array values']}) return img2df
def spectraresolution3(img0, ww=25): import pyfits import os, string, re, sys import floyds from numpy import arange, mean, compress, array, median from numpy import interp as ninterp from pyraf import iraf iraf.onedspec(_doprint=0) img = re.sub('arc_', '', img0) data, hdr = pyfits.getdata(img0, 0, header=True) crvals = floyds.util.readkey3(hdr, 'CRVAL1') cds = floyds.util.readkey3(hdr, 'CD1_1') xx = arange(len(data)) yy = data aa = crvals + (xx) * cds maxtab, mintab = floyds.util.peakdet(yy, median(yy) * 10) if len(maxtab) <= 0: maxtab, mintab = floyds.util.peakdet(yy, median(yy)) if len(maxtab) <= 0: lines = [] else: lines0, b = zip(*maxtab) lines = crvals + (array(lines0)) * cds if len(lines) > 0: lines = compress((aa[0] < array(lines)) & (array(lines) < aa[-1]), array(lines)) cursor = '' yym = ninterp(lines - ww, aa, yy) yyp = ninterp(lines + ww, aa, yy) for i in range(0, len(lines)): cursor = cursor + str(lines[i] - ww) + ' ' + str(yym[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 k\n' cursor = cursor + str(lines[i] + ww) + ' ' + str(yyp[i]) + ' 1 q\n' ff = open('_cursor', 'w') ff.write(cursor) ff.close() from pyraf import iraf aaa = iraf.noao.onedspec.bplot(img0, cursor='_cursor', spec2='', new_ima='', overwri='yes', Stdout=1) fw = [] for i in aaa[1:]: fw.append(float(string.split(string.split(i, '=')[-1], 'k')[0])) floyds.util.delete('_cursor') res = (aa[0] + ((aa[-1] - aa[0]) / 2)) / mean(fw) else: res = 9999 return res
def skysofifrom2d(fitsfile, skyfile): # print "LOGX:: Entering `skysofifrom2d` method/function in %(__file__)s" # % globals() import ntt from ntt.util import readhdr, readkey3, delete from numpy import mean, arange, compress try: from astropy.io import fits as pyfits except: import pyfits from numpy import interp as ninterp hdr = readhdr(fitsfile) _grism = readkey3(hdr, 'grism') if _grism == 'GR': _order1 = 10 else: _order1 = 6 yy1 = pyfits.open(fitsfile)[0].data[:, :].mean(1) crval2 = readkey3(hdr, 'CRVAL2') cd2 = readkey3(hdr, 'CD2_2') xx1 = arange(len(yy1)) aa1 = crval2 + (xx1) * cd2 yy1cut = compress((aa1 < 18400) | (aa1 > 18650), yy1) aa1cut = compress((aa1 < 18400) | (aa1 > 18650), aa1) yy1cut1 = compress((aa1cut < 11600) | (aa1cut > 11800), yy1cut) aa1cut1 = compress((aa1cut < 11600) | (aa1cut > 11800), aa1cut) yy1interp = ninterp(aa1, aa1cut1, yy1cut1) delete('_new3.fits') hdu = pyfits.PrimaryHDU(yy1interp) hdulist = pyfits.HDUList([hdu]) hdulist.writeto('_new3.fits') hdulist.close() ntt.util.updateheader('_new3.fits',0,{'CRVAL1':[crval2,''],'CD1_1':[cd2,'']}) # hdulist[0].header.update('CRVAL1', crval2) # hdulist[0].header.update('CD1_1', cd2) fitsfile = ntt.efoscspec2Ddef.continumsub('_new3.fits', _order1, 1) yy1 = pyfits.open(fitsfile)[0].data crval2 = pyfits.open(fitsfile)[0].header.get('CRVAL1') cd2 = pyfits.open(fitsfile)[0].header.get('CD1_1') xx1 = arange(len(yy1)) aa1 = crval2 + (xx1) * cd2 skyff = pyfits.open(skyfile)[0].data crval1 = pyfits.open(skyfile)[0].header.get('CRVAL1') cd1 = pyfits.open(skyfile)[0].header.get('CD1_1') skyxx = arange(len(skyff)) skyaa = crval1 + (skyxx) * cd1 shift = ntt.efoscspec2Ddef.checkwavelength_arc( aa1, yy1, skyaa, skyff, '', '') delete('_new3.fits') return shift
'shen_0_6_0_2.dat': '.Ia', 'shen_1_2_0_02.dat': '.Ia', 'SNIa_CSM_r.dat': 'Ia+shock', 'SNIa_RG1Msunprogenitor_maxinteraction_r.dat': 'Ia+CSM'} for key in ['snIa_K211b.dat', 'snIc_2002ap_V.dat', 'snIb_2009jf_V.dat', 'snIb_ptf13bvn_V.dat', 'PTF12cod_R.dat', 'PTF11htj_R.dat', \ 'PTF12bro_R.dat', 'cv_tpyx_V.dat', 'cv_v1324sco_V.dat', 'cv_sscyg_V.dat', \ 'shen_0_6_0_2.dat', 'shen_1_2_0_02.dat', \ 'SNIa_CSM_r.dat']: ph = models[key]['days'] mag = models[key]['mag'] hours = .5 sigma = 1 ph1 = ph + hours / 24. mag1 = ninterp(ph1, ph, mag) diff1 = mag1 - mag hours = 2 sigma = 1 ph2 = ph + hours / 24. mag2 = ninterp(ph2, ph, mag) diff2 = mag2 - mag hours = 24 sigma = 1 ph3 = ph + hours / 24. mag3 = ninterp(ph3, ph, mag) diff3 = mag3 - mag