Skip to content

Commit

Permalink
Merge pull request #18 from LCOGT/feature/wcs-line-analysis
Browse files Browse the repository at this point in the history
wcs solution for coords and length of line analysis, dev warning for auth token
  • Loading branch information
LTDakin authored Jun 26, 2024
2 parents b52d7df + 25bcd2b commit 338c887
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 27 additions & 3 deletions datalab/datalab_session/analysis/line_profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from skimage.measure import profile_line
from astropy.wcs import WCS
from astropy.wcs import WcsError

from datalab.datalab_session.util import scale_points
from datalab.datalab_session.util import get_hdu
Expand All @@ -9,9 +11,31 @@ def line_profile(input: dict):
Creates an array of luminosity values and the length of the line in arcseconds
"""
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 and distance in arcseconds
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"]


# Calculations for coordinates and angular distance
try:
wcs = WCS(sci_hdu.header)

start_sky_coord = wcs.pixel_to_world(x_points[0], y_points[0])
end_sky_coord = wcs.pixel_to_world(x_points[1], y_points[1])

arcsec_angle = start_sky_coord.separation(end_sky_coord).arcsecond

start_coords = [start_sky_coord.ra.deg, start_sky_coord.dec.deg]
end_coords = [end_sky_coord.ra.deg, end_sky_coord.dec.deg]

except WcsError as e:
error = f'{input["basename"]} does not have a valid WCS header'
print(error, e)
# if theres no valid WCS solution then we default to using pixscale to calculate the angle, and no coordinates
start_coords = None
end_coords = None
arcsec_angle = len(line_profile) * sci_hdu.header["PIXSCALE"]

return {"line_profile": line_profile, "arcsec": arcsec}
return {"line_profile": line_profile, "arcsec": arcsec_angle, "start_coords": start_coords, "end_coords": end_coords}
3 changes: 3 additions & 0 deletions datalab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def get_list_from_env(variable, default=None):
# Datalab Archive
ARCHIVE_API = os.getenv('ARCHIVE_API', 'https://archive-api.lco.global')
ARCHIVE_API_TOKEN = os.getenv('ARCHIVE_API_TOKEN')
if not ARCHIVE_API_TOKEN:
print("WARNING: ARCHIVE_API_TOKEN is missing from the environment.")
exit()

# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
Expand Down

0 comments on commit 338c887

Please sign in to comment.