Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ciso8601 for date parsing in baseline calculations #750

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ Werkzeug==2.3.3
WKTUtils==2.0.0
wrapt==1.16.0
zipp==3.6.0
zope.interface==4.7.2
zope.interface==4.7.2
Loading