Пример #1
0
def apply_speckle_filter(fi):

    outfile = fi.replace('.tif', '_sf.tif')
    looks = 4
    size = 7
    dampening_factor = 1
    (x, y, trans, proj, img) = saa.read_gdal_file(saa.open_gdal_file(fi))
    data = enh_lee(looks, size, dampening_factor, img)
    saa.write_gdal_file_float(outfile, trans, proj, data, nodata=0)
    return (outfile)
Пример #2
0
def create_dB(fi):
    (x, y, trans, proj, data) = saa.read_gdal_file(saa.open_gdal_file(fi))

    # If your input data is amplitude data, use these 2 lines:
    #    pwrdata = data*data
    #    dBdata = 10 * np.log(pwrdata)

    # If your input data is power data, use the following line:
    dBdata = 10 * np.log(data)

    outfile = fi.replace('.tif', '_dB.tif')
    saa.write_gdal_file_float(outfile, trans, proj, dBdata, nodata=0)
    return (outfile)
Пример #3
0
def makeGeotiffFiles(h5File, dataName, params):

    # Open up the HDF5 file
    source = h5py.File("%s" % h5File)
    imgarray = source["%s" % dataName][()]
    maxband = imgarray.shape[0]
    logging.info("Found %s bands to process" % maxband)

    # Read a reference file for geolocation and size information
    os.chdir("../DATA")
    x, y, trans, proj = saa.read_gdal_file_geo(
        saa.open_gdal_file(params['pFile'][0]))
    os.chdir("../Stack")

    # Get the entire date range
    longList = np.unique(params['mdate'] + params['sdate'])
    dateList = []
    for i in range(len(longList)):
        dateList.append(longList[i][0:8])
    dateList = np.unique(dateList)
    dateList.sort()
    logging.debug("Datelist is {}".format(dateList))

    for cnt in range(maxband):
        logging.info("Processing band %s" % str(cnt + 1))
        if dataName == 'recons':
            if params['train']:
                outFile = "{}_trn_gnt_phase.raw".format(dateList[cnt])
            else:
                outFile = "{}_gnt_phase.raw".format(dateList[cnt])
        elif dataName == 'rawts':
            if params['train']:
                outFile = "{}_trn_raw_phase.raw".format(dateList[cnt])
            else:
                outFile = "{}_raw_phase.raw".format(dateList[cnt])
        elif dataName == 'error':
            if params['train']:
                outFile = "{}_trn_error_phase.raw".format(dateList[cnt])
            else:
                outFile = "{}_error_phase.raw".format(dateList[cnt])

        cmd = 'gdal_translate -b {} -of ENVI HDF5:"{}"://{} {}'.format(
            cnt + 1, h5File, dataName, outFile)
        execute(cmd, uselogging=True)
        newdata = np.fromfile(outFile, dtype=np.float32, count=-1)
        img = np.reshape(newdata, (y, x))
        outFile = outFile.replace('.raw', '.tif')
        saa.write_gdal_file_float(outFile, trans, proj, img)
Пример #4
0
#!/usr/bin/env python

import re, sys, os
import numpy as np
import saa_func_lib as saa

i = sys.argv[1]
q = sys.argv[2]

(x, y, trans, proj, idata) = saa.read_gdal_file(saa.open_gdal_file(i))
(x, y, trans, proj, qdata) = saa.read_gdal_file(saa.open_gdal_file(q))

amp = np.sqrt(np.sqrt(np.power(idata, 2) + np.power(qdata, 2)))
phase = np.arctan2(qdata, idata)

saa.write_gdal_file_float('amplitude.tif', trans, proj, amp)
saa.write_gdal_file_float('phase.tif', trans, proj, phase)
Пример #5
0
def amp2pwr(fi):
    x, y, trans, proj, data = saa.read_gdal_file(saa.open_gdal_file(fi))
    pwrdata = data * data
    outfile = fi.replace(".tif", "_pwr.tif")
    saa.write_gdal_file_float(outfile, trans, proj, pwrdata, nodata=0)
    return (outfile)
Пример #6
0
def pwr2amp(fi):
    x, y, trans, proj, data = saa.read_gdal_file(saa.open_gdal_file(fi))
    ampdata = np.sqrt(data)
    outfile = fi.replace(".tif", "_amp.tif")
    saa.write_gdal_file_float(outfile, trans, proj, ampdata, nodata=0)
    return (outfile)
Пример #7
0
if bands == 1:
        (ox,oy,proj,trans,odata) = sa.read_gdal_file(oh,1)
        np.putmask(odata,odata>5,0)
elif bands ==2:
        (ox,oy,proj,trans,odata) = sa.read_gdal_file(oh,1)
        np.putmask(odata,odata>5,0)
        (ox,oy,proj,trans,pdata) = sa.read_gdal_file(oh,2)

# Create geotransform based on ann file and simple EPSG:4326 WKT for projection
otrans = [ul_lon,lon_step,0,ul_lat,0,lat_step]
oproj = 'GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]'

outfile = file.replace('grd','tif')

if (tif == 1):
    outfile = file.replace('tif','filt.tif')

if filter==1:
        print 'Applying boxcar filter in x direction'
        outdata = sa.boxcar_y(odata,3)
        print 'Applying boxcar filter in y direction'
        outdata2 = sa.boxcar_x(odata,3)
        out = (outdata + outdata2)/2
        sa.write_gdal_file_float(outfile,otrans,oproj,out)
else:
        sa.write_gdal_file_float(outfile,otrans,oproj,odata)

if bands == 2:
        outfile = file.replace('grd','phase.tif')
        sa.write_gdal_file_float(outfile,otrans,oproj,pdata)