Пример #1
0
 def toSTAC(self, **kwargs) -> Collection:
     root_collection = Collection.create(
         id=self.collectionId,
         root='https://hpda.{self.collectionId}',
         **kwargs)
     collection_root_path = os.path.join(self.collectionDir, "root.json")
     root_collection.save(collection_root_path)
     for agg in self.aggs.values():
         sub_collection = agg.toSTAC(self.collectionDir)
         root_collection.add_collection(sub_collection)
         for fileRec in agg.fileRecs:
             item: Item = fileRec.toSTAC(self.collectionDir)
             sub_collection.add_item(item)
             print(f"Saving item to {item.filename}")
             item.save(item.filename)
     return root_collection
Пример #2
0
def main(items=None, fetch=None, save=None, **kwargs):
    """ Main function for performing a search """
    _save = save if items is None else None
    items = satsearch(items, save=_save, **kwargs)
    # if not downloading nothing more to do
    if fetch is None:
        return

    # check that there is a valid geometry for clipping
    feature = items._search.get('parameters', {}).get('intersects', None)
    if feature is None:
        raise Exception('No geometry provided')

    derived_items = []
    # for each date, combine scenes
    for date in items.dates():
        print('Processing files for %s' % date)
        _items = [s for s in items if s.date == date]
        # TODO - split out by user specified metadata (e.g., platform, collection)
        item = satfetch(_items, feature['geometry'], fetch)
        derived_items.append(item)

    # this needs update to sat-stac to support adding metadata to Items
    # see https://github.com/sat-utils/sat-stac/issues/39
    #props = {
    #    'software': 'sat-fetch v%s' % __version__
    #}

    col = Collection.create()
    col._data['id'] = 'sat-fetch'
    col._data['description'] = 'Fetch items created by sat-fetch'
    col._data['links'].append({
        'rel': 'about',
        'href': 'https://github.com/sat-utils/sat-fetch'
    })
    derived_items = ItemCollection(derived_items, collections=[col])
    if save is not None:
        derived_items.save(save)
    return derived_items
Пример #3
0
 def test_add_item_without_saving(self):
     col = Collection.create()
     item = Item.open(
         os.path.join(testpath, 'catalog/eo/landsat-8-l1/item.json'))
     with self.assertRaises(STACError):
         col.add_item(item)