3
3
from datalab .datalab_session .file_utils import get_hdu , scale_points
4
4
from datalab .datalab_session .s3_utils import get_fits
5
5
6
+ # Source catalog Function Definition
7
+ # ARGS: input (dict)
8
+ # input = {
9
+ # basename (str): The name of the file to analyze
10
+ # height (int): The height of the image
11
+ # width (int): The width of the image
12
+ # source (str): The source of the file
13
+ # }
14
+ # RETURNS: output (dict)
15
+ # output = [{
16
+ # x (int): The x coordinate of the source
17
+ # y (int): The y coordinate of the source
18
+ # flux (int): The flux value of the source
19
+ # ra (float): The right ascension of the source
20
+ # dec (float): The declination of the source
21
+ # }]
22
+ #
6
23
def source_catalog (input : dict ):
7
24
"""
8
25
Returns a dict representing the source catalog data with x,y coordinates and flux values
9
26
"""
10
- fits_path = get_fits (input ['basename' ])
27
+ fits_path = get_fits (input ['basename' ], input [ 'source' ] )
11
28
12
29
cat_hdu = get_hdu (fits_path , 'CAT' )
13
30
sci_hdu = get_hdu (fits_path , 'SCI' )
@@ -19,23 +36,30 @@ def source_catalog(input: dict):
19
36
x_points = cat_hdu .data ["x" ][:SOURCE_CATALOG_COUNT ]
20
37
y_points = cat_hdu .data ["y" ][:SOURCE_CATALOG_COUNT ]
21
38
flux = cat_hdu .data ["flux" ][:SOURCE_CATALOG_COUNT ]
22
- ra = cat_hdu .data ["ra" ][:SOURCE_CATALOG_COUNT ]
23
- dec = cat_hdu .data ["dec" ][:SOURCE_CATALOG_COUNT ]
39
+
40
+ # ra, dec values may or may not be present in the CAT hdu
41
+ if "ra" in cat_hdu .data .names and "dec" in cat_hdu .data .names :
42
+ ra = cat_hdu .data ["ra" ][:SOURCE_CATALOG_COUNT ]
43
+ dec = cat_hdu .data ["dec" ][:SOURCE_CATALOG_COUNT ]
44
+ else :
45
+ # TODO: implement a fallback way to calculate ra, dec from x, y and WCS
46
+ ra = np .zeros (SOURCE_CATALOG_COUNT )
47
+ dec = np .zeros (SOURCE_CATALOG_COUNT )
24
48
25
49
# scale the x_points and y_points from the fits pixel coords to the jpg coords
26
50
fits_height , fits_width = np .shape (sci_hdu .data )
27
51
x_points , y_points = scale_points (fits_height , fits_width , input ['width' ], input ['height' ], x_points = x_points , y_points = y_points )
28
52
29
- # we will be giving a list of dicts representing each source back to the frontend
53
+ # create the list of source catalog objects
30
54
source_catalog_data = []
31
55
for i in range (SOURCE_CATALOG_COUNT ):
32
56
source_catalog_data .append ({
33
57
"x" : x_points [i ],
34
58
"y" : y_points [i ],
35
59
"flux" : flux [i ].astype (int ),
36
- # truncate the ra and dec to 4 decimal places for readability
37
- "ra" : '%.4f ' % (ra [i ]),
38
- "dec" : '%.4f ' % (dec [i ])
60
+ # Astronomical coordinates are formatted to 6 decimal places
61
+ "ra" : '%.6f ' % (ra [i ]),
62
+ "dec" : '%.6f ' % (dec [i ])
39
63
})
40
64
41
65
return source_catalog_data
0 commit comments