Exemplo n.º 1
0
def create_temp_catalog_copy(tmp_dir):
    col = TestCases.planet_disaster()
    col.normalize_hrefs(tmp_dir)
    col.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)
    move_all_assets(col, copy=True)
    col.save()

    return col
Exemplo n.º 2
0
def layout_catalog(catalog,
                   item_path_template,
                   create_subcatalogs=False,
                   remove_existing_subcatalogs=False,
                   move_assets=False):
    """Modify the layout of a STAC.

    Given a catalog and a layout template, modify the layout of the STAC
    to either generate subcatalogs based on item properties, or create subdirectories
    to organize item properties. Both of these are based on the template string
    provided. See the ``LayoutTemplate`` PySTAC API docs for more information on
    template strings.

    Args:
        catalog (Catalog or Collection): The Catalog or Collection to change the layout of.
        item_path_template (str): A string that represents a path of item properties,
            e.g. "${year}/${month}"
        create_subcatalogs (bool): If True, create subcatalogs for each of the
            template directory levels using the item properties to determine which
            catalog it belongs to.
        remove_existing_subcatalogs (bool): If True, apply the subcatalogs to all
            items throughout the catalog and clear any child catalogs, using
            the newly generated subcatalogs or item paths.
        move_assets (bool): If True, the assets of the Items will be moved alongside
            of the Items. Otherwise the asset will remain in place, with the moved
            Item's asset HREFs reflecting the existing location.

    Returns:
        Catalog or Collection: The passed in Catalog. This operation mutates the catalog.
    """

    if remove_existing_subcatalogs:
        items = catalog.get_all_items()
        for item in items:
            item.get_parent().remove_item(item.id)
            catalog.add_item(item)

        catalog.clear_children()

    if create_subcatalogs:
        catalog.generate_subcatalogs(template=item_path_template)
        catalog.normalize_hrefs(os.path.dirname(catalog.get_self_href()))
    else:
        strategy = TemplateLayoutStrategy(item_template=item_path_template)
        catalog.normalize_hrefs(os.path.dirname(catalog.get_self_href()),
                                strategy=strategy)

    if move_assets:
        move_all_assets(catalog, ignore_conflicts=True)

    return catalog
Exemplo n.º 3
0
def convert_order(manifest,
                  destination,
                  collection_id,
                  move_assets=False,
                  copy=False,
                  description=None,
                  title=None,
                  skip_validation=False):
    manifest = OrderManifest.from_file(manifest)
    collection = manifest.to_stac(collection_id=collection_id,
                                  description=description,
                                  title=title)
    collection.normalize_hrefs(destination)

    if not skip_validation:
        collection.validate_all()

    logger.info('Saving STAC collection at {}...'.format(
        collection.get_self_href()))
    collection.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)

    # Move assets after save to avoid moving without saving,
    # and so the directory structure is generated.
    if move_assets:
        logger.info('Moving assets into STAC...')
        collection = core.move_all_assets(collection, copy=copy)
        collection.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)
Exemplo n.º 4
0
def copy_two_planet_disaster_subsets(tmp_dir):
    """Test setup util that makes two copies of subset of the planet
    disaster data, each containing a single item. Updates the collection
    extents to match the single items.

    Returns a list of collection paths in the temporary directory.
    """
    item_ids = ['20170831_172754_101c', '20170831_162740_ssc1d1']
    new_cols = []
    for item_id in item_ids:
        col = TestCases.planet_disaster()
        for item in list(col.get_all_items()):
            if item.id != item_id:
                item.get_parent().remove_item(item.id)
        col.update_extent_from_items()
        col.normalize_hrefs(os.path.join(tmp_dir, item_id))
        col.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)
        move_all_assets(col, copy=True)
        col.save()
        new_cols.append(col.get_self_href())

    return new_cols