Skip to content

Commit 1e66ff3

Browse files
authored
Merge pull request #31 from LCOGT/feature/position-angle
Add call to astropy coords to calculate position angle
2 parents e64d21a + 8ba0d99 commit 1e66ff3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

datalab/datalab_session/analysis/line_profile.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from skimage.measure import profile_line
22
from astropy.wcs import WCS
33
from astropy.wcs import WcsError
4+
from astropy import coordinates
45

56
from datalab.datalab_session.file_utils import scale_points, get_hdu
67

@@ -19,15 +20,15 @@ def line_profile(input: dict):
1920
}
2021
"""
2122
sci_hdu = get_hdu(input['basename'], 'SCI')
22-
23+
2324
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"]])
24-
25+
2526
# Line profile and distance in arcseconds
2627
line_profile = profile_line(sci_hdu.data, (x_points[0], y_points[0]), (x_points[1], y_points[1]), mode="constant", cval=-1)
27-
2828

29-
# Calculations for coordinates and angular distance
30-
try:
29+
30+
# Calculates for coordinates, angular distance, and position angle
31+
try:
3132
wcs = WCS(sci_hdu.header)
3233

3334
if(wcs.get_axis_types()[0].get('coordinate_type') == None):
@@ -36,14 +37,21 @@ def line_profile(input: dict):
3637
start_sky_coord = wcs.pixel_to_world(x_points[0], y_points[0])
3738
end_sky_coord = wcs.pixel_to_world(x_points[1], y_points[1])
3839

40+
# Angular distance
3941
arcsec_angle = start_sky_coord.separation(end_sky_coord).arcsecond
4042

43+
# Coordinates
4144
start_coords = [start_sky_coord.ra.deg, start_sky_coord.dec.deg]
4245
end_coords = [end_sky_coord.ra.deg, end_sky_coord.dec.deg]
46+
47+
# Position angle
48+
position_angle = coordinates.position_angle(start_sky_coord.ra, start_sky_coord.dec,
49+
end_sky_coord.ra, end_sky_coord.dec).deg
4350
except WcsError:
4451
# no valid WCS solution
4552
start_coords = None
4653
end_coords = None
54+
position_angle = None
4755

4856
try:
4957
# attempt using pixscale to calculate the angle
@@ -52,4 +60,4 @@ def line_profile(input: dict):
5260
# no valid WCS solution, and no pixscale
5361
arcsec_angle = None
5462

55-
return {"line_profile": line_profile, "arcsec": arcsec_angle, "start_coords": start_coords, "end_coords": end_coords}
63+
return {"line_profile": line_profile, "arcsec": arcsec_angle, "start_coords": start_coords, "end_coords": end_coords, "position_angle": position_angle}

0 commit comments

Comments
 (0)