Skip to content

Commit

Permalink
added code to run se and psfex on Bok images but currently segfaults …
Browse files Browse the repository at this point in the history
…when psfex called. It does not look like se is running correctly either as I usually see it count up the sources as it finds them....
  • Loading branch information
kaylanb committed May 5, 2016
1 parent c2a2aa0 commit a820d22
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 77 deletions.
118 changes: 53 additions & 65 deletions py/legacypipe/bok.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import fitsio
import numpy as np

from legacypipe.image import LegacySurveyImage, CalibMixin
#from legacypipe.cpimage import CPImage
from image import LegacySurveyImage
from common import create_temp
from astrometry.util.util import Tan, Sip, anwcs_t
Expand All @@ -16,21 +18,21 @@
from tractor.image import Image
from tractor.tractortime import TAITime

from legacypipe.ptf import zeropoint_for_ptf


'''
Code specific to images from the 90prime camera on the Bok telescope.
'''

class BokImage(LegacySurveyImage):

#class BokImage(LegacySurveyImage):
class BokImage(LegacySurveyImage, CalibMixin):
'''
A LegacySurveyImage subclass to handle images from the 90prime
camera on the Bok telescope.
'''
def __init__(self, survey, t):
super(BokImage, self).__init__(survey, t)
self.pixscale= 0.455
self.dqfn= self.read_dq() #array of 0s for now
self.whtfn= self.imgfn.replace('.fits','.wht.fits')

self.calname = os.path.basename(self.imgfn).replace('.fits','')
Expand Down Expand Up @@ -94,70 +96,56 @@ def get_wcs(self):
wcs.plver = ''
return wcs

def run_calibs(self, psfex=True, sky=True, funpack=False, git_version=None,
force=False,
**kwargs):
def run_calibs(self, psfex=True, sky=True, se=False,
funpack=False, fcopy=False, use_mask=True,
force=False, just_check=False, git_version=None,
splinesky=False,**kwargs):

'''
Run calibration pre-processing steps.
Parameters
----------
just_check: boolean
If True, returns True if calibs need to be run.
'''
print('run_calibs for', self.name, ': sky=', sky, 'kwargs', kwargs)
se = False
##################
#from decam.py
from .common import (create_temp, get_version_header,
get_git_version)

if psfex and os.path.exists(self.psffn) and (not force):
psfex = False
if self.check_psf(self.psffn):
psfex = False
if psfex:
se = True

if se and os.path.exists(self.sefn) and (not force):
se = False
if self.check_se_cat(self.sefn):
se = False
if se:
sedir = self.survey.get_se_dir()
trymakedirs(self.sefn, dir=True)
####
trymakedirs('junk',dir=True) #need temp dir for mask-2 and invvar map
hdu=0
maskfn= self.imgfn.replace('_scie_','_mask_')
#invvar= self.read_invvar(self.imgfn,maskfn,hdu) #note, all post processing on image,mask done in read_invvar
invvar= self.read_invvar()
mask= self.read_dq()
maskfn= os.path.join('junk',os.path.basename(maskfn))
invvarfn= maskfn.replace('_mask_','_invvar_')
fitsio.write(maskfn, mask)
fitsio.write(invvarfn, invvar)
print('wrote mask-2 to %s, invvar to %s' % (maskfn,invvarfn))
#run se
hdr=fitsio.read_header(self.imgfn,ext=hdu)
magzp = zeropoint_for_ptf(hdr)
seeing = hdr['PIXSCALE'] * hdr['MEDFWHM']
gain= hdr['GAIN']
cmd = ' '.join(['sex','-c', os.path.join(sedir,'ptf.se'),
'-WEIGHT_IMAGE %s' % invvarfn, '-WEIGHT_TYPE MAP_WEIGHT',
'-GAIN %f' % gain,
'-FLAG_IMAGE %s' % maskfn,
'-FLAG_TYPE OR',
'-SEEING_FWHM %f' % seeing,
'-DETECT_MINAREA 3',
'-PARAMETERS_NAME', os.path.join(sedir,'ptf.param'),
'-FILTER_NAME', os.path.join(sedir, 'ptf_gauss_3.0_5x5.conv'),
'-STARNNW_NAME', os.path.join(sedir, 'ptf_default.nnw'),
'-PIXEL_SCALE 0',
# SE has a *bizarre* notion of "sigma"
'-DETECT_THRESH 1.0',
'-ANALYSIS_THRESH 1.0',
'-MAG_ZEROPOINT %f' % magzp,
'-CATALOG_NAME', self.sefn,
self.imgfn])
print(cmd)
if os.system(cmd):
raise RuntimeError('Command failed: ' + cmd)
if psfex:
sedir = self.survey.get_se_dir()
trymakedirs(self.psffn, dir=True)
# If we wrote *.psf instead of *.fits in a previous run...
oldfn = self.psffn.replace('.fits', '.psf')
if os.path.exists(oldfn):
print('Moving', oldfn, 'to', self.psffn)
os.rename(oldfn, self.psffn)
else:
cmd= ' '.join(['psfex',self.sefn,'-c', os.path.join(sedir,'ptf.psfex'),
'-PSF_DIR',os.path.dirname(self.psffn)])
print(cmd)
if os.system(cmd):
raise RuntimeError('Command failed: ' + cmd)

