Skip to content

Commit

Permalink
Merge pull request #2867 from astrofrog/small-delta-compass
Browse files Browse the repository at this point in the history
Use small angular offsets when determining compass properties
  • Loading branch information
pllim committed May 10, 2024
2 parents f985a7f + afef68a commit 37eba85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 9 additions & 9 deletions jdaviz/configs/imviz/tests/test_wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def test_simple_fits_wcs():
w = WCS()
result = wcs_utils.get_compass_info(w, (100, 100), r_fac=0.25)
assert_allclose(result[:-1], (50, 50,
50, 73.57533083557558,
73.57809873817803, 47.53791379556649,
0, 95.96136875946559))
50, 73.573199,
73.573199, 47.538975,
0, 95.960048))
assert result[-1]

# https://learn.astropy.org/tutorials/celestial_coords1.html
Expand All @@ -44,9 +44,9 @@ def test_simple_fits_wcs():
'NAXIS2': 1024})
result = wcs_utils.get_compass_info(w, (1024, 1024), r_fac=0.25)
assert_allclose(result[:-1], (512.0, 512.0,
512.2415718047745, 767.9895741540789,
255.98982015749573, 512.240013842715,
0.054068767449065434, -90.00035302773995))
512.2416, 768.0007,
256.0009, 512.24,
0.05406877, -90.00035))
assert not result[-1]


Expand Down Expand Up @@ -103,9 +103,9 @@ def test_simple_gwcs():

result = wcs_utils.get_compass_info(w, (1024, 2048), r_fac=0.25)
assert_allclose(result[:-1], (1024.0, 512.0,
1131.0265005852038, 279.446189124443,
1262.0057201165127, 606.2863901330095,
155.2870478938214, -86.89813081941797))
1131.026544, 279.446094,
1262.004542, 606.285924,
155.287048, -86.898131))
assert not result[-1]


Expand Down
20 changes: 14 additions & 6 deletions jdaviz/configs/imviz/wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,26 @@ def calc_compass(image_wcs, x, y, len_deg_e, len_deg_n):


def calc_compass_radius(image_wcs, x, y, radius_px):
xe, ye = add_offset_xy(image_wcs, x, y, 1.0, 0.0)
xn, yn = add_offset_xy(image_wcs, x, y, 0.0, 1.0)

# Define an angular length we can use to determine the pixel scale
# along east and north - we want to make sure we use a small length so
# that the offset points still fall inside the image in case they have
# a bounding box set.

delta = 0.1 / 3600 # 0.1 arcsec

xe, ye = add_offset_xy(image_wcs, x, y, delta, 0.0)
xn, yn = add_offset_xy(image_wcs, x, y, 0.0, delta)

# now calculate the length in pixels of those arcs
# (planar geometry is good enough here)
px_per_deg_e = math.sqrt(math.fabs(ye - y) ** 2 + math.fabs(xe - x) ** 2)
px_per_deg_n = math.sqrt(math.fabs(yn - y) ** 2 + math.fabs(xn - x) ** 2)
px_per_delta_e = math.sqrt(math.fabs(ye - y) ** 2 + math.fabs(xe - x) ** 2)
px_per_delta_n = math.sqrt(math.fabs(yn - y) ** 2 + math.fabs(xn - x) ** 2)

# now calculate the arm length in degrees for each arm
# (this produces same-length arms)
len_deg_e = radius_px / px_per_deg_e
len_deg_n = radius_px / px_per_deg_n
len_deg_e = radius_px / px_per_delta_e * delta
len_deg_n = radius_px / px_per_delta_n * delta

return calc_compass(image_wcs, x, y, len_deg_e, len_deg_n)

Expand Down

0 comments on commit 37eba85

Please sign in to comment.