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 sktimeutils.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 sktimeutils.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] )

datetime_to_jd#

datetime_to_jd(t: datetime) Tuple[float, float][source]#

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:
ut1datetime.datetime

The universal time to be converted to julian date. The Universal time is assumed to follow the Gregorian calendar

Returns:
Tuple( float, float)

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.

datetime64_to_jd#

datetime64_to_jd(ut1: datetime64) Tuple[float, float][source]#

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:
ut1numpy.datetime64

The universal time (strictly UT1) to be converted to julian date.

Returns:
Tuple( float, float)

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.

isoformat_to_jd#

isoformat_to_jd(utc: str) Tuple[float, float][source]#

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:
ut1str

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:
Tuple( float, float)

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.

number_to_jd#

number_to_jd(utc: float) Tuple[float, float][source]#

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:
ut1float

The universal time to be converted to julian date.

Returns:
Tuple( float, float)

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.