Skip to content

Commit

Permalink
fix(#30): adding tangent plane projection
Browse files Browse the repository at this point in the history
fix(#30): adding tangent plane projection
  • Loading branch information
lgrcia authored Oct 25, 2023
2 parents 9f9460b + 9516874 commit cbba45e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "twirl"
version = "0.4.1"
version = "0.4.2"
description = "Astrometric plate solving in Python"
authors = ["Lionel J. Garcia <lionel_garcia@live.fr>"]
maintainers = [
Expand Down
19 changes: 18 additions & 1 deletion twirl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
from twirl.match import cross_match, find_transform, get_transform_matrix


def _project_tangent_plane(center, skycoords):
# Calculate the tangent plane projection
tangent_plane_coords = skycoords.transform_to(center.skyoffset_frame())

# Access the projected coordinates
tangent_ra = tangent_plane_coords.lon
tangent_dec = tangent_plane_coords.lat

return np.array([tangent_ra.deg, tangent_dec.deg])


def compute_wcs(
pixel_coords: np.ndarray,
radecs: np.ndarray,
Expand Down Expand Up @@ -43,6 +54,10 @@ def compute_wcs(
A match is considered to be computed if at least one source and one target
star are located less than `tolerance` pixels away from each other.
"""
original_radecs = radecs.copy()
center = SkyCoord(*radecs.mean(0), unit="deg")
radecs = _project_tangent_plane(center, SkyCoord(radecs, unit="deg")).T

M = find_transform(
radecs,
pixel_coords,
Expand All @@ -59,7 +74,9 @@ def compute_wcs(
M = get_transform_matrix(radecs[j], pixel_coords[i])
radecs_xy = (M @ pad(radecs).T)[0:2].T
i, j = cross_match(pixel_coords, radecs_xy).T
return fit_wcs_from_points(pixel_coords[i].T, SkyCoord(radecs[j], unit="deg"))
return fit_wcs_from_points(
pixel_coords[i].T, SkyCoord(original_radecs[j], unit="deg")
)


def gaia_radecs(
Expand Down

0 comments on commit cbba45e

Please sign in to comment.