diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8b241e --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +Author: Kuznetsova E. , Shtykovsky A. + +# arttools + +This package contains ART-XC data processing tools. The package will be updated with other tools as they are created. + +## arttime + +At the current moment artools contains only arttime module. The arttime tool allows to calculate artdays and/or mission time based on Moscow time (and UTC) or MJD and convert them to each other. + +Warning: This tool should not be used to precisely convert of onboard time to real time. + +### To install: + +Clone the repo to your computer:: + +``` +git clone http://heagit.cosmos.ru:3000/kea/arttools arttools/ +``` + +Enter the repo and install it with:: + +``` +cd +pip intstall . +``` + +### To invoke + +``` +from arttools import arttime +``` + +### To use: + +``` +aday = arttime.ArtTime(artday=8000) +aday.artday +aday.missiontime +aday.mjd +aday.datetime_utc +aday.datetime_msk +print(aday) +``` + +Available arguments: + ++ artday - ART-XC days ++ missiontime - Mission time - onboard ART-XC seconds ++ mjd - MJD ++ datetime_utc - Date time based on UTC time zone ++ datetime_msk - Date time based on Moscow time zone (UTC+3) + +### Usage CLI + +``` +$ arttime --artday=8000 +$ arttime --missiontime=691200000 +$ arttime --mjd=59543.875 +$ arttime --datetime_utc=2021-11-25T21:00:00 +$ arttime --datetime_msk=2021-11-26T00:00:00 +``` + +Available parameters: + ++ --artday (--aday) - ART-XC days ++ --missiontime (--mtime) - Mission time - onboard ART-XC seconds ++ --mjd - MJD ++ --datetime_utc (--dt_utc) - Date time based on UTC time zone ++ --datetime_msk (--dt_msk) - Date time based on Moscow time zone (UTC+3) \ No newline at end of file diff --git a/README.rst b/README.rst deleted file mode 100644 index e480fff..0000000 --- a/README.rst +++ /dev/null @@ -1,26 +0,0 @@ -# Author: Kuznetsova E. , Shtykovsky A. - -======== -arttools -======== - -This package was created as a storage of tools for processing of ART-XC data. The package will be updated with other tools as they are created. - -At the current moment artools contains only arttime module. The arttime tool allows to calculate artdays and/or mission time based on Mosckow time (and UTC) or MJD and convert them to each other. - ----------- -To install: ----------- - -Clone the repo to your computer:: - -git clone https://github.com/eblur/newdust.git newdust/ - -Enter the repo and install it with:: - -cd -pip intstall . - -To invoke:: - -from arttools import arttime diff --git a/arttools/arttime.py b/arttools/arttime.py index 775e1fe..a86737f 100755 --- a/arttools/arttime.py +++ b/arttools/arttime.py @@ -2,7 +2,8 @@ # -*- coding: utf8 -*- from datetime import datetime - +import sys +import argparse import astropy.units as u from astropy.time.formats import erfa from astropy.time import Time @@ -122,31 +123,41 @@ class ArtTime(object): def __init__(self, artday=None, missiontime=None, mjd=None, datetime_utc=None, datetime_msk=None): - self._has_value = False + self._has_value = 0 self._try_aday(artday) self._try_mtime(missiontime) self._try_mjd(mjd) self._try_dtime_utc(datetime_utc) self._try_dtime_msk(datetime_msk) + self + + if self._has_value > 1: + print('Error: ArtTime needs only one argument') + exit() + + if self._has_value == 0: + datetime_utc = datetime.utcnow() + self._try_dtime_utc(datetime_utc.isoformat()) def _try_mtime(self, missiontime): if missiontime is None: return - self._has_value = True + self._has_value = self._has_value+1 self._missiontime = MissionTime(missiontime) self._artday = ArtDay(self._missiontime.to_artday()) self._mjd = MjdDay(self._missiontime.to_mjd()) self._datetime_utc = Dtime(dtime=str(self._missiontime.to_datetime(tzone=TZ_UTC))) self._datetime_msk = Dtime(dtime=str(self._missiontime.to_datetime(tzone=TZ_MSK))) + return def _try_aday(self, artday): if artday is None: return - self._has_value = True - + self._has_value = self._has_value+1 + self._artday = ArtDay(artday) self._missiontime = MissionTime(self._artday.to_mission()) self._mjd = MjdDay(self._artday.to_mjd()) @@ -157,7 +168,7 @@ class ArtTime(object): if mjd is None: return - self._has_value = True + self._has_value = self._has_value+1 self._mjd = MjdDay(mjd) self._artday = ArtDay(self._mjd.to_artday()) @@ -169,7 +180,7 @@ class ArtTime(object): if datetime_utc is None: return - self._has_value = True + self._has_value = self._has_value+1 self._datetime_utc = Dtime(datetime_utc, tzone=TZ_UTC) self._datetime_msk = Dtime(str(self._datetime_utc.to_msk())) @@ -181,7 +192,7 @@ class ArtTime(object): if datetime_msk is None: return - self._has_value = True + self._has_value = self._has_value+1 self._datetime_msk = Dtime(datetime_msk, tzone=TZ_MSK) self._datetime_utc = Dtime(str(self._datetime_msk.to_utc())) @@ -218,7 +229,59 @@ class ArtTime(object): return str(aday_str+mtime_str+mjd_str+date_msk_str+date_utc_str) +def main(): + parser = argparse.ArgumentParser( + description=("The arttime tool converts artdays, mission time, MSK and UTC date time" + " and MJD to each other. Calling arttime without parameters will use the current " + "local time as input.") + ) + parser.add_argument( + "--artday", "--aday", type=float, + help=("ART-XC days." + "Example: arttime --artday=8000") + ) + parser.add_argument( + "--missiontime", "--mtime", type=float, + help=("Onboard ART-XC seconds. " + "Example: arttime --missiontime=691200000") + ) + parser.add_argument( + "--mjd", type=float, + help=("MJD. " + "Example: arttime --mjd=59543.875") + ) + parser.add_argument( + "--datetime_utc", "--dt_utc", type=str, + help=("Date time based on UTC time zone. \n" + "Example: arttime --datetime_utc=2021-11-25T21:00:00") + ) + parser.add_argument( + "--datetime_msk", "--dt_msk", type=str, + help=("Date time based on Moscow time zone (UTC+3). " + "Example: arttime --datetime_msk=2021-11-26T00:00:00'") + ) + args = parser.parse_args() + if args.artday is not None: + print(ArtTime(artday=args.artday)) + + if args.missiontime is not None: + print(ArtTime(missiontime=args.missiontime)) + + if args.mjd is not None: + print(ArtTime(mjd=args.mjd)) + + if args.datetime_utc is not None: + print(ArtTime(datetime_utc=args.datetime_utc)) + + if args.datetime_msk is not None: + print(ArtTime(datetime_msk=args.datetime_msk)) + + if len(sys.argv) <= 1: + datetime_utc = datetime.utcnow() + print('Convertation for the current local time') + print(ArtTime(datetime_utc=datetime_utc.isoformat())) + if __name__ == '__main__': - - pass \ No newline at end of file + + main() \ No newline at end of file diff --git a/setup.py b/setup.py index f4d4343..1f38ed2 100644 --- a/setup.py +++ b/setup.py @@ -1,2 +1,10 @@ from setuptools import setup -setup(use_scm_version=True) \ No newline at end of file + +setup( + use_scm_version=True, + entry_points={ + "console_scripts": [ + "arttime = arttools.arttime:main", + ] + } +) \ No newline at end of file