Пример #1
0
 def test_substitute(self):
     """ Test string substitution with item fields """
     item = Item.open(self.filename)
     st = item.substitute('${collection}/${date}')
     assert(st == 'landsat-8-l1/2018-10-12')
     st = item.substitute('nosub')
     assert(st == 'nosub')
Пример #2
0
 def test_download(self):
     """ Retrieve a data file """
     item = Item.open(self.filename)
     fname = item.download(key='MTL', path=self.path)
     assert(os.path.exists(fname))
     fname = item.download(key='MTL', path=self.path)
     assert(os.path.exists(fname))
Пример #3
0
 def test_load_item(self):
     input1 = self.infile
     input2 = Item.open(self.infile)
     input3 = input2.data
     self.assertTrue(
         type(StacItem.load_item(input1)) == type(StacItem.load_item(
             input2)) == type(StacItem.load_item(input3)) == Item)
Пример #4
0
 def test_assets(self):
     """ Get assets for download """
     item = Item.open(self.filename)
     href = item.data['assets']['B1']['href']
     assert(item.assets['B1']['href'] == href)
     assert(item.asset('B1')['href'] == href)
     assert(item.asset('coastal')['href'] == href)
Пример #5
0
 def test_download_assets(self):
     """ Retrieve multiple data files """
     item = Item.open(self.filename)
     fnames = item.download_assets(keys=['MTL', 'ANG'],
                                   filename_template=self.filename_template)
     for f in fnames:
         assert (os.path.exists(f))
Пример #6
0
 def test_get_path(self):
     """ Test string templating with item fields """
     item = Item.open(self.filename)
     st = item.get_path('${collection}/${date}')
     assert (st == 'landsat-8-l1/2020-06-11')
     st = item.get_path('nosub')
     assert (st == 'nosub')
Пример #7
0
 def test_open_with_collection(self):
     item = Item.open(self.filename)
     assert (item.collection().id == 'landsat-8-l1')
     sum = item.collection().summaries
     assert (len(sum) == 4)
     assert (len(sum['platform']) == 1)
     assert ('landsat-8' in sum['platform'])
Пример #8
0
 def test_publish(self):
     path = os.path.join(self.path, 'test_publish')
     shutil.copytree(os.path.join(testpath, 'catalog'), path)
     cat = Catalog.open(os.path.join(path, 'catalog.json'))
     cat.publish('https://my.cat')
     item = Item.open(os.path.join(path, 'eo/landsat-8-l1/item.json'))
     assert (item.links('self')[0] ==
             'https://my.cat/eo/landsat-8-l1/item.json')
Пример #9
0
 def test_open(self):
     """ Initialize an item """
     item = Item.open(self.filename)
     dt, tm = item.properties['datetime'].split('T')
     assert(str(item.date) == dt)
     assert(item.id == item.data['id'])
     assert(item.geometry == item.data['geometry'])
     assert(str(item) == item.data['id'])
     assert(len(item.bbox) == 4)
Пример #10
0
 def load_item(item):
     if type(item) == Item:
         return item
     elif type(item) == str:
         if item.startswith('http'):
             return Item.open(item)
     elif type(item) == dict:
         return Item(item)
     else:
         raise TypeError("Invalid input encountered.")
Пример #11
0
 def test_add_item(self):
     cat = Catalog.create(root='http://my.cat').save(
         os.path.join(self.path, 'catalog.json'))
     col = Collection.open(
         os.path.join(testpath, 'catalog/eo/landsat-8-l1/catalog.json'))
     cat.add_catalog(col)
     item = Item.open(
         os.path.join(testpath, 'catalog/eo/landsat-8-l1/item.json'))
     col.add_item(item)
     assert (item.parent().id == 'landsat-8-l1')
Пример #12
0
 def test_add_item_with_subcatalogs(self):
     cat = Catalog.create(root='http://my.cat').save(
         os.path.join(self.path, 'test_subcatalogs.json'))
     col = Collection.open(
         os.path.join(testpath, 'catalog/eo/landsat-8-l1/catalog.json'))
     cat.add_catalog(col)
     item = Item.open(
         os.path.join(testpath, 'catalog/eo/landsat-8-l1/item.json'))
     col.add_item(item, path='${landsat:path}/${landsat:row}/${date}')
     assert (item.root().id == cat.id)
     assert (item.collection().id == col.id)
     # test code using existing catalogs
     col.add_item(item, '${landsat:path}/${landsat:row}/${date}')
     assert (item.root().id == cat.id)
Пример #13
0
 def _test_download_paths(self):
     """ Testing of download paths and filenames """
     item = Item.open(self.filename)
     datadir = config.DATADIR
     filename = config.FILENAME
     config.DATADIR = os.path.join(testpath, '${date}')
     config.FILENAME = '${date}_${id}'
     fname = scene.download('MTL')
     _fname = os.path.join(testpath, '2017-01-01/2017-01-01_testscene_MTL.txt')
     assert(fname == _fname)
     assert(os.path.exists(fname))
     config.DATADIR = datadir
     config.FILENAME = filename
     shutil.rmtree(os.path.join(testpath, '2017-01-01'))
     assert(os.path.exists(fname) == False)
Пример #14
0
# -*- coding: utf-8 -*-
"""
Created on Wed Oct  9 10:28:54 2019

@author: Main
"""

from satstac import Catalog, Collection, Item

cat = Catalog.open('https://landsat-stac.s3.amazonaws.com/catalog.json')
print(cat, cat.filename)

col = Collection.open('https://landsat-stac.s3.amazonaws.com/landsat-8-l1/catalog.json')
print(col, col.filename)

item = Item.open('https://landsat-stac.s3.amazonaws.com/landsat-8-l1/111/111/2018-11-30/LC81111112018334LGN00.json')
print(item, item.filename, sep='\n')
Пример #15
0
 def test_no_asset(self):
     item = Item.open(self.filename)
     assert(item.asset('no-such-asset') == None)
Пример #16
0
 def test_class_properties(self):
     """ Test the property functions of the Item class """
     item = Item.open(self.filename)
     l = os.path.join(os.path.dirname(item.filename), item.data['links'][0]['href'])
     assert(os.path.abspath(item.links()[0]) == os.path.abspath(l))
Пример #17
0
 def test_open_with_collection(self):
     item = Item.open(self.filename)
     assert(item.collection().id == 'landsat-8-l1')
     assert(len(item['eo:bands']) == 11)
     assert(item['eo:off_nadir'] == 0)
Пример #18
0
 def test_download_thumbnail(self):
     """ Get thumbnail for item """
     item = Item.open(self.filename)
     fname = item.download(key='thumbnail', path=self.path)
     assert(os.path.exists(fname))
Пример #19
0
 def test_download_nonexist(self):
     """ Test downloading of non-existent file """
     item = Item.open(self.filename)
     fname = item.download(key='fake_asset', path=self.path)
     assert(fname is None)
Пример #20
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)
Пример #21
0
 def ingest_item(self, url):
     AssetLoader(Item.open(url), self.config.API_ENDPOINT).ingest()