Skip to content

Commit e4bc982

Browse files
authored
Merge pull request #118 from Roman-Supernova-PIT/116-record-aperture-photometry
Record aperture photometry results
2 parents c78d91a + 08cd642 commit e4bc982

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

changes/118.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add aperture photometry to output. LC output files now have "aperture_sum" and "ap_zpt" columns. Also, remove ap_phot_only kwarg in get_zpt() because this makes it obsolete. pytests pass.

phrosty/pipeline.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def phot_at_coords( self, img, err, psf, pxcoords=(50, 50), ap_r=4 ):
336336
mag_err = (2.5 / np.log(10)) * np.abs(final["flux_err"][0] / final["flux_fit"][0])
337337

338338
results_dict = {
339+
'aperture_sum': init['aperture_sum'][0],
339340
'flux_fit': flux,
340341
'flux_fit_err': flux_err,
341342
'mag_fit': mag,
@@ -379,7 +380,7 @@ def get_galsim_values(self):
379380

380381
return {'exptime': exptime, 'area_eff': area_eff, 'gs_zpt': gs_zpt}
381382

382-
def get_zpt(self, zptimg, err, psf, band, stars, ap_r=4, ap_phot_only=False,
383+
def get_zpt(self, zptimg, err, psf, band, stars, ap_r=4,
383384
zpt_plot=None, oid=None, sci_pointing=None, sci_sca=None):
384385

385386
# TODO : Need to move this code all over into snappl Image. It sounds like
@@ -401,18 +402,19 @@ def get_zpt(self, zptimg, err, psf, band, stars, ap_r=4, ap_phot_only=False,
401402
# will be in the same order.
402403
photres = astropy.table.join(stars, init_params, keys=['object_id', 'ra', 'dec', 'realized_flux',
403404
'flux_truth', 'mag_truth', 'obj_type'])
404-
if not ap_phot_only:
405-
photres = astropy.table.join(photres, final_params, keys=['id'])
405+
photres = astropy.table.join(photres, final_params, keys=['id'])
406406

407407
# Get the zero point.
408408
galsim_vals = self.get_galsim_values()
409+
star_ap_mags = -2.5 * np.log10(photres['aperture_sum'])
409410
star_fit_mags = -2.5 * np.log10(photres['flux_fit'])
410411
star_truth_mags = ( -2.5 * np.log10(photres['flux_truth']) + galsim_vals['gs_zpt']
411412
+ 2.5 * np.log10(galsim_vals['exptime'] * galsim_vals['area_eff']) )
412413

413414
# Eventually, this should be a S/N cut, not a mag cut.
414415
zpt_mask = np.logical_and(star_truth_mags > 19, star_truth_mags < 21.5)
415416
zpt = np.nanmedian(star_truth_mags[zpt_mask] - star_fit_mags[zpt_mask])
417+
ap_zpt = np.nanmedian(star_truth_mags[zpt_mask] - star_ap_mags[zpt_mask])
416418

417419
if zpt_plot is not None:
418420
assert oid is not None, 'If zpt_plot=True, oid must be provided.'
@@ -443,7 +445,7 @@ def get_zpt(self, zptimg, err, psf, band, stars, ap_r=4, ap_phot_only=False,
443445
# plt.savefig(savepath, dpi=300, bbox_inches='tight')
444446
# plt.close()
445447

446-
return zpt
448+
return zpt, ap_zpt
447449

448450
def make_phot_info_dict( self, sci_image, templ_image, ap_r=4 ):
449451
# Do photometry on stamp because it will read faster
@@ -494,11 +496,12 @@ def make_phot_info_dict( self, sci_image, templ_image, ap_r=4 ):
494496
with fits.open(zptimg_path) as hdu:
495497
zptimg = hdu[0].data
496498

497-
zpt = self.get_zpt(zptimg, sci_image.image.noise, psf, self.band, stars, oid=self.object_id,
499+
zpt, ap_zpt = self.get_zpt(zptimg, sci_image.image.noise, psf, self.band, stars, oid=self.object_id,
498500
sci_pointing=sci_image.pointing, sci_sca=sci_image.image.sca)
499501

500502
# Add additional info to the results dictionary so it can be merged into a nice file later.
501503
results_dict['zpt'] = zpt
504+
results_dict['ap_zpt'] = ap_zpt
502505
results_dict['success'] = True
503506

504507
else:
@@ -507,6 +510,8 @@ def make_phot_info_dict( self, sci_image, templ_image, ap_r=4 ):
507510
f"{self.band}_{templ_image.pointing}_{templ_image.image.sca} "
508511
f"do not exist. Skipping." )
509512
results_dict['zpt'] = np.nan
513+
results_dict['ap_zpt'] = np.nan
514+
results_dict['aperture_sum'] = np.nan
510515
results_dict['flux_fit'] = np.nan
511516
results_dict['flux_fit_err'] = np.nan
512517
results_dict['mag_fit'] = np.nan
@@ -562,6 +567,8 @@ def make_lightcurve( self ):
562567
'template_pointing': [],
563568
'template_sca': [],
564569
'zpt': [],
570+
'ap_zpt': [],
571+
'aperture_sum': [],
565572
'flux_fit': [],
566573
'flux_fit_err': [],
567574
'mag_fit': [],

0 commit comments

Comments
 (0)