Skip to content

Commit

Permalink
Add tests for sun angle calc
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisherlevine committed Feb 21, 2025
1 parent 8de8efb commit 5ff4e1b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions python/lsst/summit/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,15 +1350,18 @@ def calcEclipticCoords(ra: float, dec: float) -> tuple[float, float]:
return (np.rad2deg(lambda_), np.rad2deg(beta))


def getSunAngle() -> float:
"""Get the angle of the sun to the horizon. Positive numbers means the
sun is above the horizon, negative means it is below.
def getSunAngle(time: Time | None = None) -> float:
"""Get the angle of the sun to the horizon at the specified time.
If no time is specified, the current time is used. Positive numbers means
the sun is above the horizon, negative means it is below.
Returns
-------
sun_alt : `float`
The angle of the sun to the horizon, in degrees.
"""
now = Time.now()
sun_altaz = get_sun(now).transform_to(AltAz(obstime=now, location=SIMONYI_LOCATION))
if time is None:
time = Time.now()
sun_altaz = get_sun(time).transform_to(AltAz(obstime=time, location=SIMONYI_LOCATION))
return sun_altaz.alt.deg
15 changes: 15 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import numpy as np
from astro_metadata_translator import makeObservationInfo
from astropy.coordinates import HeliocentricEclipticIAU76, SkyCoord
from astropy.time import Time

import lsst.afw.detection as afwDetect
import lsst.afw.geom as afwGeom
Expand All @@ -56,6 +57,7 @@
getExpPositionOffset,
getFieldNameAndTileNumber,
getQuantiles,
getSunAngle,
quickSmooth,
)

Expand Down Expand Up @@ -244,6 +246,19 @@ def test_getCurrentDayObs_humanStr(self):
self.assertEqual(len(dateStr), 10)
self.assertRegex(dateStr, r"\d{4}-\d{2}-\d{2}")

def test_getSunAngle(self):
"""Just a basic sanity check on the range."""
testTime = Time("2021-09-15T16:00:00", format="isot", scale="utc")
sunAngle = getSunAngle(testTime)
self.assertIsInstance(sunAngle, float)
self.assertLess(sunAngle, 90.01)
self.assertGreater(sunAngle, -90.01)

sunAngle = getSunAngle()
self.assertIsInstance(sunAngle, float)
self.assertLess(sunAngle, 90.01)
self.assertGreater(sunAngle, -90.01)


class QuantileTestCase(lsst.utils.tests.TestCase):
def setUp(self) -> None:
Expand Down

0 comments on commit 5ff4e1b

Please sign in to comment.