Beispiel #1
0
 def test_search_dltile(self):
     tile = geocontext.DLTile.from_key('64:0:1000.0:15:-2:70')
     sc, ctx = search(tile, products="landsat:LC08:PRE:TOAR", limit=4)
     self.assertGreater(len(sc), 0)
     self.assertLessEqual(len(sc),
                          4)  # test client only has 2 scenes available
     self.assertEqual(ctx, tile)
Beispiel #2
0
 def test_search_dltile(self):
     tile = geocontext.DLTile({
         "geometry": {
             "coordinates": [[
                 [-94.50970627780103, 40.460817879515986],
                 [-93.75494640538922, 40.468212507270195],
                 [-93.76149667591069, 41.04471363474632],
                 [-94.5228005945451, 41.03716803374444],
                 [-94.50970627780103, 40.460817879515986],
             ]],
             "type":
             "Polygon",
         },
         "properties": {
             "cs_code": "EPSG:32615",
             "key": "64:0:1000.0:15:-2:70",
             "outputBounds": [372000.0, 4480000.0, 436000.0, 4544000.0],
             "pad": 0,
             "resolution": 1000.0,
             "ti": -2,
             "tilesize": 64,
             "tj": 70,
             "zone": 15,
         },
     })
     sc, ctx = search(tile, products="landsat:LC08:PRE:TOAR", limit=4)
     assert len(sc) > 0
     assert len(sc) <= 4  # test client only has 2 scenes available
     assert ctx == tile
 def test_search_dltile(self):
     tile = geocontext.DLTile({
         'geometry': {
             'coordinates': [[[-94.50970627780103, 40.460817879515986],
                              [-93.75494640538922, 40.468212507270195],
                              [-93.76149667591069, 41.04471363474632],
                              [-94.5228005945451, 41.03716803374444],
                              [-94.50970627780103, 40.460817879515986]]],
             'type':
             'Polygon'
         },
         'properties': {
             'cs_code': 'EPSG:32615',
             'key': '64:0:1000.0:15:-2:70',
             'outputBounds': [372000.0, 4480000.0, 436000.0, 4544000.0],
             'pad': 0,
             'resolution': 1000.0,
             'ti': -2,
             'tilesize': 64,
             'tj': 70,
             'zone': 15
         },
     })
     sc, ctx = search(tile, products="landsat:LC08:PRE:TOAR", limit=4)
     self.assertGreater(len(sc), 0)
     self.assertLessEqual(len(sc),
                          4)  # test client only has 2 scenes available
     self.assertEqual(ctx, tile)
Beispiel #4
0
    def test_search_AOI(self):
        aoi = geocontext.AOI(self.geom, resolution=5)
        sc, ctx = search(aoi, products="landsat:LC08:PRE:TOAR", limit=4)
        assert len(sc) > 0
        assert len(sc) <= 4  # test client only has 2 scenes available

        assert ctx.resolution == 5
        assert ctx.crs == "EPSG:32615"
Beispiel #5
0
    def test_search_AOI(self):
        aoi = geocontext.AOI(self.geom, resolution=5)
        sc, ctx = search(aoi, products="landsat:LC08:PRE:TOAR", limit=4)
        self.assertGreater(len(sc), 0)
        self.assertLessEqual(len(sc), 4)  # test client only has 2 scenes available

        self.assertEqual(ctx.resolution, 5)
        self.assertEqual(ctx.crs, "EPSG:32615")
Beispiel #6
0
    def test_search_AOI_with_shape(self):
        aoi = geocontext.AOI(self.geom, shape=(100, 100))
        sc, ctx = search(aoi, products="landsat:LC08:PRE:TOAR", limit=4)
        assert len(sc) > 0
        assert len(sc) <= 4  # test client only has 2 scenes available

        assert ctx.resolution is None
        assert ctx.shape == aoi.shape
        assert ctx.crs == "EPSG:32615"
