Compare commits
3 Commits
035e80e5de
...
cf81fbddfa
Author | SHA1 | Date | |
---|---|---|---|
cf81fbddfa | |||
3fac25b620 | |||
fba1733479 |
70
README.md
Normal file
70
README.md
Normal file
@ -0,0 +1,70 @@
|
||||
Author: Kuznetsova E. <eakuznetsova@cosmos.ru>, 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 <PATH_TO_ARTTOOLS>
|
||||
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)
|
26
README.rst
26
README.rst
@ -1,26 +0,0 @@
|
||||
# Author: Kuznetsova E. <eakuznetsova@cosmos.ru>, 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 <PATH_TO_ARTTOOLS>
|
||||
pip intstall .
|
||||
|
||||
To invoke::
|
||||
|
||||
from arttools import arttime
|
@ -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
|
||||
@ -20,6 +21,10 @@ class MissionTime(object):
|
||||
def get(self):
|
||||
return self._missiontime
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
return self._missiontime
|
||||
|
||||
def __str__(self):
|
||||
return str(self._missiontime)
|
||||
|
||||
@ -44,6 +49,10 @@ class ArtDay(object):
|
||||
def get(self):
|
||||
return self._artday
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
return self._artday
|
||||
|
||||
def __str__(self):
|
||||
return str(self._artday)
|
||||
|
||||
@ -68,6 +77,10 @@ class MjdDay(object):
|
||||
def get(self):
|
||||
return self._mjd
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
return self._mjd
|
||||
|
||||
def __str__(self):
|
||||
return str(self._mjd)
|
||||
|
||||
@ -95,6 +108,10 @@ class Dtime(object):
|
||||
def get(self):
|
||||
return self._dtime
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
return self._dtime
|
||||
|
||||
def __str__(self):
|
||||
return str(self._dtime)
|
||||
|
||||
@ -122,31 +139,40 @@ 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)
|
||||
|
||||
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 +183,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 +195,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 +207,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 +244,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
|
||||
|
||||
main()
|
10
setup.py
10
setup.py
@ -1,2 +1,10 @@
|
||||
from setuptools import setup
|
||||
setup(use_scm_version=True)
|
||||
|
||||
setup(
|
||||
use_scm_version=True,
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"arttime = arttools.arttime:main",
|
||||
]
|
||||
}
|
||||
)
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
94
test/test_arttime.py
Normal file
94
test/test_arttime.py
Normal file
@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from datetime import datetime
|
||||
from arttools import arttime
|
||||
from astropy.time import Time
|
||||
from arttools.arttime import TZ_UTC
|
||||
from arttools.arttime import TZ_MSK
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
class TestConvertArtday(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._test_conv = {'artday': 8000., 'missiontime': 691200000., 'mjd': 59543.875,
|
||||
'datetime_msk': '2021-11-26T00:00:00', 'datetime_utc': '2021-11-25T21:00:00'}
|
||||
self._test_mjd = Time(self._test_conv['mjd'], format='mjd')
|
||||
self._test_dtime_utc = datetime.fromisoformat(self._test_conv['datetime_utc']).replace(tzinfo=TZ_UTC)
|
||||
self._test_dtime_msk = datetime.fromisoformat(self._test_conv['datetime_msk']).replace(tzinfo=TZ_MSK)
|
||||
|
||||
def test_ArtTime_mjd(self):
|
||||
mjd = arttime.ArtTime(mjd=self._test_conv['mjd'])
|
||||
self.assertEqual(mjd.mjd.time, self._test_mjd)
|
||||
|
||||
def test_mjd_convert(self):
|
||||
mjd = arttime.ArtTime(mjd=self._test_conv['mjd'])
|
||||
test_dtime_utc = datetime.fromisoformat(self._test_conv['datetime_utc']).replace(tzinfo=TZ_UTC)
|
||||
test_dtime_msk = datetime.fromisoformat(self._test_conv['datetime_msk']).replace(tzinfo=TZ_MSK)
|
||||
self.assertEqual(mjd.artday.time, self._test_conv['artday'])
|
||||
self.assertEqual(mjd.missiontime.time, self._test_conv['missiontime'])
|
||||
self.assertEqual(mjd.datetime_utc.time, test_dtime_utc)
|
||||
self.assertEqual(mjd.datetime_msk.time, test_dtime_msk)
|
||||
|
||||
def test_ArtTime_artday(self):
|
||||
artday = arttime.ArtTime(artday=self._test_conv['artday'])
|
||||
self.assertEqual(artday.artday.time, self._test_conv['artday'])
|
||||
|
||||
def test_artday_convert(self):
|
||||
artday = arttime.ArtTime(artday=self._test_conv['artday'])
|
||||
self.assertEqual(artday.mjd.time, self._test_mjd)
|
||||
self.assertEqual(artday.missiontime.time, self._test_conv['missiontime'])
|
||||
self.assertEqual(artday.datetime_utc.time, self._test_dtime_utc)
|
||||
self.assertEqual(artday.datetime_msk.time, self._test_dtime_msk)
|
||||
|
||||
def test_ArtTime_missiontime(self):
|
||||
missiontime = arttime.ArtTime(missiontime=self._test_conv['missiontime'])
|
||||
self.assertEqual(missiontime.missiontime.time, self._test_conv['missiontime'])
|
||||
|
||||
def test_cyclic_conversion_missiontime(self):
|
||||
missiontime = arttime.ArtTime(missiontime=self._test_conv['missiontime'])
|
||||
datetime_utc = str(missiontime.datetime_utc)
|
||||
test_datetime_utc = arttime.ArtTime(datetime_utc=datetime_utc)
|
||||
self.assertEqual(missiontime.missiontime.time, test_datetime_utc.missiontime.time)
|
||||
|
||||
def test_missiontime_convert(self):
|
||||
missiontime = arttime.ArtTime(missiontime=self._test_conv['missiontime'])
|
||||
self.assertEqual(missiontime.mjd.time, self._test_mjd)
|
||||
self.assertEqual(missiontime.artday.time, self._test_conv['artday'])
|
||||
self.assertEqual(missiontime.datetime_utc.time, self._test_dtime_utc)
|
||||
self.assertEqual(missiontime.datetime_msk.time, self._test_dtime_msk)
|
||||
|
||||
def test_ArtTime_datetime_utc(self):
|
||||
datetime_utc = arttime.ArtTime(datetime_utc=self._test_conv['datetime_utc'])
|
||||
self.assertEqual(datetime_utc.datetime_utc.time, self._test_dtime_utc)
|
||||
|
||||
def test_datetime_utc_convert(self):
|
||||
datetime_utc = arttime.ArtTime(datetime_utc=self._test_conv['datetime_utc'])
|
||||
self.assertEqual(datetime_utc.mjd.time, self._test_mjd)
|
||||
self.assertEqual(datetime_utc.artday.time, self._test_conv['artday'])
|
||||
self.assertEqual(datetime_utc.missiontime.time, self._test_conv['missiontime'])
|
||||
self.assertEqual(datetime_utc.datetime_msk.time, self._test_dtime_msk)
|
||||
|
||||
def test_ArtTime_datetime_msk(self):
|
||||
datetime_msk = arttime.ArtTime(datetime_msk=self._test_conv['datetime_msk'])
|
||||
self.assertEqual(datetime_msk.datetime_msk.time, self._test_dtime_msk)
|
||||
|
||||
def test_datetime_msk_convert(self):
|
||||
datetime_msk = arttime.ArtTime(datetime_msk=self._test_conv['datetime_msk'])
|
||||
self.assertEqual(datetime_msk.mjd.time, self._test_mjd)
|
||||
self.assertEqual(datetime_msk.artday.time, self._test_conv['artday'])
|
||||
self.assertEqual(datetime_msk.missiontime.time, self._test_conv['missiontime'])
|
||||
self.assertEqual(datetime_msk.datetime_utc.time, self._test_dtime_utc)
|
||||
|
||||
def test_ArtTime(self):
|
||||
datetime_utcnow = arttime.ArtTime()
|
||||
test_datetime_utcnow = datetime.utcnow().replace(tzinfo=TZ_UTC)
|
||||
self.assertLess((test_datetime_utcnow - datetime_utcnow.datetime_utc.time).total_seconds(), 60.)
|
||||
|
||||
#### Add test for several parameters
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user