Skip to content

Commit

Permalink
fix: None return if no match
Browse files Browse the repository at this point in the history
fix: None return if no match
  • Loading branch information
lgrcia authored Jul 21, 2023
2 parents b6bdf87 + 32b2e83 commit 224026e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 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.0"
version = "0.4.1"
description = "Astrometric plate solving in Python"
authors = ["Lionel J. Garcia <lionel_garcia@live.fr>"]
maintainers = [
Expand Down
19 changes: 12 additions & 7 deletions twirl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def compute_wcs(
Returns
-------
astropy.wcs.WCS
WCS solution for the image
WCS solution for the image if a match can be computed, None otherwise.
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.
"""
M = find_transform(
radecs,
Expand All @@ -49,12 +51,15 @@ def compute_wcs(
min_match=min_match,
quads_tolerance=quads_tolerance,
)
radecs_xy = (M @ pad(radecs).T)[0:2].T
i, j = cross_match(pixel_coords, radecs_xy).T
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"))
if M is None:
return None
else:
radecs_xy = (M @ pad(radecs).T)[0:2].T
i, j = cross_match(pixel_coords, radecs_xy).T
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"))


def gaia_radecs(
Expand Down
10 changes: 6 additions & 4 deletions twirl/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def find_transform(
if match >= min_match * len(pixels):
break

i, j = pairs[np.argmax(matches)]
M = get_transform_matrix(asterism_radecs[j], asterism_pixels[i])

return M
if len(matches) == 0:
return None
else:
i, j = pairs[np.argmax(matches)]
M = get_transform_matrix(asterism_radecs[j], asterism_pixels[i])
return M

0 comments on commit 224026e

Please sign in to comment.