Skip to content

Commit

Permalink
Merge pull request #14 from mwcraig/more-photometry-cleanup
Browse files Browse the repository at this point in the history
More photometry cleanup
  • Loading branch information
mwcraig authored Aug 17, 2020
2 parents 056dd77 + cd09be9 commit 00063cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
7 changes: 6 additions & 1 deletion stellarphot/differential_photometry/aij_rel_fluxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def calc_aij_relative_flux(star_data, comp_stars,

star_data['relative_flux'] = relative_flux
star_data['relative_flux_error'] = rel_flux_error
star_data['comparison counts'] = comp_total_vector + flux_offset
star_data['relative_flux_snr'] = relative_flux / rel_flux_error

# AIJ records the total comparison counts even though that total is used
# only for the targets, not the comparison.
star_data['comparison counts'] = comp_total_vector # + flux_offset
star_data['comparison error'] = comp_error_vector

return star_data
12 changes: 8 additions & 4 deletions stellarphot/io/aij.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def generate_aij_table(table_name, comparison_table):
info_columns = {
'date-obs': 'DATE_OBS',
'airmass': 'AIRMASS',
# 'BJD': 'BJD_MOBS',
'BJD': 'BJD_MOBS',
'exposure': 'EXPOSURE',
'filter': 'FILTER',
'aperture': 'Source_Radius',
Expand All @@ -187,9 +187,11 @@ def generate_aij_table(table_name, comparison_table):
'fwhm_x': 'X-Width',
'fwhm_y': 'Y-Width',
'width': 'Width',
#'relative flux': 'rel_flux',
#'flux error': 'rel_flux_err',
#'comparison counts': 'tot_C_cnts',
'relative_flux': 'rel_flux',
'relative_flux_error': 'rel_flux_err',
'rel_flux_SNR': 'rel_flux_SNR',
'comparison counts': 'tot_C_cnts',
'tot_C_err': 'tot_C_err'
}
by_star = table_name.group_by('star_id')
base_table = by_star.groups[0][list(info_columns.keys())]
Expand All @@ -208,6 +210,8 @@ def generate_aij_table(table_name, comparison_table):
new_column_name = new_col + f'_{char}{star_id[0]}'
new_table.rename_column(old_col, new_column_name)
base_table = hstack([base_table, new_table])
for old_col, new_col in info_columns.items():
base_table.rename_column(old_col, new_col)

return base_table

Expand Down
13 changes: 13 additions & 0 deletions stellarphot/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,15 @@ def add_to_photometry_table(phot, ccd, annulus, apertures, fname='',
# Add width x/y:
# Make small table with renamed columns
fwhm_x, fwhm_y = compute_fwhm(ccd, phot)
# Set bad values to NaN now
bad_fwhm = (fwhm_x < 0) | (fwhm_y < 0)
fwhm_x[bad_fwhm] = np.nan
fwhm_y[bad_fwhm] = np.nan

phot['fwhm_x'] = fwhm_x
phot['fwhm_y'] = fwhm_y
phot['width'] = (fwhm_x + fwhm_y) / 2

phot['sky_per_pix_avg'] = avg_sky_per_pix
phot['sky_per_pix_med'] = med_sky_per_pix
phot['sky_per_pix_std'] = std_sky_per_pix
Expand All @@ -328,6 +334,13 @@ def add_to_photometry_table(phot, ccd, annulus, apertures, fname='',
(phot['aperture_area'] *
phot['sky_per_pix_avg']))

# This can happen, for example, when the object is faint
# and centroiding is bad.
bad_flux = phot['aperture_net_flux'] < 0
all_bads = bad_flux | bad_fwhm

phot['aperture_net_flux'][all_bads] = np.nan

if camera is not None:
phot['mag_inst_{}'.format(ccd.header['filter'])] = \
(-2.5 * np.log10(camera.gain * phot['aperture_net_flux'].value /
Expand Down

0 comments on commit 00063cc

Please sign in to comment.