From 22d7c1a7eff2bd884b7c494456269d7c43d82268 Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 22 Apr 2024 15:27:35 -0800 Subject: [PATCH] use ciso8601 for date parsing in baseline calculations --- SearchAPI/Baseline/Calc.py | 13 ++++++------- SearchAPI/Baseline/Stack.py | 6 +++--- requirements.txt | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SearchAPI/Baseline/Calc.py b/SearchAPI/Baseline/Calc.py index edc10550..78d4cc7e 100644 --- a/SearchAPI/Baseline/Calc.py +++ b/SearchAPI/Baseline/Calc.py @@ -1,7 +1,6 @@ from math import sqrt, cos, sin, radians import numpy as np -import dateparser - +import ciso8601 # WGS84 constants a = 6378137 f = pow((1.0 - 1 / 298.257224), 2) @@ -15,17 +14,17 @@ def calculate_perpendicular_baselines(reference, stack): product['noStateVectors'] = True continue - asc_node_time = dateparser.parse(product['ascendingNodeTime']).timestamp() + asc_node_time = ciso8601.parse_datetime(product['ascendingNodeTime']).timestamp() - start = dateparser.parse(product['startTime']).timestamp() - end = dateparser.parse(product['stopTime']).timestamp() + start = ciso8601.parse_datetime(product['startTime']).timestamp() + end = ciso8601.parse_datetime(product['stopTime']).timestamp() center = start + ((end - start) / 2) product['relative_start_time'] = start - asc_node_time product['relative_center_time'] = center - asc_node_time product['relative_end_time'] = end - asc_node_time - t_pre = dateparser.parse(product['sv_t_pos_pre']).timestamp() - t_post = dateparser.parse(product['sv_t_pos_post']).timestamp() + t_pre = ciso8601.parse_datetime(product['sv_t_pos_pre']).timestamp() + t_post = ciso8601.parse_datetime(product['sv_t_pos_post']).timestamp() product['relative_sv_pre_time'] = t_pre - asc_node_time product['relative_sv_post_time'] = t_post - asc_node_time diff --git a/SearchAPI/Baseline/Stack.py b/SearchAPI/Baseline/Stack.py index 8d0d7559..0f20ab89 100644 --- a/SearchAPI/Baseline/Stack.py +++ b/SearchAPI/Baseline/Stack.py @@ -1,4 +1,4 @@ -import dateparser +import ciso8601 from SearchAPI.CMR.Translate import translate_params, input_fixer from SearchAPI.CMR.Query import CMRQuery from .Calc import calculate_perpendicular_baselines @@ -178,13 +178,13 @@ def get_default_product_type(reference): def calculate_temporal_baselines(reference, stack): for product in stack: if product['granuleName'] == reference: - reference_start = dateparser.parse(product['startTime']) + reference_start = ciso8601.parse_datetime(product['startTime']) break for product in stack: if product['granuleName'] == reference: product['temporalBaseline'] = 0 else: - start = dateparser.parse(product['startTime']) + start = ciso8601.parse_datetime(product['startTime']) product['temporalBaseline'] = (start.date() - reference_start.date()).days return stack diff --git a/requirements.txt b/requirements.txt index ad7ba162..525499f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -109,3 +109,4 @@ wrapt==1.13.2 zipp==3.6.0 zope.interface==4.7.2 numpy==1.21.3 +ciso8601==2.3.1