Skip to content

Commit

Permalink
Use ._time.jd1 for slight speed increase in astropy_to_nsec
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Oct 2, 2024
1 parent 4b9e99a commit 6e9daf7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/lsst/daf/butler/time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def astropy_to_nsec(self, astropy_time: astropy.time.Time) -> int:
delta = value - self.epoch
# Special care needed to preserve nanosecond precision.
# Usually jd1 has no fractional part but just in case.
jd1, extra_jd2 = divmod(delta.jd1, 1)
value = int(jd1) * self._NSEC_PER_DAY + int(round((delta.jd2 + extra_jd2) * self._NSEC_PER_DAY))
# Can use "internal" ._time.jd1 interface because we know that both
# are TAI. This is a few percent faster than using .jd1.
jd1, extra_jd2 = divmod(delta._time.jd1, 1)
value = int(jd1) * self._NSEC_PER_DAY + int(round((delta._time.jd2 + extra_jd2) * self._NSEC_PER_DAY))
return value

def nsec_to_astropy(self, time_nsec: int) -> astropy.time.Time:
Expand Down

0 comments on commit 6e9daf7

Please sign in to comment.