def test_add_metadata_error(self): d_start = date(2015, 6, 24) d_end = date(2016, 6, 24) bounding_box = (-115.927734375, 34.52466147177172, -78.31054687499999, 44.84029065139799) landsat_filters = LandsatQueryFilters() landsat_filters.data_type.set_value("L1T") landsat_filters.acquired.set_range(d_start, True, d_end, True) landsat_filters.aoi.set_bounds(*bounding_box) rows = self.metadata_service.search(SpacecraftID.LANDSAT_8, limit=2, data_filters=landsat_filters) rows = list(rows) metadata_1 = rows[0] metadata_2 = rows[1] bands = [Band.RED, Band.BLUE, Band.GREEN] band_map = BandMap(SpacecraftID.LANDSAT_8) raster_metadata = RasterMetadata() storage = Storage() storage.mount_sub_folder(metadata_1) storage.mount_sub_folder(metadata_2) second = False for band in bands: band_number = band_map.get_number(band) if second: self.assertRaises(Exception, lambda: raster_metadata.add_metadata(band_number, metadata_2)) raster_metadata.add_metadata(band_number, metadata_1) second = True
def test_landsat_5_exceptions(self): band_map_2 = BandMap(SpacecraftID.LANDSAT_7) self.assertEqual(band_map_2.get_number(Band.PANCHROMATIC), 8) self.assertEqual(band_map_2.get_band_enum(8), Band.PANCHROMATIC) self.assertEqual(band_map_2.get_resolution(Band.PANCHROMATIC), 15.0) band_map = BandMap(SpacecraftID.LANDSAT_5) self.assertRaises(KeyError, lambda: band_map.get_number(Band.CIRRUS)) self.assertRaises(KeyError, lambda: band_map.get_number(Band.PANCHROMATIC)) self.assertRaises(KeyError, lambda: band_map.get_band_enum(8))
def test_landsat_5(self): band_map = BandMap(SpacecraftID.LANDSAT_5) self.assertEqual(band_map.get_number(Band.BLUE), 1) self.assertEqual(band_map.get_number(Band.SWIR2), 7) self.assertEqual(band_map.get_number(Band.THERMAL), 6) self.assertEqual(band_map.get_band_enum(1), Band.BLUE) self.assertEqual(band_map.get_band_enum(7), Band.SWIR2) self.assertEqual(band_map.get_band_enum(6), Band.THERMAL) for idx, val in enumerate( [Band.BLUE, Band.GREEN, Band.RED, Band.NIR, Band.SWIR1]): self.assertEqual(band_map.get_band_enum(idx + 1), val) self.assertEqual(band_map.get_number(val), idx + 1) self.assertEqual(band_map.get_resolution(val), 30.0)
def test_bounds(self): metadata_service = MetadataService() landsat_filters = LandsatQueryFilters() landsat_filters.scene_id.set_value("LC80330342017072LGN00") landsat_filters.collection_number.set_value("PRE") rows = metadata_service.search( SpacecraftID.LANDSAT_8, data_filters=landsat_filters) rows = list(rows) self.assertEqual(len(rows), 1) metadata = rows[0] bands = [Band.RED, Band.BLUE, Band.GREEN] band_map = BandMap(SpacecraftID.LANDSAT_8) raster_metadata = RasterMetadata() storage = Storage() storage.mount_sub_folder(metadata) for band in bands: band_number = band_map.get_number(band) raster_metadata.add_metadata(band_number, metadata) boundary = raster_metadata.bounds self.assertIsNotNone(boundary) r = requests.get("https://raw.githubusercontent.com/johan/world.geo.json/master/countries/USA/NM/Taos.geo.json") taos_geom = r.json() taos_shape = shapely.geometry.shape(taos_geom['features'][0]['geometry']) clipped_raster = raster_metadata.calculate_clipped(taos_shape.bounds, pyproj.Proj(init='epsg:4326')) self.assertIsNotNone(clipped_raster.bounds) big_box = shapely.geometry.box(*boundary) small_box = shapely.geometry.box(*clipped_raster.bounds) self.assertTrue(big_box.contains(small_box))
def test_landsat_8_exceptions(self): band_map = BandMap(SpacecraftID.LANDSAT_8) self.assertRaises(KeyError, lambda: band_map.get_number(Band.THERMAL)) self.assertRaises(KeyError, lambda: band_map.get_band_enum(12))
def test_landsat_8(self): band_map = BandMap(SpacecraftID.LANDSAT_8) self.assertEqual(band_map.get_number(Band.ULTRA_BLUE), 1) self.assertEqual(band_map.get_number(Band.BLUE), 2) self.assertEqual(band_map.get_number(Band.SWIR1), 6) self.assertEqual(band_map.get_band_enum(2), Band.BLUE) self.assertEqual(band_map.get_band_enum(6), Band.SWIR1) self.assertEqual(band_map.get_number(Band.SWIR2), 7) self.assertEqual(band_map.get_band_enum(7), Band.SWIR2) for idx, val in enumerate( [Band.BLUE, Band.GREEN, Band.RED, Band.NIR, Band.SWIR1]): self.assertEqual(band_map.get_band_enum(idx + 2), val) self.assertEqual(band_map.get_number(val), idx + 2) self.assertEqual(band_map.get_number(Band.CIRRUS), 9) self.assertEqual(band_map.get_number(Band.TIRS1), 10) self.assertEqual(band_map.get_number(Band.TIRS2), 11) self.assertEqual(band_map.get_resolution(Band.PANCHROMATIC), 15.0) self.assertEqual(band_map.get_band_enum(9), Band.CIRRUS) self.assertEqual(band_map.get_band_enum(10), Band.TIRS1) self.assertEqual(band_map.get_band_enum(11), Band.TIRS2)
def test_landsat_7_exceptions(self): band_map = BandMap(SpacecraftID.LANDSAT_7) self.assertRaises(KeyError, lambda: band_map.get_number(Band.CIRRUS)) self.assertRaises(KeyError, lambda: band_map.get_number(Band.TIRS1)) self.assertRaises(KeyError, lambda: band_map.get_band_enum(9))