contrib/PyCuAmpcor/examples/cuDenseOffsets.py
def prepareGeometry(full_dir, out_dir, x_start, y_start, x_step, y_step, x_win_num, y_win_num,
                    fbases=['hgt','lat','lon','los','shadowMask','waterMask']):
    """Generate multilooked geometry datasets in the same grid as the estimated offset field
    from the full resolution geometry datasets.
    Parameters: full_dir    - str, path of input  geometry directory in full resolution
                out_dir     - str, path of output geometry directory
                x/y_start   - int, starting column/row number
                x/y_step    - int, output pixel step in column/row direction
                x/y_win_num - int, number of columns/rows
    """
    full_dir = os.path.abspath(full_dir)
    out_dir = os.path.abspath(out_dir)

    # grab the file extension for full resolution file
    full_exts = ['.rdr.full','.rdr'] if full_dir != out_dir else ['.rdr.full']
    full_exts = [e for e in full_exts if os.path.isfile(os.path.join(full_dir, '{f}{e}'.format(f=fbases[0], e=e)))]
    if len(full_exts) == 0:
        raise ValueError('No full resolution {}.rdr* file found in: {}'.format(fbases[0], full_dir))
    full_ext = full_exts[0]

    print('-'*50)
    print('generate the corresponding multi-looked geometry datasets using gdal ...')
    # input files
    in_files = [os.path.join(full_dir, '{f}{e}'.format(f=f, e=full_ext)) for f in fbases]
    in_files = [i for i in in_files if os.path.isfile(i)]
    fbases = [os.path.basename(i).split('.')[0] for i in in_files]

    # output files
    out_files = [os.path.join(out_dir, '{}.rdr'.format(i)) for i in fbases]
    os.makedirs(out_dir, exist_ok=True)

    for i in range(len(in_files)):
        in_file = in_files[i]
        out_file = out_files[i]

        # input file size
        ds = gdal.Open(in_file, gdal.GA_ReadOnly)
        in_wid = ds.RasterXSize
        in_len = ds.RasterYSize

        # starting column/row and column/row number
        src_win = [x_start, y_start, x_win_num * x_step, y_win_num * y_step]
        print('read {} from file: {}'.format(src_win, in_file))

        # write binary data file
        print('write file: {}'.format(out_file))
        opts = gdal.TranslateOptions(format='ENVI',
                                     width=x_win_num,
                                     height=y_win_num,
                                     srcWin=src_win,
                                     noData=0)
        gdal.Translate(out_file, ds, options=opts)
        ds = None

        # write VRT file
        print('write file: {}'.format(out_file+'.vrt'))
        ds = gdal.Open(out_file, gdal.GA_ReadOnly)
        gdal.Translate(out_file+'.vrt', ds, options=gdal.TranslateOptions(format='VRT'))
        ds = None

    return
Generate multilooked geometry datasets in the same grid as the estimated offset field
    from the full resolution geometry datasets.
    Parameters: full_dir    - str, path of input  geometry directory in full resolution
                out_dir     - str, path of output geometry directory
                x/y_start   - int, starting column/row number
                x/y_step    - int, output pixel step in column/row direction
                x/y_win_num - int, number of columns/rows
    
Generate multilooked geometry datasets in the same grid as the estimated offset field
from the full resolution geometry datasets.
Generate multilooked geometry datasets in the same grid as the estimated offset field from the full resolution geometry datasets .
def prepareGeometry(full_dir, out_dir, x_start, y_start, x_step, y_step, x_win_num, y_win_num,
                    fbases=['hgt','lat','lon','los','shadowMask','waterMask']):
    full_dir = os.path.abspath(full_dir)
    out_dir = os.path.abspath(out_dir)
    full_exts = ['.rdr.full','.rdr'] if full_dir != out_dir else ['.rdr.full']
    full_exts = [e for e in full_exts if os.path.isfile(os.path.join(full_dir, '{f}{e}'.format(f=fbases[0], e=e)))]
    if len(full_exts) == 0:
        raise ValueError('No full resolution {}.rdr* file found in: {}'.format(fbases[0], full_dir))
    full_ext = full_exts[0]
    print('-'*50)
    print('generate the corresponding multi-looked geometry datasets using gdal ...')
    in_files = [os.path.join(full_dir, '{f}{e}'.format(f=f, e=full_ext)) for f in fbases]
    in_files = [i for i in in_files if os.path.isfile(i)]
    fbases = [os.path.basename(i).split('.')[0] for i in in_files]
    out_files = [os.path.join(out_dir, '{}.rdr'.format(i)) for i in fbases]
    os.makedirs(out_dir, exist_ok=True)
    for i in range(len(in_files)):
        in_file = in_files[i]
        out_file = out_files[i]
        ds = gdal.Open(in_file, gdal.GA_ReadOnly)
        in_wid = ds.RasterXSize
        in_len = ds.RasterYSize
        src_win = [x_start, y_start, x_win_num * x_step, y_win_num * y_step]
        print('read {} from file: {}'.format(src_win, in_file))
        print('write file: {}'.format(out_file))
        opts = gdal.TranslateOptions(format='ENVI',
                                     width=x_win_num,
                                     height=y_win_num,
                                     srcWin=src_win,
                                     noData=0)
        gdal.Translate(out_file, ds, options=opts)
        ds = None
        print('write file: {}'.format(out_file+'.vrt'))
        ds = gdal.Open(out_file, gdal.GA_ReadOnly)
        gdal.Translate(out_file+'.vrt', ds, options=gdal.TranslateOptions(format='VRT'))
        ds = None
    return
