MJD calculation

I was attempting to find a simple way to calculate Modified Julian Day (MJD) from local observing time without having to re-invent the wheel. Someone MUST have done this before. Enter Astropy to save the day. Below is 4 lines of code that’ll do the conversion for you (note I’m using the Ureka installation of python). This was taken from this post on github.

$> python
Python 2.7.5 (default, Oct 20 2014, 18:43:08)
>>>
>>> from astropy.time import Time
#Make an array with various times you want to convert, format YYYY-MM-DDTHH:MM:SS.SS
#Note the ‘T’ in between the calendar day and the time on the clock
>>> times = [‘1999-01-01T00:00:00.123456789’, ‘2010-01-01T00:00:00′]
>>> t = Time(times, format=’isot’, scale=’utc’)
#Now we can print out some answers really simply
>>> t.mjd
array([ 51179.00000143, 55197. ])

and done!

Posted in Research and tagged as , , ,

Comments are closed.