Time (pyobs.utils.time)
TODO: write doc
Time is a thin subclass of astropy.time.Time used throughout pyobs
instead of the astropy original. It adds two things: hashability (so Time objects can be used in sets
and as dict keys) and a testable clock via now().
Always use pyobs.utils.time.Time rather than astropy.time.Time in pyobs code — it is a drop-in
replacement and accepts all the same constructor arguments:
from pyobs.utils.time import Time
now = Time.now()
t = Time("2024-06-01T22:00:00")
t = Time(some_datetime_object, format="datetime", scale="utc")
Simulated time
In simulation or testing scenarios, set_offset_to_now() shifts what
Time.now() returns without affecting the system clock:
from astropy.time import TimeDelta
import astropy.units as u
# make Time.now() return a time 2 hours in the past
Time.set_offset_to_now(TimeDelta(-2 * u.hour))
This is useful in simulation or testing scenarios that need to run at an arbitrary point in time.
API reference
- class Time(val, val2=None, format=None, scale=None, precision=None, in_subfmt=None, out_subfmt=None, location=None, copy=False)[source]
Bases:
TimeHashable Time class.
- night_obs(observer: Observer) date[source]
Returns the night for this time, i.e. the date of the start of the current night.
The boundary is local civil noon in the observer’s timezone. All times from noon until the next noon use the local date of the sunset after that opening noon, keeping evening exposures and morning calibrations on the same night. If no sunset is found (e.g. polar day/night), use the query’s local calendar date instead; that fallback can change at midnight.
- Parameters:
observer – Observer object to use.
- Returns:
Night for this time.
- classmethod now() Time[source]
Creates a new object corresponding to the instant in time this method is called.
Note
“Now” is determined using the ~datetime.datetime.utcnow function, so its accuracy and precision is determined by that function. Generally that means it is set by the accuracy of your system clock.
- Returns:
A new Time object (or a subclass of Time if this is called from such a subclass) at the current time.