Skip to content

Commit

Permalink
adds helper method for converting products in ASFSearchResults while …
Browse files Browse the repository at this point in the history
…keeping same ASFSearchResults object
  • Loading branch information
kim committed Dec 28, 2023
1 parent 949ffd0 commit ae96099
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion asf_search/ASFSearchResults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections import UserList
from multiprocessing import Pool
import json
from asf_search import ASFSession, ASFSearchOptions
from typing import Type, Callable
from asf_search import ASFSession, ASFSearchOptions, ASFProduct
from asf_search.download.file_download_type import FileDownloadType
from asf_search.exceptions import ASFSearchError

Expand Down Expand Up @@ -79,6 +80,16 @@ def raise_if_incomplete(self) -> None:
ASF_LOGGER.error(msg)
raise ASFSearchError(msg)


def convert_to_sublcass(self, ASFProductSubclass: type(ASFProduct), criteria: Callable[[ASFProduct], bool] = lambda _: True):
count = 0
for idx, product in enumerate(self.data):
if criteria(product):
self.data[idx] = ASFProductSubclass(args={'umm': product.umm, 'meta': product.meta}, session=product.session)
count += 1

ASF_LOGGER.log(f'Converted {count} ASFProduct objects to subclass f{type(ASFProductSubclass)}')

def _download_product(args) -> None:
product, path, session, fileType = args
product.download(path=path, session=session, fileType=fileType)

0 comments on commit ae96099

Please sign in to comment.