本文整理汇总了Python中pyraf.iraf.osfn函数的典型用法代码示例。如果您正苦于以下问题:Python osfn函数的具体用法?Python osfn怎么用?Python osfn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了osfn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: advanceprocess
def advanceprocess(instrume, obsdate, propcode, median, function, order, rej_lo, rej_hi, niter, interp, sdbhost, sdbname, sdbuser, sdbpass, logfile, verbose):
"""Advance process the rss data"""
rawpath = instrume+'/raw'
prodpath = instrume+'/advance'
os.mkdir(prodpath)
instrume_name='RSS'
prefix = 'P'
img_list=[]
for img in glob.glob('%s/raw/%s*fits' % (instrume, prefix)):
struct=pyfits.open(img)
if struct[0].header['PROPID'].upper().strip() != 'JUNK':
img_list.append(img)
images=','.join(img_list)
obslog = '%s/%s%sOBSLOG.fits' % (prodpath, prefix, obsdate)
gaindb = iraf.osfn('pysalt$data/%s/%samps.dat' % (instrume, instrume_name))
xtalkfile = iraf.osfn('pysalt$data/%s/%sxtalk.dat' % (instrume, instrume_name))
geomfile = iraf.osfn('pysalt$data/%s/%sgeom.dat' % (instrume, instrume_name))
saltadvance(images, prodpath, obslogfile=obslog, gaindb=gaindb, xtalkfile=xtalkfile,
geomfile=geomfile, subover=True,trim=True,masbias=None,
subbias=False, median=False, function='polynomial', order=5,rej_lo=3,
rej_hi=3, niter=5,interp='linear', sdbhost=sdbhost, sdbname=sdbname,sdbuser=sdbuser, password=sdbpass,
clobber=True, logfile=logfile, verbose=verbose)
return
示例2: processdata
def processdata(instrume, obsdate, propcode, median, function, order, rej_lo, rej_hi, niter, interp, logfile, verbose):
"""Clean and process the data"""
#set up instrument specific naming
if instrume=='rss':
instrume_name='RSS'
prefix='P'
elif instrume=='scam':
instrume_name='SALTICAM'
prefix='S'
rawpath = instrume+'/raw'
prodpath = instrume+'/product'
img_list=[]
for img in glob.glob('%s/raw/%s*fits' % (instrume, prefix)):
struct=pyfits.open(img)
if struct[0].header['PROPID'].upper().strip() != 'JUNK':
img_list.append(img)
img_str=','.join(img_list)
obslog = '%s/%s%sOBSLOG.fits' % (prodpath, prefix, obsdate)
gaindb = iraf.osfn('pysalt$data/%s/%samps.dat' % (instrume, instrume_name))
#gaindb = ''
xtalkfile = iraf.osfn('pysalt$data/%s/%sxtalk.dat' % (instrume, instrume_name))
geomfile = iraf.osfn('pysalt$data/%s/%sgeom.dat' % (instrume, instrume_name))
if len(img_list)>0:
saltclean(images=img_str,outpath=prodpath,obslogfile=obslog,gaindb=gaindb,
xtalkfile=xtalkfile,geomfile=geomfile,subover=True,trim=True,
median=median,function=function,order=order,rej_lo=rej_lo,
rej_hi=rej_hi,niter=niter,masbias=True,subbias=False,interp=interp,
clobber=True,logfile=logfile,verbose=verbose)
rawsize = 0.
rawnum = 0
prodsize = 0.
prodnum = 0
if len(img_list)>0:
files = glob.glob('%s/raw/%s*.fits' % (instrume, prefix))
rawnum = len(files)
for file in files:
rawsize += os.stat(file).st_size
files = glob.glob('%s/product/*%s*.fits' % (instrume, prefix))
prodnum = len(files)
for file in files:
prodsize += os.stat(file).st_size
# collate RSS data for individual PIs
outpath = '.'
if len(img_list):
saltobsid(propcode=propcode,obslog=obslog,rawpath=rawpath,prodpath=prodpath, outpath=outpath,clobber=True,logfile=logfile,verbose=verbose)
return rawsize, rawnum, prodsize, prodnum
示例3: preprocessdata
def preprocessdata(instrume, prefix, obsdate, keyfile, log, logfile, verbose):
"""Run through all of the processing of the individual data files"""
log.message('Beginning pre-processing of %s data' % instrume.upper())
#set up the input path
inpath=instrume+'/raw/'
#creaate the product directory
prodpath=instrume+'/product/'
saltio.createdir(prodpath)
# convert any slot mode binary data to FITS
convertbin(inpath, iraf.osfn('pysalt$data/%s/%s_fits.config' % (instrume, instrume)), logfile, verbose)
# fix sec keywords for data of unequal binning obtained before 2006 Aug 12
if int(obsdate) < 20060812:
pinfiles = instrume+'/raw/*.fits'
log.message('Fixing SEC keywords in older data')
log.message('SALTFIXSEC -- infiles=' + pinfiles)
pipetools.saltfixsec(infiles=pinfiles)
#fix the key words for the data set
recfile = prodpath+prefix+ obsdate + 'KEYLOG.fits'
img=','.join(glob.glob(inpath+prefix+'*fits'))
if img:
salteditkey(images=img,outimages=img,outpref='',keyfile=keyfile,recfile=recfile,
clobber=True,logfile=logfile,verbose=verbose)
示例4: agncalibrate
def agncalibrate(img, outfile, calfile, specformat='lcogt'):
#set up some files that will be needed
logfile='specext.log'
hdu = fits.open(img)
w1 = hdu[0].header['CRVAL1']
p1 = hdu[0].header['CRPIX1']
dw = hdu[0].header['CD1_1']
f = hdu[0].data[0][0]
e = hdu[0].data[3][0]
xarr = np.arange(len(f))
w = (xarr)*dw+w1
cal_spectra=st.readspectrum(calfile, error=False, ftype='ascii')
airmass=hdu[0].header['AIRMASS']
exptime=hdu[0].header['EXPTIME']
extfile=iraf.osfn("pysalt$data/site/suth_extinct.dat")
ext_spectra=st.readspectrum(extfile, error=False, ftype='ascii')
flux_spec=Spectrum.Spectrum(w, f, e, stype='continuum')
flux_spec=calfunc(flux_spec, cal_spectra, ext_spectra, airmass, exptime, True)
hdu[0].data[0][0] = flux_spec.flux
hdu[0].data[3][0] = flux_spec.var
hdu.writeto(outfile, clobber=True)
示例5: galextract
def galextract(img, yc=None, dy=None, normalize=True, calfile=None, convert=True, specformat='ascii'):
#set up some files that will be needed
logfile='specext.log'
#create the spectra text files for all of our objects
spec_list=[]
#skynormalize the data
if normalize:
specslitnormalize(img, 'n'+img, '', response=None, response_output=None, order=3, conv=1e-2, niter=20,
startext=0, clobber=True,logfile='salt.log',verbose=True)
hdu=pyfits.open('n'+img)
target=hdu[0].header['OBJECT']
ofile='%s.%s_%i_%i.ltxt' % (target, extract_date(img), extract_number(img), yc)
#ofile = img.replace('fits', 'txt')
extract_spectra(hdu, yc, dy, ofile, smooth=False, grow=10, clobber=True, specformat=specformat, convert=convert)
if calfile is not None:
airmass=hdu[0].header['AIRMASS']
exptime=hdu[0].header['EXPTIME']
extfile=iraf.osfn("pysalt$data/site/suth_extinct.dat")
speccal(ofile, ofile.replace("txt", "spec"), calfile, extfile, airmass, exptime, clobber=True, logfile='salt.log', verbose=True)
示例6: specpolfilter
def specpolfilter(filterlist, infilelist):
obss = len(infilelist)
obsdict=obslog(infilelist)
for b in range(obss):
hdul = pyfits.open(infilelist[b])
dwav = float(hdul['SCI'].header['CDELT1'])
wav0 = float(hdul['SCI'].header['CRVAL1'])
wavs = int(hdul['SCI'].header['NAXIS1'])
ctypelist = (hdul['SCI'].header['CTYPE3']).split(',')
stokes_sw = hdul['SCI'].data[:,0,:]
var_sw = hdul['VAR'].data[:,0,:]
pstokess = len(ctypelist)-1
ok_w = (hdul['BPM'].data[:,0,:] == 0).all(axis=0)
wav_w = wav0 + dwav*np.arange(wavs)
print "\n"+infilelist[b]
print ("Filter "+pstokess*"%5s Err ") % tuple(ctypelist[1:])
for filter in filterlist:
if filter in ("U","B","V"):
filterfile = iraf.osfn("pysalt$data/scam/filters/Johnson_"+filter+".txt")
elif filter in ("R","I"):
filterfile = iraf.osfn("pysalt$data/scam/filters/Cousins_"+filter+".txt")
# else:
# (filter file in cwd)
wav_l,feff_l = np.loadtxt(filterfile,dtype=float,unpack=True)
feff_l[feff_l < .0001] = 0.
feff_w = interp1d(wav_l,feff_l,kind='linear',bounds_error=False)(wav_w)
okf_w = (ok_w & (feff_w > .0003))
feff_w[~okf_w] = 0.
if feff_w[okf_w].sum() == 0: continue
stokesfil_s = (feff_w[okf_w]*stokes_sw[:,okf_w]).sum(axis=1)/feff_w[okf_w].sum()
varfil_s = (feff_w[okf_w]**2*var_sw[:,okf_w]).sum(axis=1)/(feff_w[okf_w].sum()**2)
nstokesfil_s = 100.*stokesfil_s/stokesfil_s[0]
nerrfil_s = 100.*np.sqrt(varfil_s[:pstokess+1])/stokesfil_s[0]
print ("%4s "+pstokess*"%9.4f %7.4f ") % \
(tuple(filter)+tuple(np.vstack((nstokesfil_s[1:],nerrfil_s[1:])).T.ravel()))
return()
示例7: init_northsouth
def init_northsouth(fs, topdir, rawpath):
# Get the correct directory for the standard star
base_stddir = 'spec50cal/'
extfile = iraf.osfn('gmisc$lib/onedstds/kpnoextinct.dat')
observatory = 'Gemini-North'
global is_GS
is_GS = pyfits.getval(fs[0], 'DETECTOR') == 'GMOS + Hamamatsu'
if is_GS:
global dooverscan
dooverscan = True
if not os.path.exists(topdir + '/raw_fixhdr'):
os.mkdir(topdir + '/raw_fixhdr')
rawpath = '%s/raw_fixhdr/' % topdir
os.system('gmoss_fix_headers.py --files="%s/raw/*.fits" --destination=%s' % (topdir, rawpath))
base_stddir = 'ctionewcal/'
observatory = 'Gemini-South'
extfile = iraf.osfn('gmisc$lib/onedstds/ctioextinct.dat')
return extfile, observatory, base_stddir, rawpath
示例8: mosred
def mosred(infile_list, slitmask,propcode=None, dy=0, inter=True, guesstype='rss', guessfile='', rstep=100, automethod='Matchlines', preprocess=False):
#set up the files
infiles=','.join(['%s' % x for x in infile_list])
obsdate=os.path.basename(infile_list[0])[7:15]
#set up some files that will be needed
logfile='spec'+obsdate+'.log'
dbfile='spec%s.db' % obsdate
#create the observation log
obs_dict=obslog(infile_list)
#check the value of dy
#apply the mask to the data sets
for i in range(len(infile_list)):
specslit(image=infile_list[i], outimage='', outpref='s', exttype='rsmt', slitfile=slitmask,
outputslitfile='', regprefix='ds_', sections=3, width=25.0, sigma=2.2, thres=6.0, order=1, padding=5, yoffset=dy,
inter=False, clobber=True, logfile=logfile, verbose=True)
for i in range(len(infile_list)):
if obs_dict['OBJECT'][i].upper().strip()=='ARC' and (obs_dict['PROPID'][i].upper().strip()==propcode or propcode is None):
lamp=obs_dict['LAMPID'][i].strip().replace(' ', '')
arcimage='s'+os.path.basename(infile_list[i])
if lamp == 'NONE': lamp='CuAr'
lampfile=iraf.osfn("pysalt$data/linelists/%s.salt" % lamp)
specselfid(arcimage, '', 'a', arcimage, 'middlerow', 3, clobber=True, logfile=logfile, verbose=True)
specidentify('a'+arcimage, lampfile, dbfile, guesstype=guesstype,
guessfile=guessfile, automethod=automethod, function='legendre', order=3,
rstep=rstep, rstart='middlerow', mdiff=20, thresh=3, niter=5, smooth=3,
inter=True, clobber=True, preprocess=True, logfile=logfile, verbose=True)
#specrectify(arcimage, outimages='', outpref='x', solfile=dbfile, caltype='line',
# function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None,
# blank=0.0, clobber=True, logfile=logfile, verbose=True)
objimages=''
spec_list=[]
for i in range(len(infile_list)):
if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS') and \
(obs_dict['PROPID'][i].upper().strip()==propcode or propcode is None) and \
obs_dict['OBSMODE'][i].count('SPECTROSCOPY'):
img = infile_list[i]
##rectify it
specselfid('s'+img, '', 'a', arcimage, 'middlerow', 3, clobber=True, logfile=logfile, verbose=True)
specrectify('as'+img, outimages='', outpref='x', solfile=dbfile, caltype='line',
function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None,
blank=0.0, clobber=True, logfile=logfile, verbose=True)
示例9: specred
def specred(infile_list, target, propcode, calfile=None, inter=True, automethod='Matchlines'):
#set up the files
infiles=','.join(['%s' % x for x in infile_list])
obsdate=os.path.basename(infile_list[0])[7:15]
#set up some files that will be needed
logfile='spec'+obsdate+'.log'
dbfile='spec%s.db' % obsdate
#create the observation log
obs_dict=obslog(infile_list)
for i in range(len(infile_list)):
if obs_dict['OBJECT'][i].upper().strip()=='ARC' and obs_dict['PROPID'][i].upper().strip()==propcode:
lamp=obs_dict['LAMPID'][i].strip().replace(' ', '')
arcimage=os.path.basename(infile_list[i])
if lamp == 'NONE': lamp='CuAr'
lampfile=iraf.osfn("pysalt$data/linelists/%s.salt" % lamp)
specidentify(arcimage, lampfile, dbfile, guesstype='rss',
guessfile='', automethod=automethod, function='legendre', order=3,
rstep=100, rstart='middlerow', mdiff=20, thresh=3, niter=5, smooth=3,
inter=False, clobber=True, logfile=logfile, verbose=True)
specrectify(arcimage, outimages='', outpref='x', solfile=dbfile, caltype='line',
function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None,
blank=0.0, clobber=True, logfile=logfile, verbose=True)
objimages=''
spec_list=[]
for i in range(len(infile_list)):
if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS') and obs_dict['PROPID'][i].upper().strip()==propcode:
img = infile_list[i]
##rectify it
specrectify(img, outimages='', outpref='x', solfile=dbfile, caltype='line',
function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None,
blank=0.0, clobber=True, logfile=logfile, verbose=True)
#extract the spectra
spec_list.append(extract_spectra('x'+img, yc=1030, calfile=calfile, findobject=True, smooth=False, maskzeros=True, clobber=True))
#combine the results
w,f,e = speccombine(spec_list, obsdate)
outfile = "%s_%s.spec" % (target, obsdate)
write_spectra(outfile, w,f,e)
示例10: buildtmc
def buildtmc(tmcname):
from pyraf import iraf
from iraf import stsdas,hst_calib,synphot
out=open('buildtmc.log','w')
f=pyfits.open(tmcname)
flist=f[1].data.field('filename')
iraf.set(crrefer='./') #work locally
for k in range(len(flist)):
oldname=iraf.osfn(flist[k]).split('[')[0]
newname=fincre(oldname)
if os.path.exists(newname):
flist[k]=fincre(flist[k])
else:
out.write("%s: no change necessary\n"%oldname)
f.writeto(tmcname.replace(".fits","_new.fits"))
out.close()
示例11: makesensfunc
def makesensfunc(scifiles, objname, base_stddir, extfile):
#TODO use individual standard star observations in each setting, not just red and blue
for f in scifiles:
redorblue = getredorblue(f)
# If this is a standard star, run standard
# Standards will have an observation class of either progCal or partnerCal
# Standards will have an observation class of either progCal or partnerCal
obsclass = pyfits.getval(f[:-4] + '.fits', 'OBSCLASS')
if obsclass == 'progCal' or obsclass == 'partnerCal':
# Figure out which directory the stardard star is in
stddir = iraf.osfn('gmisc$lib/onedstds/') + base_stddir
# iraf.gsstandard('est' + f[:-4], 'std' + redorblue,
# 'sens' + redorblue, starname=objname.lower(),
# caldir='gmisc$lib/onedstds/'+stddir, fl_inter=True)
specsens('et' + f[:-4] + '.fits', 'sens' + redorblue + '.fits',
stddir + objname + '.dat' , extfile,
float(pyfits.getval(f[:-4] + '.fits', 'AIRMASS')),
float(pyfits.getval(f[:-4] + '.fits', 'EXPTIME')))
示例12: setglobal
def setglobal(self,fname=None):
if fname is None:
fname=__file__
self.propername=self.id()
base,ext=os.path.splitext(os.path.basename(fname))
main,case,test=self.propername.split('.')
self.name=os.path.join(base,test,case)
self.wavename=self.name+'_wave.fits'
#Make sure the directories exist
dirname=os.path.dirname(self.name)
if not os.path.isdir(dirname):
os.makedirs(dirname)
self.file=self.name
self.thresh=0.01
self.superthresh=0.20
self.sigthresh=0.01
self.discrep=-99
self.tda={'Obsmode':self.obsmode,
'Spectrum':self.spectrum,
'ETCid':None, #placeholder
'Thresh':self.thresh,
'Superthresh':self.superthresh,
'SigThresh':self.sigthresh,
'crrefer':iraf.osfn('crrefer$'),
'pysyn_cdbs':os.environ['PYSYN_CDBS'],
'SkyLines':self.hasSkyLines()}
try:
self.tda['Subset']=self.subset
except AttributeError:
pass
try:
self.tda['ETCid']=self.etcid
except AttributeError:
pass
try:
self.tda['form']=self.form
except AttributeError:
pass
self.tra={}
示例13: specred
def specred(infile_list, propcode=None, inter=True, automethod='Matchlines'):
#set up the files
infiles=','.join(['%s' % x for x in infile_list])
obsdate=os.path.basename(infile_list[0])[7:15]
#set up some files that will be needed
logfile='spec'+obsdate+'.log'
dbfile='spec%s.db' % obsdate
#create the observation log
obs_dict=obslog(infile_list)
for i in range(len(infile_list)):
if obs_dict['OBJECT'][i].upper().strip()=='ARC' and obs_dict['PROPID'][i].upper().strip()==propcode:
lamp=obs_dict['LAMPID'][i].strip().replace(' ', '')
arcimage=os.path.basename(infile_list[i])
if lamp == 'NONE': lamp='CuAr'
lampfile=iraf.osfn("pysalt$data/linelists/%s.salt" % lamp)
#lampfile='/Users/crawford/research/kepler/Xe.salt'
specidentify(arcimage, lampfile, dbfile, guesstype='rss',
guessfile='', automethod=automethod, function='legendre', order=3,
rstep=100, rstart='middlerow', mdiff=20, thresh=3, niter=5, smooth=3,
inter=inter, clobber=True, logfile=logfile, verbose=True)
#specrectify(arcimage, outimages='', outpref='x', solfile=dbfile, caltype='line',
# function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None,
# blank=0.0, clobber=True, logfile=logfile, verbose=True)
objimages=''
spec_list=[]
for i in range(len(infile_list)):
if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS') and obs_dict['PROPID'][i].upper().strip()==propcode:
img = infile_list[i]
##rectify it
specrectify(img, outimages='', outpref='x', solfile=dbfile, caltype='line',
function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None,
blank=0.0, nearest=True, clobber=True, logfile=logfile, verbose=True)
示例14: createbadpixel
def createbadpixel(inhdu, bphdu, sci_ext, bp_ext):
"""Create the bad pixel hdu from a bad pixel hdu"""
if bphdu is None:
data=inhdu[sci_ext].data*0.0
else:
infile=inhdu._HDUList__file.name
bpfile=bphdu._HDUList__file.name
if not saltkey.compare(inhdu[0], bphdu[0], 'INSTRUME', infile, bpfile):
message = '%s and %s are not the same %s' % (infile,bpfile, 'INSTRUME')
raise SaltError(message)
for k in ['CCDSUM', 'NAXIS1', 'NAXIS2']:
if not saltkey.compare(inhdu[sci_ext], bphdu[sci_ext], k, infile, bpfile):
message = '%s and %s are not the same %s' % (infile,bpfile, k)
raise SaltError(message)
data=bphdu[sci_ext].data.copy()
header=inhdu[sci_ext].header.copy()
header['EXTVER']=bp_ext
header.update('SCIEXT',sci_ext,comment='Extension of science frame')
return pyfits.ImageHDU(data=data, header=header, name='BPM')
# -----------------------------------------------------------
# main code
if not iraf.deftask('saltprepare'):
parfile = iraf.osfn("saltred$saltprepare.par")
t = iraf.IrafTaskFactory(taskname="saltprepare",value=parfile,function=saltprepare, pkgname='saltred')
示例15: masktool
from pyraf.iraf import pysalt
import os, string, sys, glob, pyfits, time
from PyQt4 import QtCore, QtGui
from pySlitMask import SlitMaskGui
from saltsafelog import logging, history
from salterror import SaltError
debug=True
# -----------------------------------------------------------
# core routine
def masktool(catalog='', image='', logfile='salt.log', verbose=True):
with logging(logfile,debug) as log:
app = QtGui.QApplication([])
myapp = SlitMaskGui(infile=catalog, inimage=image)
myapp.show()
app.exec_()
# -----------------------------------------------------------
# main code
parfile = iraf.osfn("proptools$masktool.par")
t = iraf.IrafTaskFactory(taskname="masktool",value=parfile,function=masktool, pkgname='proptools')