|
| 1 | +from copy import copy |
1 | 2 | import json |
2 | 3 |
|
3 | 4 | import os |
|
19 | 20 | from . import constants |
20 | 21 | from .SearchAPISession import SearchAPISession |
21 | 22 | from asf_search.ASFSearchOptions.config import config as asf_config |
| 23 | +from asf_enumeration import aria_s1_gunw |
22 | 24 |
|
23 | 25 | asf_config['session'] = SearchAPISession() |
24 | 26 |
|
@@ -115,18 +117,13 @@ async def query_baseline(searchOptions: BaselineSearchOptsModel = Depends(proces |
115 | 117 | } |
116 | 118 | ) |
117 | 119 |
|
118 | | - # reference_product = None |
119 | 120 | if is_frame_based and opts.dataset[0] == asf.DATASET.ARIA_S1_GUNW: |
120 | | - try: |
121 | | - reference_product = asf.search(frame=int(reference), opts=opts, maxResults=1)[0] |
122 | | - except (KeyError, IndexError, ValueError) as exc: |
123 | | - raise HTTPException(detail=f"Reference scene not found with frame: {reference}", status_code=400) from exc |
| 121 | + return _get_aria_baseline_stack(reference=reference, opts=opts, output=output) |
124 | 122 |
|
125 | | - else: |
126 | | - try: |
127 | | - reference_product = asf.granule_search(granule_list=[reference], opts=opts)[0] |
128 | | - except (KeyError, IndexError, ValueError) as exc: |
129 | | - raise HTTPException(detail=f"Reference scene not found: {reference}", status_code=400) from exc |
| 123 | + try: |
| 124 | + reference_product = asf.granule_search(granule_list=[reference], opts=opts)[0] |
| 125 | + except (KeyError, IndexError, ValueError) as exc: |
| 126 | + raise HTTPException(detail=f"Reference scene not found: {reference}", status_code=400) from exc |
130 | 127 |
|
131 | 128 | try: |
132 | 129 | if reference_product.get_stack_opts() is None: |
@@ -270,6 +267,23 @@ def validate_wkt(wkt: str): |
270 | 267 | 'repairs': repairs |
271 | 268 | } |
272 | 269 |
|
| 270 | +def _get_aria_baseline_stack(reference: str, opts: asf.ASFSearchOptions, output: str): |
| 271 | + if output.lower() == 'count': |
| 272 | + stack_opts = asf.Products.ARIAS1GUNWProduct.get_stack_opts_for_frame(int(reference), opts=opts) |
| 273 | + count=asf.search_count(opts=stack_opts) |
| 274 | + return Response( |
| 275 | + content=str(count), |
| 276 | + status_code=200, |
| 277 | + media_type='text/html; charset=utf-8', |
| 278 | + headers=constants.DEFAULT_HEADERS |
| 279 | + ) |
| 280 | + try: |
| 281 | + stack = asf.stack_from_id(reference, opts=opts) |
| 282 | + response_info = as_output(stack, output) |
| 283 | + return Response(**response_info) |
| 284 | + except (KeyError, IndexError, ValueError) as exc: |
| 285 | + raise HTTPException(detail=f"Reference scene not found with frame: {reference}", status_code=400) from exc |
| 286 | + |
273 | 287 |
|
274 | 288 | @router.get('/', response_class=JSONResponse) |
275 | 289 | @router.get('/health', response_class=JSONResponse) |
|
0 commit comments