Skip to content

Commit 224026e

Browse files
authored
fix: None return if no match
fix: None return if no match
2 parents b6bdf87 + 32b2e83 commit 224026e

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "twirl"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
description = "Astrometric plate solving in Python"
55
authors = ["Lionel J. Garcia <[email protected]>"]
66
maintainers = [

twirl/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def compute_wcs(
3939
Returns
4040
-------
4141
astropy.wcs.WCS
42-
WCS solution for the image
42+
WCS solution for the image if a match can be computed, None otherwise.
43+
A match is considered to be computed if at least one source and one target
44+
star are located less than `tolerance` pixels away from each other.
4345
"""
4446
M = find_transform(
4547
radecs,
@@ -49,12 +51,15 @@ def compute_wcs(
4951
min_match=min_match,
5052
quads_tolerance=quads_tolerance,
5153
)
52-
radecs_xy = (M @ pad(radecs).T)[0:2].T
53-
i, j = cross_match(pixel_coords, radecs_xy).T
54-
M = get_transform_matrix(radecs[j], pixel_coords[i])
55-
radecs_xy = (M @ pad(radecs).T)[0:2].T
56-
i, j = cross_match(pixel_coords, radecs_xy).T
57-
return fit_wcs_from_points(pixel_coords[i].T, SkyCoord(radecs[j], unit="deg"))
54+
if M is None:
55+
return None
56+
else:
57+
radecs_xy = (M @ pad(radecs).T)[0:2].T
58+
i, j = cross_match(pixel_coords, radecs_xy).T
59+
M = get_transform_matrix(radecs[j], pixel_coords[i])
60+
radecs_xy = (M @ pad(radecs).T)[0:2].T
61+
i, j = cross_match(pixel_coords, radecs_xy).T
62+
return fit_wcs_from_points(pixel_coords[i].T, SkyCoord(radecs[j], unit="deg"))
5863

5964

6065
def gaia_radecs(

twirl/match.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def find_transform(
131131
if match >= min_match * len(pixels):
132132
break
133133

134-
i, j = pairs[np.argmax(matches)]
135-
M = get_transform_matrix(asterism_radecs[j], asterism_pixels[i])
136-
137-
return M
134+
if len(matches) == 0:
135+
return None
136+
else:
137+
i, j = pairs[np.argmax(matches)]
138+
M = get_transform_matrix(asterism_radecs[j], asterism_pixels[i])
139+
return M

0 commit comments

Comments
 (0)