def test_sentinel_scene_interpreter(self): expected = 'tiles/56/W/NV/2016/5/30/0' scene = 'S2A_tile_20160530_56WNV_0' self.assertEqual(Sentinel2.scene_interpreter(scene), expected) scene = 'S2A_OPER_MSI_L1C_TL_SGS__20160530T030406_A004890_T56WNV_N01.01' self.assertEqual(Sentinel2.scene_interpreter(scene), expected)
def test_parse_amazon_s3_path(self): self.assertTupleEqual( ('56', 'W', 'NV', datetime.date(2016, 5, 30), '0'), Sentinel2.parse_amazon_s3_tile_path('tiles/56/W/NV/2016/5/30/0')) self.assertTupleEqual( ('36', 'U', 'YV', datetime.date(2015, 8, 26), '0'), Sentinel2.parse_amazon_s3_tile_path('tiles/36/U/YV/2015/8/26/0')) with self.assertRaises(ValueError): Sentinel2.parse_amazon_s3_tile_path('56/W/NV/2016/5/30/0')
def test_scene_interpreter_success(self): scene = 'S2A_OPER_MSI_L1C_TL_SGS__20160325T150955_A003951_T34RCS_N02.01' output = Sentinel2.scene_interpreter(scene) expect = 'tiles/34/R/CS/2016/3/25/0' self.assertEqual(output, expect) scene = 'S2A_OPER_MSI_L1C_TL_SGS__20160325T150955_A003951_T34RCS_N02.01' output = Sentinel2.scene_interpreter(scene) expect = 'tiles/34/R/CS/2016/3/25/0' self.assertEqual(output, expect) scene = 'S2A_tile_20160526_1VCH_0' output = Sentinel2.scene_interpreter(scene) expect = 'tiles/1/V/CH/2016/5/26/0' self.assertEqual(output, expect)
def test_download_with_band_name(self, fake_fetch): """ Test downloading from S3 for a given sceneID with band names """ fake_fetch.side_effect = self._fake_fetch l = Sentinel2(download_dir=self.temp_folder) results = l.download(self.scenes, ['red', 'green', 'blue']) self.assertTrue(isinstance(results, Scenes)) self.assertEqual(self.scenes, results.scenes) self.assertEqual(len(results[self.scenes[0]].files), 3)
def test_download_path(self, fake_fetch): """ Test downloading from S3 for a given sceneID """ fake_fetch.side_effect = self._fake_fetch l = Sentinel2(download_dir=self.temp_folder) results = l.download(self.paths, [4, 3, 2]) self.assertTrue(isinstance(results, Scenes)) total = sum([len(s.files) for s in results]) self.assertEqual(total, len(self.paths) * 3)
def test_download_scene_name(self, fake_fetch): """ Test downloading from S3 for a given sceneID """ fake_fetch.return_value = 'file.tif' l = Sentinel2(download_dir=self.temp_folder) results = l.s3(self.scenes, [4, 3, 2]) self.assertTrue(isinstance(results, Scenes)) total = sum([len(s.files) for s in results]) self.assertEqual(total, len(self.scenes) * 3)
def test_override_relative_path(self, fake_fetch): fake_fetch.side_effect = self._fake_fetch l = Sentinel2( download_dir=self.temp_folder, relative_product_path_builder=self._custom_relative_path_builder) results = l.download(self.paths[1:] + self.scenes[1:], [4, 3, 2]) self.assertTrue(isinstance(results, Scenes)) for scene in results: for f in scene.files: self.assertTrue( f.startswith( os.path.join(self.temp_folder, 'test/37/T/BG/2016-03-20/0/')))
def test_scene_interpreter_fail(self): with self.assertRaises(IncorrectSentine2SceneId): scene = 'S2A_OPER_MSI_L1C_TL_SGS__20160325T150955_A003951_T34RCS_N02.what' Sentinel2.scene_interpreter(scene)
def test_amazon_s3_url_sentinel2(self): scene = 'S2A_OPER_MSI_L1C_TL_SGS__20160325T150955_A003951_T34RCS_N02.01' path = Sentinel2.scene_interpreter(scene) string = Sentinel2.amazon_s3_url(path, 11) expect = 'tiles/34/R/CS/2016/3/25/0/B11.jp2' assert expect in string