def hrefs_from_catalog(catalog: Catalog, N: int = None) -> Tuple[str, str]: def find_label_collection(c): return 'label' in str.lower(c.description) catalog.make_all_asset_hrefs_absolute() labels = next(filter(find_label_collection, catalog.get_children())) label_items = list(labels.get_items()) label_hrefs = [] imagery_hrefs = [] for item in label_items: try: imagery = item.get_links('source')[0] imagery.resolve_stac_object() imagery_href = imagery.target.assets.get('cog').href except: imagery_href = None label_href = pystac_workaround(item.assets.get('data').href) label_hrefs.append(label_href) if imagery_href.startswith('./'): imagery_href = re.sub('^\.\/[0-9]+-', './', imagery_href) imagery_href = imagery_href.replace('14060at01p00r17', '140603t01p00r17') imagery_hrefs.append(imagery_href) if N is not None: N = int(N) label_hrefs = [label_hrefs[N]] imagery_hrefs = [imagery_hrefs[N]] return (label_hrefs, imagery_hrefs)
def hrefs_from_catalog(catalog: Catalog) -> Tuple[str, str]: catalog.make_all_asset_hrefs_absolute() catalog = next(catalog.get_children()) children = list(catalog.get_children()) imagery = next(filter(lambda child: \ "image" in str.lower(child.description), children)) imagery_item = next(imagery.get_items()) imagery_assets = list(imagery_item.assets.values()) imagery_href = pystac_workaround(imagery_assets[1].href) labels = next(filter(lambda child: \ "label" in str.lower(child.description), children)) labels_item = next(labels.get_items()) labels_href = pystac_workaround( next(iter(labels_item.assets.values())).href) label_dict = labels_item.to_dict() label_dict['properties']['class_id'] = None aoi_geometries = [label_dict] return (imagery_href, labels_href, aoi_geometries)