def test_example(self): self.assertEqual("0100101111101110", compress(example_image))
def test_do(self): img = numpy.array([[0]]) self.assertEqual("10", compress(img)) img = numpy.array([[1]]) self.assertEqual("11", compress(img))
def test(self): self.assertEqual(main.compress([]), []) self.assertEqual(main.compress([1, 2, 3, 1, 4, 5]), [1, 2, 3, 1, 4, 5]) self.assertEqual( main.compress([1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5]), [1, 2, 3, 1, 4, 5])
def main(InputFolder, OutputFolder, DEM, _6S, pansharpen, pyramid, pid, cache, InputFile_list): if InputFolder: files = glob.glob(join(InputFolder, "GF*")) elif InputFile_list: files = InputFile_list else: raise ValueError("Please specify --InputFolder or --InputFile_list") os.environ["GDAL_CACHEMAX"] = cache # Batch preprocess begins for i, file in enumerate(files): print("进程%d: 处理第%d景数据中,共%d景数据" % (pid, i + 1, len(files))) try: # Extract archive if ".tar.gz" in file: # Extract to current directory datapath = file.replace(".tar.gz", "") try: untar(file, datapath) except: continue else: datapath = file # Get spectral rasters and pancromatic rasters M, P = get_rasters_name(datapath) # RPC Orthorectification for spectral rasters m_out_list = list() for m in M: try: m_in = join(datapath, m) m_out = join(OutputFolder, m) rpc_ortho(m_in, DEM, m_out) temp = correction(m_out).radiometric() # Compress and delete temp file compress(temp, m_out) m_out_list.append(m_out) except: continue # Mosaic GF6_WFV-1,2,3 if "GF6_WFV" in M[0]: m = join(OutputFolder, M[0]) mosaic_file = re.sub("-[0-9].tiff", "-mosaic.tiff", m) vrt = re.sub("-[0-9].tiff", ".vrt", m) txt = re.sub("-[0-9].tiff", ".txt", m) [save_txt(txt, m_out) for m_out in m_out_list] mosaic(mosaic_file, txt, vrt) [os.remove(m_out) for m_out in m_out_list] # 6S atmospheric correction if _6S: if "GF6_WFV" in M[0]: metadata = re.sub("-[0-9].tiff", ".xml", join(datapath, M[0])) temp = correction(mosaic_file, metadata).atmospheric() compress(temp, mosaic_file) else: for m_out in m_out_list: metadata = re.sub( ".tiff", ".xml", join(datapath, os.path.basename(m_out))) temp = correction(m_out, metadata).atmospheric() compress(temp, m_out) # Pansharpening if pansharpen and len(P) > 0: fusion_list = list() for p in P: p_in = join(datapath, p) p_out = join(OutputFolder, p) rpc_ortho(p_in, DEM, p_out) temp = correction(p_out).radiometric() compress(temp, p_out) fusion = p_out.replace("PAN", "FUS") fusion_list.append(fusion) # Trying to find corresponding spectral dataset m = glob.glob( p_out.rsplit("PAN", 1)[0] + "M*" + p_out.rsplit("PAN", 1)[1])[0] pansharpening(m, p_out, fusion) os.remove(m) os.remove(p_out) # Build pyramid, we only build for the final raster if pyramid: if "GF6_WFV" in M[0]: build_pyramid(mosaic_file) elif pansharpen and len(P) > 0: [build_pyramid(fusion) for fusion in fusion_list] else: [build_pyramid(m_out) for m_out in m_out_list] except: continue
def test_compress(self): self.assertEqual(main.compress("test"), 81.25)