# astrotool.date_time module¶

Date and time functions for AstroTool.

astrotool.date_time.date_time2jd(year, month, day, hour, minute, second)[source]

Compute the Julian Day for a given year, month, day, hour, minute and second.

Notes

• Date and time are expressed in UT.

Parameters
• year (int) – Year CE (UT). Note that year=0 = 1 BCE.

• month (int) – Month number of year (UT; 1-12).

• day (int) – Day of month with fraction (UT; 1.0-31.999).

• hour (int) – Hour of time of day (UT).

• minute (int) – Minute of hour of time (UT).

• second (double) – Second of minute of time (UT).

Returns

jd: Julian day (days).

Return type

double

Note

• uses julian_day().

astrotool.date_time.deltat(jd)[source]

Return the value of DeltaT through interpolation.

For the date range -700 - now, the value for Delta T is obtained by interpolation of known historical

values. Outside this range, a lenghtening of the day of 1.8 ms/century is assumed, as well as that the minimum of the parabola is DeltaT=12s in 1820.

Parameters

jd (double) – Julian day (days).

Returns

Delta T (s).

Return type

double

References

astrotool.date_time.deltat_1820(jd)[source]

Return a rough estimate for the value of Delta T.

A lenghtening of the day of 1.8 ms/century is assumed, as well as and that the minimum of the parabola is DeltaT=12s in 1820.

Parameters

jd (double) – Julian day (days).

Returns

Delta T (s).

Return type

double

References

astrotool.date_time.doy_from_datetime(date_time)[source]

Compute the day of year for a given datetime.

Parameters

date_time (datetime) – Date and time.

Returns

Day of year.

Return type

(int)

astrotool.date_time.doy_from_ymd(year, month, day)[source]

Compute the day of year for a given year, month and day.

Parameters
• year (int) – Year of date.

• month (int) – Month of date.

• day (int) – Day of date.

Returns

Day of year.

Return type

(int)

astrotool.date_time.fix_date_time(year, month, day, hour, minute, second)[source]

Fix a given set of date and time variables (year, month, day, hour, minute and second) to make them consistent.

For example, month=13 will be corrected to month=1 in the next year, day=32 to a date in the next month, hour=24 to hour=0 on the next day, et cetera. This is useful, because some sources list hours between 1 and 24, rather than 0-23, on which Python’s datetime crashes. In rare cases of roundoff of 59.9 or a leap second, second=60. More generally, this makes it straightforward to add or subtract dates and times and to take into account timezones, DST, et cetera.

Parameters
• year (int) – Year CE. Note that year=0 = 1 BCE.

• month (int) – Month number of year.

• day (int) – Day of month with fraction.

• hour (int) – Hour of time of day.

• minute (int) – Minute of hour of time.

• second (double) – Second of minute of time.

Returns

tuple containing (year CE, month, day, hour, minute, second):

• year (int): Year CE. Note that year=0 = 1 BCE.

• month (int): Month number of year (UT; 1-12).

• day (int): Day of month with fraction (UT; 1-31).

• hour (int): Hour of time of day (0-23).

• minute (int): Minute of hour of time (0-59).

• second (double): Second of minute of time (0.000-59.999).

Return type

tuple (int,int,int, int,int,double)

Note

• uses date_time2jd() and jd2date_time().

astrotool.date_time.gmst(jd)[source]

Calculate Greenwich Mean Sidereal Time for any instant, in radians.

Parameters

jd (double) – Julian day (days).

Returns

gmst: Greenwich mean sidereal time (rad).

Return type

double

References

• Explanatory Supplement to the Astronomical Almanac, 3rd ed, Eq. 6.66 (2012).

astrotool.date_time.jd2date_time(jd)[source]

Compute the date and time from a given Julian Day.

Parameters

jd (double) – Julian day (days).

Returns

tuple containing (year CE, month, day, hour, minute, second):

• year (int): Year CE (UT). Note that year=0 = 1 BCE.

• month (int): Month number of year (UT; 1-12).

• day (int): Day of month with fraction (UT; 1.0-31.999).

• hour (int): Hour of time of day (UT).

• minute (int): Minute of hour of time (UT).

• second (double): Second of minute of time (UT).

Return type

tuple (int,int,int, int,int,double)

Note

• uses jd2ymd().

astrotool.date_time.jd2tjc(jd)[source]

Compute the time in Julian centuries since 2000.0.

Parameters

jd (double) – Julian day (days).

Returns

tjc: Time in Julian centuries since 2000.0 (UT).

Return type

double

astrotool.date_time.jd2tjm(jd)[source]

Compute the time in Julian millennia since 2000.0.

Parameters

jd (double) – Julian day (days).

Returns

tjm: Time in Julian millennia since 2000.0 (UT).

Return type

double

astrotool.date_time.jd2year(jd)[source]

Compute a year with fraction from a given Julian Day.

Parameters

jd (double) – Julian day (days).

Returns

Year CE, with decimals. Note that year=0 indicates 1 BCE.

Return type

double

astrotool.date_time.jd2ymd(jd)[source]

Compute the calendar date from a given Julian Day.

Notes

• Date and time are expressed in UT.

• Decimals can be returned in the day to indicate the time of day, e.g. 1.0 for midnight and 1.5 for noon on the first day of the month.

Parameters

jd (double) – Julian day (days).

Returns

Tuple containing (year, month, day):

• year (int): Year CE (UT). Note that year=0 indicates 1 BCE.

• month (int): Month number of year (UT; 1-12).

• day (double): Day of month with fraction (UT; 1.0-31.999).

Return type

tuple (int,int,double)

astrotool.date_time.julian_day(year, month, day)[source]

Compute the Julian Day for a given year, month and day.

Notes

• Date and time are expressed in UT.

• Decimals can be used in the day to take into account the time of day other than midnight, e.g. 1.5 for noon on the first day of the month.

Parameters
• year (int) – Year CE (UT). Note that year=0 = 1 BCE.

• month (int) – Month number of year (UT; 1-12).

• day (double) – Day of month with fraction (UT; 1.0-31.999).

Returns

jd: Julian day (days).

Return type

double

astrotool.date_time.weekday_en_abbr_from_datetime(datetime)[source]

Return an English abbreviation of the weekday for a given datetime.

Parameters

datetime (datetime)

Returns

String with the three-character English abbreviation of the weekday (Mon-Sun).

Return type

(str)

astrotool.date_time.ymdhms_us_from_datetime64(dt64)[source]

Convert (array of) datetime64 to a calendar (array of) year, month, day, hour, minute, seconds, microsecond with these quantites indexed on the last axis.

Parameters

dt64 (datetime64) – (numpy array of) datetime(s) (of arbitrary shape).

Returns

(…, 7) calendar array with last axis representing year, month, day, hour, minute,

second, microsecond.

Return type

uint32 array