space::time
cheatah-space v0.1.0-alpha — Biome Standard 0.6.3-alpha
Concepts
DatetimeArray— An ndarray of datetime structs (see is_datetime_v) — lit up when that struct lands.DatetimeScalar— A single broken-down datetime value (see is_datetime_v).Numeric— A scalar that makes sense as a continuous time/epoch quantity — any arithmetic type.NumericArray— An ndarray with a numeric (arithmetic) entry — the vectorized continuous-time input.TimeInput— The full accepted domain: a sensible scalar, a numeric ndarray, or a datetime-struct ndarray.
Functions
Julian Date of the Unix epoch, 1970-01-01T00:00:00Z.
2440587.5.
O(1).
none.
systests/test_jd.purrimport io
import space.time as st
# The Unix epoch's Julian Date is the anchor of every unix<->jd conversion.
io.print(st.jd_unix_epoch()) # 2440587.5
io.print(st.unix_to_jd(0.0) == st.jd_unix_epoch()) # trueJulian Date of the J2000.0 epoch, 2000-01-01T12:00:00 TT.
2451545.0.
O(1).
none.
systests/test_jd.purrimport io
import space.time as st
# J2000.0 — the reference epoch of modern astronomical series.
io.print(st.jd_j2000()) # 2451545.0
io.print(st.jd_to_j2000_seconds(st.jd_j2000())) # 0.0 — J2000 is its own originCDF_EPOCH of the Unix epoch: milliseconds from 0000-01-01T00:00:00.000 to 1970-01-01 — the constant that bridges Unix time and NASA CDF's millisecond epoch.
62167219200000.0.
O(1).
none.
systests/test_cdf_epoch.purrimport io
import space.time as st
# The Unix epoch expressed as a CDF_EPOCH (ms since year 0).
io.print(st.cdf_epoch_unix_offset_ms()) # 62167219200000.0
io.print(st.unix_to_cdf_epoch(0.0) == st.cdf_epoch_unix_offset_ms()) # trueUnix epoch seconds → Julian Date.
seconds | scalar or numeric ndarray of seconds since 1970-01-01T00:00:00Z. |
the corresponding Julian Date(s).
O(n).
one result array for an ndarray; none for a scalar.
systests/test_jd.purr systests/test_vectorized.purrimport io
import ndarray
import space.time as st
io.print(st.unix_to_jd(946728000.0)) # 2451545.0 — J2000, exactly
let jds = st.unix_to_jd(ndarray.array([0.0, 86400.0])) # a whole array, vectorized
io.print(jds[0], jds[1]) # 2440587.5 2440588.5Julian Date → Unix epoch seconds.
jd | scalar or numeric ndarray of Julian Dates. |
seconds since 1970-01-01T00:00:00Z.
O(n).
one result array for an ndarray; none for a scalar.
systests/test_jd.purr systests/test_vectorized.purrimport io
import space.time as st
io.print(st.jd_to_unix(2451545.0)) # 946728000.0 — J2000 in Unix seconds
io.print(st.jd_to_unix(st.unix_to_jd(86400.0))) # 86400.0 — the round tripJulian Date → Modified Julian Date (MJD = JD − 2400000.5).
jd | scalar or numeric ndarray of Julian Dates. |
the Modified Julian Date(s).
O(n).
one result array for an ndarray; none for a scalar.
systests/test_mjd.purrimport io
import space.time as st
io.print(st.jd_to_mjd(st.jd_j2000())) # 51544.5 — J2000 as an MJDModified Julian Date → Julian Date.
mjd | scalar or numeric ndarray of Modified Julian Dates. |
the Julian Date(s).
O(n).
one result array for an ndarray; none for a scalar.
systests/test_mjd.purrimport io
import space.time as st
io.print(st.mjd_to_jd(51544.5)) # 2451545.0 — back to a full JDUnix epoch seconds → Modified Julian Date.
seconds | scalar or numeric ndarray of seconds since the Unix epoch. |
the Modified Julian Date(s).
O(n).
one result array for an ndarray; none for a scalar.
systests/test_mjd.purr systests/test_vectorized.purrimport io
import space.time as st
io.print(st.unix_to_mjd(0.0)) # 40587.0 — the Unix epoch's MJDModified Julian Date → Unix epoch seconds.
mjd | scalar or numeric ndarray of Modified Julian Dates. |
seconds since the Unix epoch.
O(n).
one result array for an ndarray; none for a scalar.
systests/test_mjd.purrimport io
import space.time as st
io.print(st.mjd_to_unix(40587.0)) # 0.0 — the Unix epoch againSeconds elapsed since the J2000.0 epoch for a given Julian Date.
jd | scalar or numeric ndarray of Julian Dates. |
seconds since 2000-01-01T12:00:00.
O(n).
one result array for an ndarray; none for a scalar.
systests/test_j2000.purrimport io
import space.time as st
io.print(st.jd_to_j2000_seconds(2451546.0)) # 86400.0 — one day after J2000Julian centuries (36525 days) elapsed since J2000.0 — the time argument for most astronomical polynomial series (mean sidereal time, precession, …).
jd | scalar or numeric ndarray of Julian Dates. |
Julian centuries since J2000.0.
O(n).
one result array for an ndarray; none for a scalar.
systests/test_j2000.purrimport io
import space.time as st
# The `T` fed to precession / sidereal-time polynomial series.
io.print(st.jd_to_j2000_centuries(2451545.0 + 36525.0)) # 1.0 — one Julian centuryUnix epoch seconds → NASA CDF_EPOCH (milliseconds since year 0).
Feeds space.cdf epoch variables directly. CDF_TT2000 (ns since J2000 with leap seconds) needs a leap-second table and lands with space.cdf — see the cdf roadmap.
seconds | scalar or numeric ndarray of seconds since the Unix epoch. |
the CDF_EPOCH value(s) in milliseconds.
O(n).
one result array for an ndarray; none for a scalar.
systests/test_cdf_epoch.purr systests/test_vectorized.purrimport io
import space.time as st
# J2000 as a CDF_EPOCH — ready to write into a CDF epoch variable.
io.print(st.unix_to_cdf_epoch(946728000.0)) # 63113947200000.0NASA CDF_EPOCH (milliseconds since year 0) → Unix epoch seconds.
ms | scalar or numeric ndarray of CDF_EPOCH values in milliseconds. |
seconds since the Unix epoch.
O(n).
one result array for an ndarray; none for a scalar.
systests/test_cdf_epoch.purrimport io
import space.time as st
# An epoch read from a CDF file, back onto the Unix scale.
io.print(st.cdf_epoch_to_unix(63113947200000.0)) # 946728000.0 — J2000Constants & variables
Trait hook for cheatah's forthcoming datetime struct.
It defaults to false; when cheatah::datetime defines its broken-down datetime type, this is specialized to true for it (here or there), which lights up DatetimeScalar / DatetimeArray and the datetime overloads — without this header taking a dependency on that type today.
