def search(self): """ Search for Landsat-8 scenes """ # Convert AOI to GeoJSON aoi_file = tempdir() + '/aoi_geojson.geojson' Module('v.out.ogr', overwrite=True, input=options['map'], format='GeoJSON', output=aoi_file) # Reproject to espg 4326 aoi_file_re = tempdir() + '/aoi_reprojected.geojson' os.system("ogr2ogr -t_srs epsg:4326 " + aoi_file_re + " " + aoi_file) # Search for scenes with open(aoi_file_re) as f: aoi = json.dumps(json.load(f)) search = Search(date_from=options['date_from'], date_to=options['date_to'], satellite_name='Landsat-8', intersects=aoi, cloud_from=0, cloud_to=options['clouds']) self._scenes = search.scenes() os.remove(aoi_file)
def test_search(self): """ Perform simple query """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.dumps(json.load(f)) search = Search(datetime='2017-01-05', intersects=aoi) self.assertEqual(search.found(), 1) scenes = search.scenes() self.assertTrue(isinstance(scenes[0], Scene))
def test_geo_search(self): """ Perform simple query """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.dumps(json.load(f)) search = Search(datetime='2019-07-01', intersects=aoi) assert (search.found() == 13) items = search.items() assert (len(items) == 13) assert (isinstance(items[0], Item))
def test_geo_search(self): """ Perform simple query """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.dumps(json.load(f)) search = Search(datetime='2018-09-25', intersects=aoi) assert(search.found() == 2) items = search.items() assert(len(items) == 2) assert(isinstance(items[0], Item))
def test_geo_search(self): """ Perform simple query """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.load(f) search = Search(datetime='2020-06-07', intersects=aoi['geometry']) assert (search.found() == 12) items = search.items() assert (len(items) == 12) assert (isinstance(items[0], Item))
def test_get_ids_search(self): """ Get Items by ID through normal search """ ids = ['LC80340332018034LGN00', 'LC80340322018034LGN00'] search = Search.search(ids=ids, collection='landsat-8-l1') items = search.items() assert(search.found() == 2) assert(len(items) == 2)
def test_search_sort(self): """ Perform search with sort """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.dumps(json.load(f)) search = Search.search(datetime='2018-01-01/2018-01-15', intersects=aoi, sort=['<datetime']) items = search.items() assert(len(items) == 33)
def test_get_ids_search(self): """ Get Items by ID through normal search """ ids = ['LC81692212019263', 'LC81691102019263'] search = Search.search(ids=ids, collection='landsat-8-l1') items = search.items() assert (search.found() == 2) assert (len(items) == 2)
def get_search(self): """ Initialize and return search object """ sids = [ self.results[s]['features'][0]['properties']['id'] for s in self.results ] return Search(id=sids)
def test_get_ids_search(self): """ Get Items by ID through normal search """ ids = ['S2A_28QBH_20200611_0_L2A', 'S2A_28QCH_20200611_0_L2A'] search = Search.search(ids=ids) items = search.items() assert (search.found() == 4) assert (len(items) == 4)
def test_get_ids_search(self): """ Get Items by ID through normal search """ ids = ['LC80340332018034LGN00', 'LC80340322018034LGN00'] search = Search.search(ids=ids, collection='landsat-8-l1') items = search.items() assert (search.found() == 2) assert (len(items) == 2)
def test_search_sort(self): """ Perform search with sort """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.load(f) search = Search.search(datetime='2020-06-07', intersects=aoi['geometry'], sortby=['-properties.datetime']) items = search.items() min_found = 12 assert(len(items) >= min_found)
def test_search_sort(self): """ Perform search with sort """ with open(os.path.join(self.path, 'aoi1.geojson')) as f: aoi = json.dumps(json.load(f)) search = Search.search(datetime='2019-07-01/2019-07-07', intersects=aoi, sort=['<datetime']) items = search.items() assert (len(items) == 27)
def test_search_property_operator(self): expected = { 'query': { 'eo:cloud_cover': { 'lte': '10' }, 'collection': { 'eq': 'sentinel-2-l1c' } } } instance = Search.search(collection='sentinel-2-l1c', property=['eo:cloud_cover<=10']) actual = instance.kwargs assert actual == expected
def test_search_query_operator(self): expected = { 'collections': ['sentinel-s2-l1c'], 'query': { 'eo:cloud_cover': { 'lte': '10' }, 'data_coverage': { 'gt': '80' } } } instance = Search.search( collections=['sentinel-s2-l1c'], query=['eo:cloud_cover<=10', 'data_coverage>80']) assert instance.kwargs == expected
def get_search(self): """ Initialize and return search object """ sids = [ self.results[s]['results'][0]['scene_id'] for s in self.results ] return Search(scene_id=sids)
def test_empty_search(self): """ Perform search for 0 results """ search = Search(scene_id=['nosuchscene']) self.assertEqual(search.found(), 0)
def test_query_bad_url(self): with self.assertRaises(SatSearchError): Search.query(url=os.path.join(config.API_URL, 'collections/nosuchcollection'))
def test_get_ids_without_collection(self): with self.assertRaises(SatSearchError): search = Search.search(ids=['LC80340332018034LGN00']) items = search.items()
def test_empty_search(self): """ Perform search for 0 results """ search = Search(datetime='2001-01-01') self.assertEqual(search.found(), 0)
def test_get_items_by_id(self): """ Get Items by ID """ ids = ['LC81692212019263', 'LC81691102019263'] items = Search.items_by_id(ids, collection='landsat-8-l1') assert (len(items) == 2)
def test_empty_search(self): """ Perform search for 0 results """ search = Search(datetime='2001-01-01') self.assertEqual(search.found(), 0)
def test_get_items_by_id(self): """ Get Items by ID """ ids = ['LC80340332018034LGN00', 'LC80340322018034LGN00'] items = Search.items_by_id(ids, collection='landsat-8-l1') assert(len(items) == 2)
def get_searches(self): """ Initialize and return search object """ return [ Search(datetime=r['properties']['datetime']) for r in self.results ]
def query_satapi(aoi, clip=False, **kwargs): """ Search sat-api using sat-search """ if clip: aoi = get_coastline(aoi) search = Search(intersects=json.dumps(aoi), **kwargs) return search.scenes()
def test_get_ids_without_collection(self): with self.assertRaises(SatSearchError): search = Search.search(ids=['LC80340332018034LGN00']) items = search.items()
def test_get_items_by_id(self): """ Get Items by ID """ ids = ['LC80340332018034LGN00', 'LC80340322018034LGN00'] items = Search.items_by_id(ids, collection='landsat-8-l1') assert (len(items) == 2)
def test_query_bad_url(self): with self.assertRaises(SatSearchError): Search.query(url=os.path.join(config.API_URL, 'collections/nosuchcollection'))