conversions (class)

class conversions(log, settings=False)[source]

Bases: object

The worker class for the conversions module

Key Arguments

  • log – logger

  • settings – the settings dictionary

Usage

Todo

  • add usage info

  • create a sublime snippet for usage

  • add mjd_to_date

  • add decimal_day_to_day_hour_min_sec

  • add date_to_mjd

  • convert all functions in __init__ to modules

usage code

Methods

decimal_day_to_day_hour_min_sec(daysFloat)

Convert a day from decimal format to hours mins and sec

get()

get the conversions object

mjd_to_ut_datetime(mjd[, sqlDate, …])

mjd to ut datetime

ut_datetime_to_mjd(utDatetime)

ut datetime to mjd

decimal_day_to_day_hour_min_sec(daysFloat)[source]

Convert a day from decimal format to hours mins and sec

Precision should be respected.

Key Arguments

  • daysFloat – the day as a decimal.

Return

  • daysInt – day as an integer

  • hoursInt – hour as an integer (None if input precsion too low)

  • minsInt – mins as an integer (None if input precsion too low)

  • secFloat – secs as a float (None if input precsion too low)

Usage

Todo

  • replace decimal_day_to_day_hour_min_sec in all other code

from astrocalc.times import conversions
converter = conversions(
    log=log
)
daysInt, hoursInt, minsInt, secFloat = converter.decimal_day_to_day_hour_min_sec(
    daysFloat=24.2453
)
print(daysInt, hoursInt, minsInt, secFloat)

# OUTPUT: 24, 5, 53, None

daysInt, hoursInt, minsInt, secFloat = converter.decimal_day_to_day_hour_min_sec(
    daysFloat=24.1232435454
)
print("%(daysInt)s days, %(hoursInt)s hours, %(minsInt)s mins, %(secFloat)s sec" % locals())

# OUTPUT: 24 days, 2 hours, 57 mins, 28.242 sec
get()[source]

get the conversions object

Return

  • conversions

- @review: when complete, clean get method
- @review: when complete add logging
mjd_to_ut_datetime(mjd, sqlDate=False, datetimeObject=False)[source]

mjd to ut datetime

Precision should be respected.

Key Arguments

  • mjd – time in MJD.

  • sqlDate – add a ‘T’ between date and time instead of space

  • datetimeObject – return a datetime object instead of a string. Default False

Todo

  • replace getDateFromMJD in all code

  • replace getSQLDateFromMJD in all code

Return

  • utDatetime - the UT datetime in string format

Usage

from astrocalc.times import conversions
converter = conversions(
    log=log
)
utDate = converter.mjd_to_ut_datetime(
    mjd=57504.61577585013
)
print(utDate)

# OUT: 2016-04-26 14:46:43.033

utDate = converter.mjd_to_ut_datetime(
    mjd=57504.61577585013,
    sqlDate=True
)
print(utDate)

# OUT: 2016-04-26T14:46:43.033
ut_datetime_to_mjd(utDatetime)[source]

ut datetime to mjd

If the date given has no time associated with it (e.g. 20160426), then the datetime assumed is 20160426 00:00:00.0.

Precision should be respected.

Key Arguments

  • utDatetime – UT datetime. Can accept various formats e.g. 201604261444, 20160426, 20160426144444.5452, 2016-04-26 14:44:44.234, 20160426 14h44m44.432s

Return

  • mjd – the MJD

Todo

  • replace getMJDFromSqlDate in all code

Usage

from astrocalc.times import conversions
converter = conversions(
    log=log
)
mjd = converter.ut_datetime_to_mjd(utDatetime="20160426t1446")
print(mjd)

# OUT: 57504.6153

mjd = converter.ut_datetime_to_mjd(utDatetime="2016-04-26 14:44:44.234")
print(mjd)

# OUT: 57504.61440