funpack = True

if just_check:
return (se or psfex)

todelete = []
#if funpack:
# # The image & mask files to process (funpacked if necessary)
# imgfn,maskfn = self.funpack_files(self.imgfn, self.dqfn, self.hdu, todelete)
#else:
# imgfn,maskfn = self.imgfn,self.dqfn
imgfn,maskfn = self.imgfn,self.dqfn
print('----TEMPORARILY FORCING se and psfex to run for testing ------')
#if se:
self.run_se('90prime', imgfn, 'junkname')
#if psfex:
self.run_psfex('90prime')

print('exiting early')
import sys
sys.exit()

#############

31 changes: 19 additions & 12 deletions py/legacypipe/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,23 +681,26 @@ def run_se(self, surveyname, imgfn, maskfn):

sedir = self.survey.get_se_dir()
trymakedirs(self.sefn, dir=True)

cmd = ' '.join([
'sex',
'-c', os.path.join(sedir, surveyname + '.se'),
'-FLAG_IMAGE ' + maskfn,
'-SEEING_FWHM %f' % seeing,
'-PARAMETERS_NAME', os.path.join(sedir, surveyname + '.param'),
'-FILTER_NAME', os.path.join(sedir, 'gauss_5.0_9x9.conv'),
'-STARNNW_NAME', os.path.join(sedir, 'default.nnw'),
'-PIXEL_SCALE 0',
# SE has a *bizarre* notion of "sigma"
'-DETECT_THRESH 1.0',
'-ANALYSIS_THRESH 1.0',
'-MAG_ZEROPOINT %f' % magzp,
'-CATALOG_NAME', self.sefn,
imgfn])
'-MAG_ZEROPOINT %f' % magzp])
if surveyname == '90prime':
cmd+= ' -PHOT_APERTURES 7.5,15.0,22.0'
cmd+= ' -FILTER_NAME %s' % os.path.join(sedir, surveyname + '.conv') #sextractor default .conv file
else:
cmd+= ' -FLAG_IMAGE %s' % maskfn #Bok does not have this
cmd+= ' -FILTER_NAME %s' % os.path.join(sedir, 'gauss_5.0_9x9.conv')
cmd+= ' -CATALOG_NAME %s %s' % (self.sefn,imgfn)
print(cmd)

if os.system(cmd):
raise RuntimeError('Command failed: ' + cmd)

Expand All @@ -709,12 +712,16 @@ def run_psfex(self, surveyname):
primhdr = self.read_image_primary_header()
plver = primhdr.get('PLVER', '')
verstr = get_git_version()
cmds = ['psfex -c %s -PSF_DIR %s %s' %
(os.path.join(sedir, surveyname + '.psfex'),
os.path.dirname(self.psffn), self.sefn),
'modhead %s LEGPIPEV %s "legacypipe git version"' %
(self.psffn, verstr),
'modhead %s PLVER %s "CP ver of image file"' % (self.psffn, plver)]
if surveyname == '90prime':
cmds = ['psfex %s -c %s -PSF_DIR %s' % \
(self.sefn, os.path.join(sedir, surveyname + '.psfex'), os.path.dirname(self.psffn))]
else:
cmds = ['psfex -c %s -PSF_DIR %s %s' %
(os.path.join(sedir, surveyname + '.psfex'),
os.path.dirname(self.psffn), self.sefn),
'modhead %s LEGPIPEV %s "legacypipe git version"' %
(self.psffn, verstr),
'modhead %s PLVER %s "CP ver of image file"' % (self.psffn, plver)]
for cmd in cmds:
print(cmd)
rtn = os.system(cmd)
Expand Down

0 comments on commit a820d22

Please sign in to comment.