def prepareGeometry ( full_dir , out_dir , x_start , y_start , x_step , y_step , x_win_num , y_win_num , fbases = [ 'hgt' , 'lat' , 'lon' , 'los' , 'shadowMask' , 'waterMask' ] ) : full_dir = os . path . abspath ( full_dir ) out_dir = os . path . abspath ( out_dir ) full_exts = [ '.rdr.full' , '.rdr' ] if full_dir != out_dir else [ '.rdr.full' ] full_exts = [ e for e in full_exts if os . path . isfile ( os . path . join ( full_dir , '{f}{e}' . format ( f = fbases [ 0 ] , e = e ) ) ) ] if len ( full_exts ) == 0 : raise ValueError ( 'No full resolution {}.rdr* file found in: {}' . format ( fbases [ 0 ] , full_dir ) ) full_ext = full_exts [ 0 ] print ( '-' * 50 ) print ( 'generate the corresponding multi-looked geometry datasets using gdal ...' ) in_files = [ os . path . join ( full_dir , '{f}{e}' . format ( f = f , e = full_ext ) ) for f in fbases ] in_files = [ i for i in in_files if os . path . isfile ( i ) ] fbases = [ os . path . basename ( i ) . split ( '.' ) [ 0 ] for i in in_files ] out_files = [ os . path . join ( out_dir , '{}.rdr' . format ( i ) ) for i in fbases ] os . makedirs ( out_dir , exist_ok = True ) for i in range ( len ( in_files ) ) : in_file = in_files [ i ] out_file = out_files [ i ] ds = gdal . Open ( in_file , gdal . GA_ReadOnly ) in_wid = ds . RasterXSize in_len = ds . RasterYSize src_win = [ x_start , y_start , x_win_num * x_step , y_win_num * y_step ] print ( 'read {} from file: {}' . format ( src_win , in_file ) ) print ( 'write file: {}' . format ( out_file ) ) opts = gdal . TranslateOptions ( format = 'ENVI' , width = x_win_num , height = y_win_num , srcWin = src_win , noData = 0 ) gdal . Translate ( out_file , ds , options = opts ) ds = None print ( 'write file: {}' . format ( out_file + '.vrt' ) ) ds = gdal . Open ( out_file , gdal . GA_ReadOnly ) gdal . Translate ( out_file + '.vrt' , ds , options = gdal . TranslateOptions ( format = 'VRT' ) ) ds = None return
Generate multilooked geometry datasets in the same grid as the estimated offset field
from the full resolution geometry datasets.
Generate multilooked geometry datasets in the same grid as the estimated offset field from the full resolution geometry datasets .
"""Generate multilooked geometry datasets in the same grid as the estimated offset field
    from the full resolution geometry datasets.
    Parameters: full_dir    - str, path of input  geometry directory in full resolution
                out_dir     - str, path of output geometry directory
                x/y_start   - int, starting column/row number
                x/y_step    - int, output pixel step in column/row direction
                x/y_win_num - int, number of columns/rows
    """ # grab the file extension for full resolution file # input files # output files # input file size # starting column/row and column/row number # write binary data file # write VRT file
full_dir
out_dir
x_start
y_start
x_step
y_step
x_win_num
y_win_num
fbases