Beispiel #7
0
    def test_search_geom(self):
        sc, ctx = search(self.geom, products="landsat:LC08:PRE:TOAR", limit=4)
        assert len(sc) > 0
        assert len(sc) <= 4  # test client only has 2 scenes available

        assert isinstance(ctx, geocontext.AOI)
        assert ctx.__geo_interface__ == self.geom
        assert ctx.resolution == 15
        assert ctx.crs == "EPSG:32615"

        for scene in sc:
            # allow for changes in publicly available data
            assert abs(len(scene.properties.bands) - 24) < 4
            assert "derived:ndvi" in scene.properties.bands
Beispiel #8
0
    def test_search_geom(self):
        sc, ctx = search(self.geom, products="landsat:LC08:PRE:TOAR", limit=4)
        self.assertGreater(len(sc), 0)
        self.assertLessEqual(len(sc), 4)  # test client only has 2 scenes available

        self.assertIsInstance(ctx, geocontext.AOI)
        self.assertEqual(ctx.__geo_interface__, self.geom)
        self.assertEqual(ctx.resolution, 15)
        self.assertEqual(ctx.crs, "EPSG:32615")

        for scene in sc:
            # allow for changes in publicly available data
            self.assertAlmostEqual(len(scene.properties.bands), 24, delta=4)
            self.assertIn("derived:ndvi", scene.properties.bands)
Beispiel #9
0
    def test_search_datetime(self):
        start_datetime = datetime.datetime(2016, 7, 6)
        end_datetime = datetime.datetime(2016, 7, 15)
        sc, ctx = search(self.geom,
                         products="landsat:LC08:PRE:TOAR",
                         start_datetime=start_datetime,
                         end_datetime=end_datetime,
                         limit=4)

        self.assertGreater(len(sc), 0)
        self.assertLessEqual(len(sc),
                             4)  # test client only has 2 scenes available

        for scene in sc:
            self.assertGreaterEqual(scene.properties['date'], start_datetime)
            self.assertLessEqual(scene.properties['date'], end_datetime)
Beispiel #10
0
    def test_search_datetime(self):
        start_datetime = datetime.datetime(2016, 7, 6)
        end_datetime = datetime.datetime(2016, 7, 15)
        sc, ctx = search(
            self.geom,
            products="landsat:LC08:PRE:TOAR",
            start_datetime=start_datetime,
            end_datetime=end_datetime,
            limit=4,
        )

        assert len(sc) > 0
        assert len(sc) <= 4  # test client only has 2 scenes available

        for scene in sc:
            assert scene.properties["date"] >= start_datetime
            assert scene.properties["date"] <= end_datetime
Beispiel #11
0
def mosaic(
        aoi,
        year=None,
        products=PRODUCTS,
        bands=INPUT_BANDS,
        alpha_band=ALPHA_BAND,
        start=None,
        end=None,
        dest=None,
        dry_run=False,
        return_geocontext=False):
    if _is_str(aoi):
        aoi=DLTile.from_key(aoi)
    start=start or f'{year}-05-01'
    end=end or f'{year}-09-01'
    if not alpha_band:
        bands=bands[:4]
    sc,_=search(aoi,products=products,start_datetime=start,end_datetime=end)
    if sc:
        if dest:
            if dry_run:
                out=f'{dest}: {len(sc)}'
            else:
                out=sc.download_mosaic(
                    bands,
                    aoi,
                    dest=dest)
        else:
            if dry_run:
                out=len(sc)
            else:
                out=sc.mosaic(bands,aoi,mask_nodata=False,raster_info=False)
    else:
        out=False
    if return_geocontext:
        return out, aoi
    else:
        return out
Beispiel #12
0
 def test_search_no_products(self):
     sc, ctx = search(self.geom, limit=4)
     assert len(sc) > 0
     assert len(sc) <= 4  # test client only has 2 scenes available
Beispiel #13
0
 def test_search_no_products(self):
     sc, ctx = search(self.geom, limit=4)
     self.assertGreater(len(sc), 0)
     self.assertLessEqual(len(sc), 4)  # test client only has 2 scenes available
Beispiel #14
0
 def test_search_geom_no_shapely(self):
     with self.assertRaisesRegexp(NotImplementedError, "pip install"):
         sc, ctx = search(self.geom,
                          products="landsat:LC08:PRE:TOAR",
                          limit=4)