From 164bfa4006481708b29ca3ec753020d83b3196fa Mon Sep 17 00:00:00 2001 From: Jeremy Kubica <104161096+jeremykubica@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:50:06 -0500 Subject: [PATCH 1/2] Initial Version --- src/kbmod/run_search.py | 56 ++--------------------------------------- src/kbmod/wcs_utils.py | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/kbmod/run_search.py b/src/kbmod/run_search.py index eb71c3247..d1b36ffe6 100644 --- a/src/kbmod/run_search.py +++ b/src/kbmod/run_search.py @@ -2,13 +2,8 @@ import time import warnings -import astropy.coordinates as astroCoords -import astropy.units as u import koffi import numpy as np -from astropy.coordinates import solar_system_ephemeris -from astropy.time import Time -from numpy.linalg import lstsq import kbmod.search as kb @@ -19,6 +14,7 @@ from .filters.stamp_filters import append_all_stamps, get_coadds_and_filter from .masking import apply_mask_operations from .result_list import * +from .wcs_utils import calc_ecliptic_angle from .work_unit import WorkUnit @@ -224,7 +220,7 @@ def run_search_from_work_unit(self, work): if work.config["average_angle"] is None: center_pixel = (work.im_stack.get_width() / 2, work.im_stack.get_height() / 2) if work.get_wcs(0) is not None: - work.config.set("average_angle", self._calc_suggested_angle(work.get_wcs(0), center_pixel)) + work.config.set("average_angle", calc_ecliptic_angle(work.get_wcs(0), center_pixel)) else: print("WARNING: average_angle is unset and no WCS provided. Using 0.0.") work.config.set("average_angle", 0.0) @@ -332,51 +328,3 @@ def _count_known_matches(self, result_list, search): if num_found > 0: print(matches_string) print("-----------------") - - def _calc_suggested_angle(self, wcs, center_pixel=(1000, 2000), step=12): - """Projects an unit-vector parallel with the ecliptic onto the image - and calculates the angle of the projected unit-vector in the pixel - space. - - Parameters - ---------- - wcs : ``astropy.wcs.WCS`` - World Coordinate System object. - center_pixel : tuple, array-like - Pixel coordinates of image center. - step : ``float`` or ``int`` - Size of step, in arcseconds, used to find the pixel coordinates of - the second pixel in the image parallel to the ecliptic. - - Returns - ------- - suggested_angle : ``float`` - Angle the projected unit-vector parallel to the ecliptic - closes with the image axes. Used to transform the specified - search angles, with respect to the ecliptic, to search angles - within the image. - - Note - ---- - It is not neccessary to calculate this angle for each image in an - image set if they have all been warped to a common WCS. - """ - # pick a starting pixel approximately near the center of the image - # convert it to ecliptic coordinates - start_pixel = np.array(center_pixel) - start_pixel_coord = astroCoords.SkyCoord.from_pixel(start_pixel[0], start_pixel[1], wcs) - start_ecliptic_coord = start_pixel_coord.geocentrictrueecliptic - - # pick a guess pixel by moving parallel to the ecliptic - # convert it to pixel coordinates for the given WCS - guess_ecliptic_coord = astroCoords.SkyCoord( - start_ecliptic_coord.lon + step * u.arcsec, - start_ecliptic_coord.lat, - frame="geocentrictrueecliptic", - ) - guess_pixel_coord = guess_ecliptic_coord.to_pixel(wcs) - - # calculate the distance, in pixel coordinates, between the guess and - # the start pixel. Calculate the angle that represents in the image. - x_dist, y_dist = np.array(guess_pixel_coord) - start_pixel - return np.arctan2(y_dist, x_dist) diff --git a/src/kbmod/wcs_utils.py b/src/kbmod/wcs_utils.py index 06ba24176..6f99c51c1 100644 --- a/src/kbmod/wcs_utils.py +++ b/src/kbmod/wcs_utils.py @@ -280,6 +280,53 @@ def _calc_actual_image_fov(wcs, ref_pixel, image_size): return refsep2 +def calc_ecliptic_angle(self, wcs, center_pixel=(1000, 2000), step=12): + """Projects an unit-vector parallel with the ecliptic onto the image + and calculates the angle of the projected unit-vector in the pixel space. + + Parameters + ---------- + wcs : ``astropy.wcs.WCS`` + World Coordinate System object. + center_pixel : tuple, array-like + Pixel coordinates of image center. + step : ``float`` or ``int`` + Size of step, in arcseconds, used to find the pixel coordinates of + the second pixel in the image parallel to the ecliptic. + + Returns + ------- + suggested_angle : ``float`` + Angle the projected unit-vector parallel to the eclipticc closes + with the image axes. Used to transform the specified search angles, + with respect to the ecliptic, to search angles within the image. + + Note + ---- + It is not neccessary to calculate this angle for each image in an + image set if they have all been warped to a common WCS. + """ + # pick a starting pixel approximately near the center of the image + # convert it to ecliptic coordinates + start_pixel = numpy.array(center_pixel) + start_pixel_coord = astropy.coordinates.SkyCoord.from_pixel(start_pixel[0], start_pixel[1], wcs) + start_ecliptic_coord = start_pixel_coord.geocentrictrueecliptic + + # pick a guess pixel by moving parallel to the ecliptic + # convert it to pixel coordinates for the given WCS + guess_ecliptic_coord = astropy.coordinates.SkyCoord( + start_ecliptic_coord.lon + step * u.arcsec, + start_ecliptic_coord.lat, + frame="geocentrictrueecliptic", + ) + guess_pixel_coord = guess_ecliptic_coord.to_pixel(wcs) + + # calculate the distance, in pixel coordinates, between the guess and + # the start pixel. Calculate the angle that represents in the image. + x_dist, y_dist = numpy.array(guess_pixel_coord) - start_pixel + return numpy.arctan2(y_dist, x_dist) + + def extract_wcs_from_hdu_header(header): """Read an WCS from the an HDU header and do basic validity checking. From 67f95c7f9b2653ee6a074140990072bd516e0345 Mon Sep 17 00:00:00 2001 From: Jeremy Kubica <104161096+jeremykubica@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:00:49 -0500 Subject: [PATCH 2/2] Fixes --- src/kbmod/wcs_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kbmod/wcs_utils.py b/src/kbmod/wcs_utils.py index 6f99c51c1..661977c9b 100644 --- a/src/kbmod/wcs_utils.py +++ b/src/kbmod/wcs_utils.py @@ -280,7 +280,7 @@ def _calc_actual_image_fov(wcs, ref_pixel, image_size): return refsep2 -def calc_ecliptic_angle(self, wcs, center_pixel=(1000, 2000), step=12): +def calc_ecliptic_angle(wcs, center_pixel=(1000, 2000), step=12): """Projects an unit-vector parallel with the ecliptic onto the image and calculates the angle of the projected unit-vector in the pixel space. @@ -315,7 +315,7 @@ def calc_ecliptic_angle(self, wcs, center_pixel=(1000, 2000), step=12): # pick a guess pixel by moving parallel to the ecliptic # convert it to pixel coordinates for the given WCS guess_ecliptic_coord = astropy.coordinates.SkyCoord( - start_ecliptic_coord.lon + step * u.arcsec, + start_ecliptic_coord.lon + step * astropy.units.arcsec, start_ecliptic_coord.lat, frame="geocentrictrueecliptic", )