Skip to content

Commit

Permalink
Add call to astropy coords to calculate position angle
Browse files Browse the repository at this point in the history
Thanks Curtis!
  • Loading branch information
mgdaily committed Sep 11, 2024
1 parent e5e3aa2 commit ae76c70
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions datalab/datalab_session/analysis/line_profile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from skimage.measure import profile_line
from astropy.wcs import WCS
from astropy.wcs import WcsError
from astropy import coordinates

from datalab.datalab_session.file_utils import scale_points, get_hdu

Expand All @@ -19,15 +20,15 @@ def line_profile(input: dict):
}
"""
sci_hdu = get_hdu(input['basename'], 'SCI')

x_points, y_points = scale_points(input["height"], input["width"], sci_hdu.data.shape[0], sci_hdu.data.shape[1], x_points=[input["x1"], input["x2"]], y_points=[input["y1"], input["y2"]])

# Line profile and distance in arcseconds
line_profile = profile_line(sci_hdu.data, (x_points[0], y_points[0]), (x_points[1], y_points[1]), mode="constant", cval=-1)


# Calculations for coordinates and angular distance
try:
try:
wcs = WCS(sci_hdu.header)

if(wcs.get_axis_types()[0].get('coordinate_type') == None):
Expand All @@ -40,6 +41,8 @@ def line_profile(input: dict):

start_coords = [start_sky_coord.ra.deg, start_sky_coord.dec.deg]
end_coords = [end_sky_coord.ra.deg, end_sky_coord.dec.deg]
position_angle = coordinates.position_angle(start_sky_coord.ra, start_sky_coord.dec,
end_sky_coord.ra, end_sky_coord.dec).deg
except WcsError:
# no valid WCS solution
start_coords = None
Expand All @@ -52,4 +55,4 @@ def line_profile(input: dict):
# no valid WCS solution, and no pixscale
arcsec_angle = None

return {"line_profile": line_profile, "arcsec": arcsec_angle, "start_coords": start_coords, "end_coords": end_coords}
return {"line_profile": line_profile, "arcsec": arcsec_angle, "start_coords": start_coords, "end_coords": end_coords, "position_angle": position_angle}

0 comments on commit ae76c70

Please sign in to comment.