Skip to content

Commit

Permalink
Adds warning when missing state vectors for relevant baseline stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Dec 21, 2023
1 parent 8941d59 commit 24246bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions asf_search/baseline/stack.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
from typing import Tuple, List
from dateutil.parser import parse
import pytz
from .calc import calculate_perpendicular_baselines
from asf_search import ASFProduct, ASFSearchResults

precalc_datasets = ['AL', 'R1', 'E1', 'E2', 'J1']

def get_baseline_from_stack(reference: ASFProduct, stack: ASFSearchResults):
warnings = None
def get_baseline_from_stack(reference: ASFProduct, stack: ASFSearchResults) -> Tuple[ASFSearchResults, List[dict]]:
warnings = []

if len(stack) == 0:
raise ValueError('No products found matching stack parameters')
stack = [product for product in stack if not product.properties['processingLevel'].lower().startswith('metadata') and product.baseline != None]
reference, stack, warnings = check_reference(reference, stack)
reference, stack, reference_warnings = check_reference(reference, stack)

if reference_warnings is not None:
warnings.append(reference_warnings)

stack = calculate_temporal_baselines(reference, stack)

if get_platform(reference.properties['sceneName']) in precalc_datasets:
stack = offset_perpendicular_baselines(reference, stack)
else:
stack = calculate_perpendicular_baselines(reference.properties['sceneName'], stack)

if missing_state_vectors := len([scene for scene in stack if scene.baseline.get('noStateVectors')]):
warnings.append({'MISSING STATE VECTORS': f'{missing_state_vectors} scenes in stack missing State Vectors, perpendicular baseline not calculated for these scenes'})

return ASFSearchResults(stack), warnings

def valid_state_vectors(product: ASFProduct):
Expand All @@ -40,8 +47,7 @@ def check_reference(reference: ASFProduct, stack: ASFSearchResults):
warnings = None
if reference.properties['sceneName'] not in [product.properties['sceneName'] for product in stack]: # Somehow the reference we built the stack from is missing?! Just pick one
reference = stack[0]
warnings = [{'NEW_REFERENCE': 'A new reference scene had to be selected in order to calculate baseline values.'}]

warnings = {'NEW_REFERENCE': 'A new reference scene had to be selected in order to calculate baseline values.'}
if get_platform(reference.properties['sceneName']) in precalc_datasets:
if 'insarBaseline' not in reference.baseline:
raise ValueError('No baseline values available for precalculated dataset')
Expand All @@ -50,8 +56,7 @@ def check_reference(reference: ASFProduct, stack: ASFSearchResults):
reference = find_new_reference(stack)
if reference == None:
raise ValueError('No valid state vectors on any scenes in stack, this is fatal')
warnings = [{'NEW_REFERENCE': 'A new reference had to be selected in order to calculate baseline values.'}]

warnings = {'NEW_REFERENCE': 'A new reference had to be selected in order to calculate baseline values.'}
return reference, stack, warnings

def get_platform(reference: str):
Expand Down
4 changes: 4 additions & 0 deletions asf_search/search/baseline_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from asf_search import ASF_LOGGER
from asf_search.baseline.stack import get_baseline_from_stack, get_default_product_type
from copy import copy

Expand Down Expand Up @@ -43,6 +44,9 @@ def stack_from_product(

stack.sort(key=lambda product: product.properties['temporalBaseline'])

for warning in warnings:
ASF_LOGGER.warn(f'{warning}')

return stack


Expand Down

0 comments on commit 24246bf

Please sign in to comment.