示例#1
0
def stitch_geos(slclist, reverse, output_path, overwrite=False, verbose=True):
    """Combines multiple .geo files of the same date into one image"""
    if verbose:
        print("Stitching geos for %s" % slclist[0].date)
        print("reverse=", reverse)
        for g in slclist:
            print("image:", g.filename, g.start_time)

    g = slclist[0]
    new_name = "{}_{}.geo".format(g.mission, g.date.strftime("%Y%m%d"))
    new_name = os.path.join(output_path, new_name)
    if os.path.exists(new_name):
        if os.path.islink(new_name):
            print("Removing symlink %s" % new_name)
            os.remove(new_name)
        elif overwrite:  # real file
            print("Overwrite=True: Removing %s" % new_name)
            os.remove(new_name)
        else:
            print(" %s exists, not overwriting. skipping" % new_name)
            return

    # TODO: load as blocks, not all at once
    # stitched_img = combine_complex([sario.load(g.filename) for g in slclist])
    stitched_img = combine_complex([g.filename for g in slclist])

    print("Saving stitched to %s" % new_name)
    # Remove any file with same name before saving
    # This prevents symlink overwriting old files
    sario.save(new_name, stitched_img)
示例#2
0
def save(filepath, mask, downsample=0):
    # maskfile = filepath.replace(ext, '.jpg')
    # Keep old .ext so we know what type was masked
    ext = sario.get_file_ext(filepath)
    maskfile = filepath.replace(ext, ext + '.png')

    if args.downsample:
        sario.save(maskfile, utils.downsample_im(mask, args.downsample))
    else:
        sario.save(maskfile, mask)
    return True
示例#3
0
    def test_save_elevation(self):
        try:
            loaded_dem = sario.load_file(self.dem_path)
            save_path = self.dem_path.replace(".dem", "_test.dem")

            # Must copy the .dem.rsc as well
            old_dem_rsc = self.dem_path + ".rsc"
            new_dem_rsc = old_dem_rsc.replace(".dem", "_test.dem")
            shutil.copyfile(old_dem_rsc, new_dem_rsc)

            sario.save(save_path, loaded_dem)
            self.assertTrue(exists(save_path))

            reloaded_dem = sario.load_file(save_path)
            assert_array_almost_equal(reloaded_dem, loaded_dem)

        finally:
            os.remove(new_dem_rsc)
            os.remove(save_path)
示例#4
0
    def test_load_uavsar(self):
        try:
            temp_dir = tempfile.mkdtemp()
            grd1 = "brazos_14937_17090_017_170903_L090HHHH_CX_01_ML5X5.grd"
            grdfile = os.path.join(temp_dir, grd1)
            sario.save(grdfile,
                       np.array([[1, 2], [3, 4]]).astype(sario.FLOAT_32_LE))

            annfile = os.path.join(
                temp_dir, "brazos_14937_17090_017_170903_L090_CX_01_ML5X5.ann")
            with open(annfile, "w") as f:
                f.write(
                    "grd_mag.set_rows (pixels) = 2 ; ground range data lines\n"
                )
                f.write(
                    "grd_mag.set_cols (pixels) = 2 ; ground range data samples\n"
                )

            emptygrd = sario.load(grdfile, verbose=True)
        finally:
            shutil.rmtree(temp_dir)