Skip to content

Commit

Permalink
Merge pull request #28 from mcara/fix-new-table
Browse files Browse the repository at this point in the history
Fix for removed 'new_table'
  • Loading branch information
pllim committed Jan 19, 2017
2 parents 4f56c9c + dcd20b7 commit a7e1a95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
36 changes: 18 additions & 18 deletions commissioning/basecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def hasSkyLines(self):
return True
else:
return False

def setglobal(self,fname=None):
if fname is None:
fname=__file__
Expand All @@ -37,7 +37,7 @@ def setglobal(self,fname=None):
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
Expand All @@ -64,7 +64,7 @@ def setglobal(self,fname=None):
self.tda['form']=self.form
except AttributeError:
pass

self.tra={}

def run_crbox(self,spstring,form,output="",wavecat="INDEF",
Expand All @@ -79,7 +79,7 @@ def run_crbox(self,spstring,form,output="",wavecat="INDEF",
form=form,
wavecat=wavecat,
output=output)


def run_countrate(self,form,output=None):
if output is None:
Expand All @@ -97,7 +97,7 @@ def run_countrate(self,form,output=None):

if count == 10:
raise(e)

def runpy(self):
self.sptest=etc.parse_spec(self.spectrum)
self.csname=self.name+'.fits'
Expand Down Expand Up @@ -138,7 +138,7 @@ def count_outliers(self,Nsigma=3):
std=self.adiscrep.std()
outliers=N.where(abs(self.adiscrep) > mean + Nsigma*std)
return len(outliers[0])

def arraytest(self,test,ref):
#Exclude the endpoints where the gradient is very steep
self.adiscrep=self.arraydiff(test,ref)#[2:-2]
Expand Down Expand Up @@ -171,7 +171,7 @@ def savepysyn(self,wave,flux,fname,units=None):
ytype='flux'
col1=pyfits.Column(name='wavelength',format='D',array=wave)
col2=pyfits.Column(name=ytype,format='D',array=flux)
tbhdu=pyfits.new_table(pyfits.ColDefs([col1,col2]))
tbhdu=pyfits.BinTableHDU.from_columns(pyfits.ColDefs([col1,col2]))
tbhdu.header.update('tunit1','angstrom')
tbhdu.header.update('tunit2',units)
tbhdu.writeto(fname.replace('.fits','_pysyn.fits'))
Expand Down Expand Up @@ -203,7 +203,7 @@ def testcrspec(self):

if count == 10:
raise e

os.unlink(wname)

#Now do the comparison
Expand All @@ -212,7 +212,7 @@ def testcrspec(self):
rflux=spref.flux[ridx]
tflux=self.sptest(spref.wave[ridx])
self.arraysigtest(tflux,rflux)

class calcphotCase(calcspecCase):
Extrap=None
def runpy(self):
Expand All @@ -228,10 +228,10 @@ def runpy(self):
except OSError:
pass
self.discrep=-99







def testthru(self):
iraf.calcband(obsmode=self.obsmode,output=self.cbname)
ref=S.FileBandpass(self.cbname)
Expand All @@ -241,7 +241,7 @@ def testthru(self):
self.savepysyn(rwave,tthru,self.cbname)
self.arraysigtest(tthru,rthru)


def testefflam(self):
iraf.calcphot(obsmode=self.obsmode,spectrum=self.spectrum,
form='photlam', func='efflerg')
Expand Down Expand Up @@ -286,10 +286,10 @@ def testthru(self):
__test__ = False
def testefflam(self):
__test__ = False


class thermbackCase(calcspecCase):

def runpy(self):

#self.sptest=etc.parse_spec(self.spectrum)
Expand Down Expand Up @@ -334,7 +334,7 @@ def testcrspec(self):
## if N.any(self.sp.wave != ref.wave):
## raise ValueError('wave arrays not equal')
## self.arraysigtest(self.sp.flux,ref.flux)

def testthermback(self):
iraf.thermback(obsmode=self.obsmode,form='counts')
rtherm=iraf.thermback.getParam('thermback.thermflux',native=1)
Expand Down Expand Up @@ -378,7 +378,7 @@ def testcrphotlam(self):
tflux=obs.binflux[tidx]
self.savepysyn(obs.binwave,obs.binflux,
self.crname,units='photlam')

self.arraysigtest(tflux,rflux)

def testcrcounts(self):
Expand All @@ -395,7 +395,7 @@ def testcrcounts(self):
units='counts')
if N.any(obs.binwave != spref.wave):
raise ValueError('wave arrays not equal')

