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

Limit source catalog to 1000 brightest sources, avoid magic numbers #50

Merged
merged 1 commit into from
Jan 23, 2025
Merged
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
19 changes: 11 additions & 8 deletions datalab/datalab_session/analysis/source_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ def source_catalog(input: dict):
cat_hdu = get_hdu(fits_path, 'CAT')
sci_hdu = get_hdu(fits_path, 'SCI')

DECIMALS_OF_PRECISION = 6
MAX_SOURCE_CATALOG_SIZE = min(len(cat_hdu.data["x"]), 1000)

# get x,y and flux values
x_points = cat_hdu.data["x"]
y_points = cat_hdu.data["y"]
flux = cat_hdu.data["flux"]
x_points = cat_hdu.data["x"][:MAX_SOURCE_CATALOG_SIZE]
y_points = cat_hdu.data["y"][:MAX_SOURCE_CATALOG_SIZE]
flux = cat_hdu.data["flux"][:MAX_SOURCE_CATALOG_SIZE]

# ra, dec values may or may not be present in the CAT hdu
if "ra" in cat_hdu.data.names and "dec" in cat_hdu.data.names:
ra = cat_hdu.data["ra"]
dec = cat_hdu.data["dec"]
ra = cat_hdu.data["ra"][:MAX_SOURCE_CATALOG_SIZE]
dec = cat_hdu.data["dec"][:MAX_SOURCE_CATALOG_SIZE]
else:
# TODO: implement a fallback way to calculate ra, dec from x, y and WCS
ra = None
Expand All @@ -49,15 +52,15 @@ def source_catalog(input: dict):

# create the list of source catalog objects
source_catalog_data = []
for i in range(len(cat_hdu.data)):
for i in range(MAX_SOURCE_CATALOG_SIZE):
source_data = {
"x": x_points[i],
"y": y_points[i],
"flux": flux[i].astype(int)
}
if ra is not None and dec is not None:
source_data["ra"] = '%.6f' % (ra[i])
source_data["dec"] = '%.6f' % (dec[i])
source_data["ra"] = f'%.{DECIMALS_OF_PRECISION}f' % (ra[i])
source_data["dec"] = f'%.{DECIMALS_OF_PRECISION}f' % (dec[i])

source_catalog_data.append(source_data)

Expand Down
Loading