Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use small angular offsets when determining compass properties #2867

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ejeschke , this function was actually from ginga:

https://github.com/ejeschke/ginga/blob/7e61d9772ec1e57c332f1e2c0280d308972640c4/ginga/util/wcs.py#L762-L764

Are you interested to have a similar patch over at ginga?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a good change, so sure!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK please see ejeschke/ginga#1102 . Thanks!

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