self.arraysigtest(tflux,rflux)

def testcountrate(self):
Expand Down
12 changes: 6 additions & 6 deletions commissioning/doscalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def getdata(dirpath,fieldname,instr,save=True):
nfiles=len(flist)
if nfiles == 0:
raise ValueError('No files found')

val=N.zeros((nfiles,),dtype=N.float64)
obsmode=N.zeros((nfiles,),dtype=N.float64)
spectrum=N.zeros((nfiles,),dtype=N.float64)
Expand All @@ -26,7 +26,7 @@ def getdata(dirpath,fieldname,instr,save=True):
scount=0
namedict={}
i=0

#
# Start processing
for fname in flist:
Expand All @@ -45,7 +45,7 @@ def getdata(dirpath,fieldname,instr,save=True):
sdict[sp]=scount
scount+=1
spectrum[i]=sdict[sp]

try:
val[i]=float(d['tra_discrep'])
except KeyError:
Expand All @@ -68,7 +68,7 @@ def getdata(dirpath,fieldname,instr,save=True):
c5=pyfits.Column(name='discrep',format='D',
array=val)

tbhdu=pyfits.new_table(pyfits.ColDefs([c1,c2,c3,c4,c5]))
tbhdu=pyfits.BinTableHDU.from_columns(pyfits.ColDefs([c1,c2,c3,c4,c5]))
outname=os.path.join(os.path.abspath(os.path.dirname(dirpath)),
"%s_%s_table.fits"%(instr,fieldname))
tbhdu.writeto(outname,clobber=True)
Expand All @@ -87,7 +87,7 @@ def plotdata(obsmode,spectrum,val,odict,sdict,
instr,fieldname,outdir,outname):
isetting=P.isinteractive()
P.ioff()

P.clf()
P.plot(obsmode,val,'.')
P.ylabel('(pysyn-syn)/syn')
Expand All @@ -105,7 +105,7 @@ def plotdata(obsmode,spectrum,val,odict,sdict,
matplotlib.interactive(isetting)

def run(dirpath, fieldname, instr):

namedict,odict,sdict,obsmode,spectrum,val = getdata(dirpath,
fieldname,
instr)
Expand Down
12 changes: 6 additions & 6 deletions commissioning/extrap/extrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run(fname,outdir=None):

if outdir is not None and not os.path.isdir(outdir):
os.mkdir(outdir)

dwave=0.001
f=pyfits.open(fname)
nonparam,error=classify_file(f)
Expand All @@ -59,7 +59,7 @@ def run(fname,outdir=None):
if ok:
f.close()
return "%s: no change necessary"%fname


#If not ok, we fall through to here.
#We're going to have to make a new hdu
Expand Down Expand Up @@ -93,7 +93,7 @@ def run(fname,outdir=None):
clist.append(tc)

#Now we have all the columns; put them in an HDU
tbhdu=pyfits.new_table(clist)
tbhdu=pyfits.BinTableHDU.from_columns(clist)
#and copy in the header information we need
h=f[1].header.copy()
h.update('NAXIS1',tbhdu.header['NAXIS1'])
Expand Down Expand Up @@ -125,7 +125,7 @@ def blue(fname,outdir=None):
"""Cut&pasted from run, but to operate only on blue end."""
if outdir is not None and not os.path.isdir(outdir):
os.mkdir(outdir)

dwave=0.001
f=pyfits.open(fname)
nonparam,error=classify_file(f)
Expand All @@ -144,7 +144,7 @@ def blue(fname,outdir=None):
if ok:
f.close()
return "%s: no change necessary"%fname


#If not ok, we fall through to here.
#We're going to have to make a new hdu
Expand Down Expand Up @@ -178,7 +178,7 @@ def blue(fname,outdir=None):
clist.append(tc)

#Now we have all the columns; put them in an HDU
tbhdu=pyfits.new_table(clist)
tbhdu=pyfits.BinTableHDU.from_columns(clist)
#and copy in the header information we need
h=f[1].header.copy()
h.update('NAXIS1',tbhdu.header['NAXIS1'])
Expand Down

0 comments on commit a7e1a95

Please sign in to comment.