1
1
from skimage .measure import profile_line
2
2
from astropy .wcs import WCS
3
3
from astropy .wcs import WcsError
4
+ from astropy import coordinates
4
5
5
6
from datalab .datalab_session .file_utils import scale_points , get_hdu
6
7
@@ -19,15 +20,15 @@ def line_profile(input: dict):
19
20
}
20
21
"""
21
22
sci_hdu = get_hdu (input ['basename' ], 'SCI' )
22
-
23
+
23
24
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
+
25
26
# Line profile and distance in arcseconds
26
27
line_profile = profile_line (sci_hdu .data , (x_points [0 ], y_points [0 ]), (x_points [1 ], y_points [1 ]), mode = "constant" , cval = - 1 )
27
-
28
28
29
- # Calculations for coordinates and angular distance
30
- try :
29
+
30
+ # Calculates for coordinates, angular distance, and position angle
31
+ try :
31
32
wcs = WCS (sci_hdu .header )
32
33
33
34
if (wcs .get_axis_types ()[0 ].get ('coordinate_type' ) == None ):
@@ -36,14 +37,21 @@ def line_profile(input: dict):
36
37
start_sky_coord = wcs .pixel_to_world (x_points [0 ], y_points [0 ])
37
38
end_sky_coord = wcs .pixel_to_world (x_points [1 ], y_points [1 ])
38
39
40
+ # Angular distance
39
41
arcsec_angle = start_sky_coord .separation (end_sky_coord ).arcsecond
40
42
43
+ # Coordinates
41
44
start_coords = [start_sky_coord .ra .deg , start_sky_coord .dec .deg ]
42
45
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
43
50
except WcsError :
44
51
# no valid WCS solution
45
52
start_coords = None
46
53
end_coords = None
54
+ position_angle = None
47
55
48
56
try :
49
57
# attempt using pixscale to calculate the angle
@@ -52,4 +60,4 @@ def line_profile(input: dict):
52
60
# no valid WCS solution, and no pixscale
53
61
arcsec_angle = None
54
62
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