julian date

Functions have been provided that convert universal time to Julian Date. The code internally utilizes the jdcal package to provide the conversion and provides several functions that wrap the call. Most users should be content calling ut_to_jd which is able to convert scalars, sequences or np.ndarrays of strings, datetime, datetime64, or floats to julian date. Each julian date is returned as two parts, the julian day and the fraction of julian day. For example:

import numpy as np
from datetime import datetime
from arg_common.juliandate import ut_to_jd

tstr        = '2019-01-11 15:32:45.123456'
tdatetime   = datetime.fromisoformat( tstr)
tdatetime64 = np.datetime64(tstr,dtype='datetime64[ms]')

jda1,jda2 = ut_to_jd( tstr )            # Test scalar UTC string to julian date
jdb1,jdb2 = ut_to_jd( tdatetime )       # Test scalar datetime to julian date
jdc1,jdc2 = ut_to_jd( tdatetime64 )     # Test scalar numpy.datetime64 to julian date

print( 'jd from str        = ', jda1,' + ',jda2 )
print( 'jd from datetime   = ', jdb1,' + ',jdb2 )
print( 'jd from datetime64 = ', jdc1,' + ',jdc2 )

The ut_to_jd 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_jd

tstr      = ['2019-01-11 15:32:45.123456', 2019-01-12 16:32:45.123456', 2019-01-13 17:32:45.123456']
jda1,jda2 = ut_to_jd( tstr )                            # Test array UTC string to julian date

print( 'First jd   = ', jda1[0],' + ',jda2[0] )
print( 'Second jd  = ', jda1[1],' + ',jda2[1] )
print( 'Third jd   = ', jda1[2],' + ',jda2[2] )

ut_to_jd

arg_common.juliandate.ut_to_jd(ut: Union[numpy.ndarray, List[Any], Any])

A convenience function that converts various arrays or scalar representations of UT to julian date. Each Julian date is returned as two floating point components, jd1 and jd2. If the input is an array of value sthen jd1 and jd2 will be returned as floating point arrays with the same shape and size as the input array. If the inputs are scalar values then jd1 and jd2 will be returned as scalar floating point values.

Parameters:utc (scalar, list, tuple or array) –

The input time which represents a universal time (strictly UT1). It can be represented by (i) a string in a supported python datetime.isoformat (ii) a number which is assumed to represent a julian date if it is greater than 500,000 or a modified julian date if it less than 500,000, (iii) a datetime.datetime object representing UT (iv) a numpy.datetime64 object representing UT

The ut 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

datetime_to_jd

arg_common.juliandate.datetime_to_jd(t: datetime.datetime) → Tuple[float, float]

Converts a scalar datetime.datetime object to julian date which is returned as a two element floating point tuple. No attempt has been made to manage timezones inside the datetime object. We recommend that you don’t use objects with time-zones in this code.

Parameters:ut1 (datetime.datetime) – The universal time to be converted to julian date. The Universal time is assumed to follow the Gregorian calendar
Returns:Returns a two element floating point tuple. The first element contains the high order (julian days) part of the julian date. The second element contains the low order fraction of a day.
Return type:Tuple( float, float)

datetime64_to_jd

arg_common.juliandate.datetime64_to_jd(ut1: numpy.datetime64) → Tuple[float, float]

Converts a scalar numpy datetime64 object to julian date which is returned as a two element floating point tuple. No attempt has been made to manage timezones inside the datetime64 object. We recommend you don’t use objects with time-zones

Parameters:ut1 (numpy.datetime64) – The universal time (strictly UT1) to be converted to julian date.
Returns:Returns a two element floating point tuple. The first element contains the high order (julian days) part of the julian date. The second element contains the low order fraction of a day.
Return type:Tuple( float, float)

isoformat_to_jd

arg_common.juliandate.isoformat_to_jd(utc: str) → Tuple[float, float]

Converts a string representing a UT instant encoded in isoformat to a julian date which is returned as a two element floating point tuple. No attempt has been made to manage timezones inside the datetime object. We recommend that you don’t use objects with time-zones in this code.

Parameters:ut1 (str) – The universal time (strictly UT1) to be converted to julian date. The string is encoded is isoformat, eg ‘2009-11-15T15:36:49.000123’
Returns:Returns a two element floating point tuple. The first element contains the high order (julian days) part of the julian date. The second element contains the low order fraction of a day.
Return type:Tuple( float, float)

number_to_jd

arg_common.juliandate.number_to_jd(utc: float) → Tuple[float, float]

Converts a number to a julian date which is returned as a two element floating point tuple. Numbers less than 500,000 are assumed to represent modified julian date. Numbers greater than 500,000 are assumed to be julian dates. The calculation is useful for converting floating point values to the two element tuples used by the novas and sofa software.

Parameters:ut1 (float) – The universal time to be converted to julian date.
Returns:Returns a two element floating point tuple. The first element contains the high order (julian days) part of the julian date. The second element contains the low order fraction of a day.
Return type:Tuple( float, float)