예제 #1
0
def item2dataset(stacservice, item_filter, mapper: Stac2ODCMapper,
                 **kwargs) -> None:
    """Function to convert a STAC Collection JSON to ODC Dataset YAML

    Args:
        stacservice (stac.collection.Collection): An Collection
        item_filter (dict): A dict with behavior definitions
        mapper (stac2odc.mapper.Stac2ODCMapper): An mapper to convert STAC collection to ODC Datasets
    See:
        See the BDC STAC catalog for more information on the collections available
        (http://brazildatacube.dpi.inpe.br/bdc-stac/0.8.0/)
    """

    if kwargs['verbose']:
        logger.info("item2dataset is running!")

    total_items = 0
    limit = STAC_ITEM_PER_PAGE
    max_items = kwargs['max_items']

    if kwargs['verbose']:
        logger.info("Collecting information from STAC...")

    for page in range(1, STAC_MAX_PAGE + 1):
        if max_items is not None and max_items == total_items:
            break

        if limit > (max_items - total_items):
            limit = (max_items - total_items)

        collection = stacservice.collection(item_filter["collections"][0])
        features = stacservice.search({
            **item_filter,
            **{
                "page": page,
                "limit": limit
            }
        }).features

        if len(features) == 0:
            break

        # Multiple dataset is ignored!
        odc_items = mapper.map_dataset(collection, features, **kwargs)
        total_items += len(odc_items)

        if kwargs['verbose']:
            logger.info('Saving page {}'.format(page))

        for odc_item in odc_items:
            with open(
                    '{}.yaml'.format(
                        os.path.join(kwargs['outpath'], odc_item['id'])),
                    'w') as _file:
                yaml.dump(odc_item, _file)

    if kwargs['verbose']:
        logger.info("Finished!")
예제 #2
0
def collection2product(collection: Collection, mapper: Stac2ODCMapper,
                       **kwargs) -> OrderedDict:
    """Function to convert a STAC Collection JSON to ODC Product YAML

    Args:
        collection (stac.collection.Collection): An Collection
        constants (dict): A dict with behavior definitions
        mapper (stac2odc.mapper.Stac2ODCMapper): An mapper to convert STAC collection to ODC Products
    See:
        See the BDC STAC catalog for more information on the collections available
        (http://brazildatacube.dpi.inpe.br/bdc-stac/0.8.0/)
    """

    # ToDo: Add validators
    return mapper.map_collection(collection, **kwargs)