def coreg_wrapper(argsin):

    ref_vrt, in_dem, fn_excl_mask, fn_incl_mask, strip_out_dir = argsin

    print('Coregistering strip: ' + in_dem)

    if not os.path.exists(strip_out_dir):

        try:
            # _, outslave, _, stats = dem_coregistration(ref_vrt, in_dem, glaciermask=fn_excl_mask, landmask=fn_incl_mask,
            #                                            outdir=strip_out_dir, inmem=True)
            # rmse = stats[3]
            # clean_coreg_dir(strip_out_dir, '.')
            # if rmse < 10:
            #     outslave.write(os.path.basename(strip_out_dir) + '_adj.tif', out_folder=strip_out_dir)
            _, _, shift_params, stats = dem_coregistration(ref_vrt, in_dem, glaciermask=fn_excl_mask, landmask=fn_incl_mask,
                                                       outdir=strip_out_dir, inmem=True)
            rmse = stats[3]
            clean_coreg_dir(strip_out_dir, '.')
            orig_slv = GeoImg(in_dem)
            if rmse < 10:
                orig_slv.shift(shift_params[0], shift_params[1])
                orig_slv.img = orig_slv.img + shift_params[2]
                orig_slv.write(os.path.basename(strip_out_dir)+ '_adj.tif', out_folder=strip_out_dir)
                # outslave.write(os.path.basename(strip_out_dir) + '_adj.tif', out_folder=strip_out_dir)
        except Exception:
            clean_coreg_dir(strip_out_dir, '.')

    else:
        print('Output dir already exists, skipping...')
def main():
    np.seterr(all='ignore')
    parser = _argparser()
    args = parser.parse_args()

    if args.outfilename is None:
        args.outfilename = args.dem.rsplit('.tif', 1)[0] + '_XAJ.tif'
    # read in DEM to apply corrections to
    dem = GeoImg(args.dem)

    # apply optional correlation mask
    if args.corr_mask is not None:
        corr = GeoImg(args.corr_mask)
        dem.img[corr.img < args.threshold] = np.nan

    ang_mapN = GeoImg('TrackAngleMap_3N.tif')
    ang_mapB = GeoImg('TrackAngleMap_3B.tif')
    ang_mapNB = ang_mapN.copy(
        new_raster=np.array(np.divide(ang_mapN.img + ang_mapB.img, 2)))

    # first apply the cross-track correction
    myang = np.deg2rad(ang_mapNB.img)
    xxr, _ = mt.get_xy_rot(dem, myang)
    pcoef = read_params_file(args.cross_track_params)
    cross_correction = mt.fitfun_polynomial(xxr, pcoef)
    dem.img = dem.img + cross_correction

    # next, apply *either* the full soluton, or just the low-frequency solution
    xxn_mat, xxb_mat = mt.get_atrack_coord(dem, ang_mapN, ang_mapB)
    if not args.low_freq:
        scoef = read_params_file(args.along_track_full)
    else:
        scoef = read_params_file(args.along_track_low)
    sinmod = mt.fitfun_sumofsin_2angle(xxn_mat, xxb_mat, scoef)
    along_correction = np.reshape(sinmod, dem.img.shape)
    dem.img = dem.img + along_correction
    dem.write(args.outfilename, out_folder=args.input_dir)
Ejemplo n.º 3
0
def reshape_geoimg(fname, xr, yr, rescale=True):
    ds = gdal.Warp('', fname, xRes=xr, yRes=yr, format='VRT', resampleAlg=gdal.GRA_Lanczos)
    resamp = GeoImg(ds)
    if rescale:
        resamp.img = (resamp.img / 256).astype(np.uint8)
    return resamp