mjd¶
This is a description of the arg_common.mjd module. It provides several utility functions to convert to and from modified julian date. The example below demonstrates how to convert standard python representations of UTC into mjd:
import numpy as np
from datetime import datetime
from arg_common.mjd import ut_to_mjd
tstr = '2019-01-11 15:32:45.123456'
tdatetime = datetime.fromisoformat( tstr)
tdatetime64 = np.datetime64(tstr,dtype='datetime64[ms]')
mjda = ut_to_mjd( tstr ) # Test scalar UTC string to julian date
mjdb = ut_to_mjd( tdatetime ) # Test scalar datetime to julian date
mjdc = ut_to_mjd( tdatetime64 ) # Test scalar numpy.datetime64 to julian date
print( 'mjd from str = ', jda)
print( 'mjd from datetime = ', jdb)
print( 'mjd from datetime64 = ', jdc)
The ut_to_mjd function also supports arrays or lists of time objects/strings and generates arrays of jd1 and jd2. For example, using strings:
import numpy as np
from datetime import datetime
from arg_common.juliandate import ut_to_mjd
tstr = ['2019-01-11 15:32:45.123456', 2019-01-12 16:32:45.123456', 2019-01-13 17:32:45.123456']
mjd = ut_to_mjd( tstr ) # Test array UTC string to modified julian date
print( 'First mjd = ', mjd[0])
print( 'Second mjd = ', mjd[1])
print( 'Third mjd = ', mjd[2])
ut_to_mjd¶
-
arg_common.mjd.
ut_to_mjd
(utc)¶ A convenience function that converts various arrays or scalar representations of UT to modified julian date. Scalar input values will return as a scalar float modified julian date while array, list or tuple input values are all returned as numpy arrays of mjd in float64.
Parameters: utc (scalar, list, tuple or array) – The input time which represents a coordinated universal time. It can be represented by (i) a string in a supported python datetime.isoformat (ii) a number. The number is assumed to represent a modified julian date. (iii) a datetime.datetime object. (iv) a numpy.datetime64 object. The utc object can be a scalar, list, tuple or numpy array. The same representation format must be used for all objects in the arrays and sequences. Returns: The mjd is returned as a scalar if the input was a scalar or as a numpy array for input sequences and arrays Return type: scalar or numpy.ndarray of float
mjd_to_ut¶
-
arg_common.mjd.
mjd_to_ut
(mjd)¶ A convenience function that converts scalars or arrays of floating point modified julian dates to universal time representations. The universal time is always returned as a scalar or array of numpy.datetime64 object(s).
Parameters: mjd (scalar, array, or sequence of float) – The input can be a scalar, numpy array or regular python list/tuple of floats storing MJD values. Returns: Returns either a scalar or array of numpy.datetime64 that matches the input object Return type: numpy.datetime64 or numpy.ndarray< numpy.datetime64 >
mjd_to_datetime¶
-
arg_common.mjd.
mjd_to_datetime
(mjd: float) → datetime.datetime¶ Converts a modified julian date to a datetime.datetime object. This function only works on scalar values of mjd. Time zones are not set.
Parameters: mjd (float) – The modified julian date. Returns: The datetime.datetime corresponding to the modified julian date. No time zone is set Return type: datetime.datetime
mjd_to_datetime64¶
-
arg_common.mjd.
mjd_to_datetime64
(mjd: float) → numpy.datetime64¶ Converts an modified julian date to a numpy.datetime64. This function only works on scalar values of mjd.
Parameters: mjd (float) – The modified julian date. Returns: The numpy.datetime64 corresponding to the modified julian date Return type: numpy.datetime64
datetime64_to_datetime¶
-
arg_common.mjd.
datetime64_to_datetime
(usertime: numpy.datetime64) → datetime.datetime¶ Converts a numpy.datetime64 to a datetime.datetime
Parameters: usertime (numpy.datetime64) – A time specified with a numpy datetime64 object. Explicit time zones are not currently supported. Only single scalar values are supported in this function. Returns: The time expressed as a regular python datetime.datetime. Return type: datetime.datetime