Skip to content

Commit

Permalink
Add function for getting ecliptic coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisherlevine committed Nov 1, 2024
1 parent 83e1902 commit 9681d66
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions python/lsst/summit/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,54 @@ def getCameraFromInstrumentName(instrumentName: str) -> lsst.afw.cameraGeom.Came
case _:
raise ValueError(f"Unsupported instrument: {instrumentName}")
return camera


def calcEclipticCoords(ra: float, dec: float) -> tuple[float, float]:
"""Get the ecliptic coordinates of the specified ra and dec.
Transform J2000 (ra, dec), both in degrees, to
IAU1976 Ecliptic coordinates (also returning degrees).
Matches the results of:
from astropy.coordinates import SkyCoord, HeliocentricEclipticIAU76
import astropy.units as u
p = SkyCoord(ra=ra0*u.deg, dec=dec0*u.deg, distance=1*u.au, frame='hcrs')
ecl = p.transform_to(HeliocentricEclipticIAU76)
print(ecl.lon.value, ecl.lat.value)
except that it's fast.
Parameters
----------
ra : `float`
The right ascension, in degrees.
dec : `float`
The declination, in degrees.
Returns
-------
lambda : `float`
The ecliptic longitude in degrees.
beta : `float`
The ecliptic latitude in degrees.
"""

ra, dec = np.deg2rad(ra), np.deg2rad(dec)

# IAU 1976 obliquity
epsilon = np.deg2rad(23.43929111111111)
cos_eps, sin_eps = np.cos(epsilon), np.sin(epsilon)

sra, cra = np.sin(ra), np.cos(ra)
sdec, cdec = np.sin(dec), np.cos(dec)

lambda_ = np.arctan2((sra * cos_eps + sdec / cdec * sin_eps), cra)
beta = np.arcsin(sdec * cos_eps - cdec * sin_eps * sra)

# normalize
if lambda_ < 0:
lambda_ += np.twopi

return (np.rad2deg(lambda_), np.rad2deg(beta))

0 comments on commit 9681d66

Please sign in to comment.