Barycentric Julian Dates in Python

(I wrote some code to calculate BJDs in Python. Skip the next few paragraphs if you don’t want any context.)

I’ve been working on a problem that involves (somewhat) precise timing of astronomical events over the span of a year or two. Doing this right can be tricky since we generally learn about events by the light they give off, and this light can take varying amounts of time to reach the Earth from its origin; most notably, our motion around the sun changes the distance between us and sources by enough to affect the apparent time of an event by several minutes.

Of course, astronomers have known about this issue for a while, which is why we have Barycentric Julian Dates (BJDs). Times in astronomy are usually reported as some kind of “Julian date,” which is just a large number counting days since some reference value. (This is a much subtler task than you might think.) When we report a BJD, the apparent time of an event has been adjusted to be what it would be as if it we were observing at the barycenter of the Solar System, which is the coordinate origin of all modern, precise astronomical positional calculations. If the source of the events is stationary with respect to the barycenter, this gives us a steady clock with which to measure when each event happened.

To time precisely, then, we need to be able to compute the BJD of an event from its apparent time as measured at some telescope. Pulsar astronomers need to do these calculations to nanosecond precision, so there must be some ridiculously detailed code out there somewhere, but Google doesn’t bring up many options. Jason Eastman and collaborators at Ohio State University have a great resource with documentation, online calculators, and code. Their core seems to be based on a routine called BARYCEN by Eckart Göhler. Both reference documentation and some helper code from Craig Markwardt.

Unfortunately, all of this code is written in IDL. Let us never forget that 1) IDL is not free and 2) it is a lame, bad, unpleasant language. I generally do things in Python instead. I haven’t been able to find any Python libraries for BJD computations, so I added support to my library for precision astronomy in Python.

Now, both the library and the BJD support are halfassed. The library builds off of two well-vetted libraries, IAU SOFA and USNO NOVAS, but itself is not well-tested and only exposes a few routines I’ve needed — none of which has, in fact, required precision beyond the most basic levels. The BJD support, meanwhile, only corrects for the Earth’s orbit, and so is accurate to only 0.1 second or so: that is, a hundred million times worse than what pulsar astronomers need.

But it’s good enough for me! And if you want to compute BJDs in Python, hopefully you can build off of precastro rather than starting from scratch. It should be capable of extremely precise calculations even if there may be some wrinkles to work out, and as always I’ve tried to make the API as nice as possible.

### Further References🔗

These are basically copied from the resources linked above; I haven’t read them myself. Standing on the shoulders of giants and all that.