From 43ccef60bcdbdfe82a00a294e9e5124726ab4f3f Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Tue, 2 Nov 2021 08:29:52 -0500 Subject: [PATCH 1/2] Make add_in_quadrature public --- stellarphot/differential_photometry/aij_rel_fluxes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stellarphot/differential_photometry/aij_rel_fluxes.py b/stellarphot/differential_photometry/aij_rel_fluxes.py index 7c2c7ac4..a9eae17d 100644 --- a/stellarphot/differential_photometry/aij_rel_fluxes.py +++ b/stellarphot/differential_photometry/aij_rel_fluxes.py @@ -3,8 +3,9 @@ from astropy.coordinates import SkyCoord import astropy.units as u +__all__ = ['add_in_quadrature', 'calc_aij_relative_flux'] -def _add_in_quadrature(array): +def add_in_quadrature(array): """ Add an array of numbers in quadrature. """ @@ -77,7 +78,7 @@ def calc_aij_relative_flux(star_data, comp_stars, comp_fluxes = comp_fluxes.group_by('date-obs') comp_totals = comp_fluxes.groups.aggregate(np.sum)[flux_column_name] comp_num_stars = comp_fluxes.groups.aggregate(np.count_nonzero)[flux_column_name] - comp_errors = comp_fluxes.groups.aggregate(_add_in_quadrature)[error_column_name] + comp_errors = comp_fluxes.groups.aggregate(add_in_quadrature)[error_column_name] comp_total_vector = np.ones_like(star_data[flux_column_name]) comp_error_vector = np.ones_like(star_data[flux_column_name]) From 5d72626116180ce3fd0b8aab8c2d105861631aeb Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Tue, 2 Nov 2021 10:45:04 -0500 Subject: [PATCH 2/2] Speed up calculation of FWHM It makes no sense at all that using .data speeds things up, but it does by a factor of ~20. --- stellarphot/source_detection.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/stellarphot/source_detection.py b/stellarphot/source_detection.py index e0ab745f..e1cbd11a 100644 --- a/stellarphot/source_detection.py +++ b/stellarphot/source_detection.py @@ -65,22 +65,27 @@ def compute_fwhm(ccd, sources, fwhm_estimate=5, except AttributeError: pass - cutout = Cutout2D(ccd, (x, y), 5 * fwhm_estimate) + cutout = Cutout2D(ccd.data, (x, y), 5 * fwhm_estimate) if fit: fit = _fit_2dgaussian(cutout.data) fwhm_x.append(gaussian_sigma_to_fwhm * fit.x_stddev_1) fwhm_y.append(gaussian_sigma_to_fwhm * fit.y_stddev_1) print('Still fitting!!') else: - dat = np.where(cutout.data - sky > 0, cutout.data - sky, 0) - mom1 = _moments(dat, order=1) - xc = mom1[0, 1] / mom1[0, 0] - yc = mom1[1, 0] / mom1[0, 0] - moments = _moments_central(dat, - center=(xc, yc), order=2) - mom_scale = (moments / mom1[0, 0]) - fwhm_xm = 2 * np.sqrt(np.log(2) * mom_scale[0, 2]) - fwhm_ym = 2 * np.sqrt(np.log(2) * mom_scale[2, 0]) + sc = data_properties(cutout.data - sky) + + # dat = np.where(cutout.data - sky > 0, cutout.data - sky, 0) + # mom1 = _moments(dat, order=1) + # xc = mom1[0, 1] / mom1[0, 0] + # yc = mom1[1, 0] / mom1[0, 0] + # moments = _moments_central(dat, + # center=(xc, yc), order=2) + # mom_scale = (moments / mom1[0, 0]) + # fwhm_xm = 2 * np.sqrt(np.log(2) * mom_scale[0, 2]) + # fwhm_ym = 2 * np.sqrt(np.log(2) * mom_scale[2, 0]) + + fwhm_xm = sc.fwhm.value + fwhm_ym = fwhm_xm fwhm_x.append(fwhm_xm) fwhm_y.append(fwhm_ym)