Skip to content
Snippets Groups Projects
Commit 2ed7a264 authored by Sam Kagan's avatar Sam Kagan
Browse files

Added MJD converter

parent 8e3ead95
No related branches found
No related tags found
No related merge requests found
......@@ -19,3 +19,19 @@
Workspaces data delivery module
"""
__version__ = "2.8.5.dev1"
from datetime import datetime
def convert_datetime_to_mjd(timestamp: datetime) -> float:
"""Convert UTC datetime to MJD
Sources:
- https://www.celestialprogramming.com/julian.html for JD
- https://core2.gsfc.nasa.gov/time/a for MJD
"""
secs_since_posix_epoch = timestamp.timestamp()
SECS_IN_DAY = 86400
SECS_FROM_JD_TO_POSIX_EPOCHS = 2440587.5
JD_TO_MJD = 2400000.5
return (secs_since_posix_epoch / SECS_IN_DAY) + SECS_FROM_JD_TO_POSIX_EPOCHS - JD_TO_MJD
......@@ -27,6 +27,7 @@ import re
from typing import Iterator, List
import pendulum
from delivery import convert_datetime_to_mjd
from pendulum.datetime import DateTime
from .products import ArchiveProduct, ProductMetadata, RestoreProduct, SpooledProduct
......@@ -136,7 +137,7 @@ class RestoreProductFinder(ProductFinder):
start_timestamp_match = re.match(r"^casa-(?P<timestamp>[0-9]+-[0-9]+).log$", casa_log_name)
assert start_timestamp_match
start_timestamp = pendulum.from_format(start_timestamp_match.group("timestamp"), "YYYYMMDD-HHmmss")
start_mjd = date_to_mjd(start_timestamp)
start_mjd = convert_datetime_to_mjd(start_timestamp)
return ProductMetadata(
project_metadata["telescope"], project_metadata["project_code"], "restored_cms", None, None, str(start_mjd)
)
......@@ -147,7 +148,3 @@ class RestoreProductFinder(ProductFinder):
def find_products(self) -> Iterator[SpooledProduct]:
yield RestoreProduct(self.dir, self._metadata)
def date_to_mjd(timestamp: DateTime) -> float:
return 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment