Skip to content

Commit

Permalink
use ciso8601 for date parsing in baseline calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Apr 22, 2024
1 parent dc114d9 commit 22d7c1a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
13 changes: 6 additions & 7 deletions SearchAPI/Baseline/Calc.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions SearchAPI/Baseline/Stack.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 22d7c1a

Please sign in to comment.