Skip to content

Commit

Permalink
Merge pull request #40 from esheldon/piff
Browse files Browse the repository at this point in the history
Piff
  • Loading branch information
esheldon authored Dec 12, 2019
2 parents 2cb8784 + 827ceb0 commit 1b41225
Showing 1 changed file with 22 additions and 64 deletions.
86 changes: 22 additions & 64 deletions meds/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,24 @@ def _get_wcs(self, file_id):
either load the wcs from the image_info, or from
the image header
"""
if hasattr(self, 'psf_data'):
psf = self.psf_data[file_id]
if hasattr(psf, 'get_wcs'):
wcs = psf.get_wcs()

impath = self.image_info['image_path'][file_id].strip()
ext = self.image_info['image_ext'][file_id]
hdr = fitsio.read_header(impath, ext=ext)

if 'znaxis1' in hdr:
naxis = numpy.array([hdr['znaxis1'], hdr['znaxis2']])
else:
naxis = numpy.array([hdr['naxis1'], hdr['naxis2']])

wcs.set_naxis(naxis)

return wcs

if 'wcs' in self.image_info.dtype.names:
wcs_string = self.image_info['wcs'][file_id]
wcs_data = json.loads(wcs_string)
Expand Down Expand Up @@ -1218,27 +1236,18 @@ def _set_psf_data(self, psf_data):
"size as image info struct")

assert 'psf' in self, 'you must have a psf entry when loading psfs'
assert self['psf']['type'] == 'psfex', \
'only psf type psfex" supported'

self.psf_data=psf_data

def _set_psf_layout(self):
"""
set the box sizes and start row for each psf image
"""
if self.psf_data is None:
raise ValueError("_set_psf_layout called "
"with no psf data set")

if self['psf']['type'] == 'psfex':
self._set_layout_psfex()
else:
raise ValueError('psf type %s not one of the allowed '
'values ["psfex"]' % self['psf']['type'])

def _set_layout_psfex(self):
"""
set the box sizes and start row for each psf image
"""
print('setting psf layout for PSFEx')
print('setting psf layout')

obj_data=self.obj_data
psf_data=self.psf_data
Expand Down Expand Up @@ -1276,57 +1285,6 @@ def _set_layout_psfex(self):

self.total_psf_pixels = total_psf_pixels

def _set_layout_psfex_old(self):
"""
set the box sizes and start row for each psf image
"""
obj_data=self.obj_data
psf_data=self.psf_data

total_psf_pixels = 0

#psf_npix = psf_size*psf_size

psf_start_row = 0
psf_shape=None
for iobj in xrange(obj_data.size):
for icut in xrange(obj_data['ncutout'][iobj]):

row = obj_data['orig_row'][iobj, icut]
col = obj_data['orig_col'][iobj, icut]
file_id = obj_data['file_id'][iobj,icut]

p = psf_data[file_id]

pim = p.get_rec(row,col)
cen = p.get_center(row,col)
try:
sigma = p.get_sigma(row,col)
except:
sigma = p.get_sigma()

if psf_shape is None:
psf_shape = pim.shape
psf_npix = psf_shape[0]**2
obj_data['psf_box_size'] = psf_shape[0]
else:
tpsf_shape = pim.shape
if tpsf_shape != psf_shape:
raise ValueError("currently all psfs "
"must be same size")


obj_data['psf_cutout_row'][iobj,icut] = cen[0]
obj_data['psf_cutout_col'][iobj,icut] = cen[1]
obj_data['psf_sigma'][iobj,icut] = sigma
obj_data['psf_start_row'][iobj,icut] = psf_start_row

psf_start_row += psf_npix
total_psf_pixels += psf_npix


self.total_psf_pixels = total_psf_pixels

def _check_required_obj_data_fields(self, obj_data):
"""
make sure the input structure has the required fields
Expand Down

0 comments on commit 1b41225

Please sign in to comment.