From e96c8a30fa23956183e727f4cd75c1ce88b32ada Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 10 Dec 2019 15:31:22 -0500 Subject: [PATCH 1/2] working on piff and pixmappy --- meds/maker.py | 86 +++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 65 deletions(-) diff --git a/meds/maker.py b/meds/maker.py index a3546f0..cb0cd64 100644 --- a/meds/maker.py +++ b/meds/maker.py @@ -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) @@ -1218,27 +1236,16 @@ 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): - 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') + if self.psf_data is None: + raise ValueError("_set_psf_layout called " + "with no psf data set") obj_data=self.obj_data psf_data=self.psf_data @@ -1276,57 +1283,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 From 827ceb01d7bc21eb98837dd1e5d852436ba4e93d Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 10 Dec 2019 21:14:03 -0500 Subject: [PATCH 2/2] print setting layout psf --- meds/maker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meds/maker.py b/meds/maker.py index cb0cd64..7585bef 100644 --- a/meds/maker.py +++ b/meds/maker.py @@ -1247,6 +1247,8 @@ def _set_psf_layout(self): raise ValueError("_set_psf_layout called " "with no psf data set") + print('setting psf layout') + obj_data=self.obj_data psf_data=self.psf_data