-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from LCOGT/feature/source-catalog-data
source-catalog analysis function, improved scale points util
- Loading branch information
Showing
6 changed files
with
86 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,7 @@ cython_debug/ | |
|
||
# vscode | ||
.vscode | ||
|
||
# temp files | ||
tmp/ | ||
tmp/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
from skimage.measure import profile_line | ||
|
||
from datalab.datalab_session.util import scale_flip_points | ||
from datalab.datalab_session.util import scale_points | ||
from datalab.datalab_session.util import get_hdu | ||
|
||
# For creating an array of brightness along a user drawn line | ||
def line_profile(input: dict, sci_hdu: object): | ||
def line_profile(input: dict): | ||
""" | ||
Creates an array of luminosity values and the length of the line in arcseconds | ||
""" | ||
points = scale_flip_points(input['width'], input['height'], sci_hdu.data, [(input["x1"], input["y1"]), (input["x2"], input["y2"])]) | ||
line_profile = profile_line(sci_hdu.data, points[0], points[1], mode="constant", cval=-1) | ||
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 = profile_line(sci_hdu.data, (x_points[0], y_points[0]), (x_points[1], y_points[1]), mode="constant", cval=-1) | ||
arcsec = len(line_profile) * sci_hdu.header["PIXSCALE"] | ||
|
||
return {"line_profile": line_profile, "arcsec": arcsec} | ||
|
||
def debug_point_on_sci_data(x, y, sci_hdu: object): | ||
""" | ||
Debugging function to check a point (x,y) on the sci data has the same value as the point cross checked in DS9 | ||
""" | ||
print(f"data: {sci_hdu.data[y, x]}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import numpy as np | ||
|
||
from datalab.datalab_session.util import get_hdu, scale_points | ||
|
||
|
||
def source_catalog(input: dict): | ||
""" | ||
Returns a dict representing the source catalog data with x,y coordinates and flux values | ||
""" | ||
cat_hdu = get_hdu(input['basename'], 'CAT') | ||
sci_hdu = get_hdu(input['basename'], 'SCI') | ||
|
||
# The number of sources to send back to the frontend, default 50 | ||
SOURCE_CATALOG_COUNT = min(50, len(cat_hdu.data["x"])) | ||
|
||
# get x,y and flux values for the first SOURCE_CATALOG_COUNT sources | ||
x_points = cat_hdu.data["x"][:SOURCE_CATALOG_COUNT] | ||
y_points = cat_hdu.data["y"][:SOURCE_CATALOG_COUNT] | ||
flux = cat_hdu.data["flux"][:SOURCE_CATALOG_COUNT] | ||
ra = cat_hdu.data["ra"][:SOURCE_CATALOG_COUNT] | ||
dec = cat_hdu.data["dec"][:SOURCE_CATALOG_COUNT] | ||
|
||
# scale the x_points and y_points from the fits pixel coords to the jpg coords | ||
fits_height, fits_width = np.shape(sci_hdu.data) | ||
x_points, y_points = scale_points(fits_height, fits_width, input['width'], input['height'], x_points=x_points, y_points=y_points) | ||
|
||
# we will be giving a list of dicts representing each source back to the frontend | ||
source_catalog_data = [] | ||
for i in range(SOURCE_CATALOG_COUNT): | ||
source_catalog_data.append({ | ||
"x": x_points[i], | ||
"y": y_points[i], | ||
"flux": flux[i].astype(int), | ||
# truncate the ra and dec to 4 decimal places for readability | ||
"ra": '%.4f'%(ra[i]), | ||
"dec": '%.4f'%(dec[i]) | ||
}) | ||
|
||
return source_catalog_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters