From fb7ad09211b6cd2fc51b8da9e87eb5f4aab77824 Mon Sep 17 00:00:00 2001 From: Simon Kraatz <49723397+sgk0@users.noreply.github.com> Date: Wed, 6 May 2020 18:04:58 -0400 Subject: [PATCH] pull request in response to rtcApp.py is incomplete #120 (#128) * Update README.md * Update runTopo.py * Update rtcApp.py * Update runNormalize.py * Update SConscript --- README.md | 7 ++- applications/SConscript | 1 + applications/rtcApp.py | 41 +++++++++--- components/isceobj/RtcProc/Factories.py | 2 +- components/isceobj/RtcProc/SConscript | 2 +- components/isceobj/RtcProc/runGeocode.py | 80 ++++++++++++++++++++++++ components/isceobj/RtcProc/runTopo.py | 1 - 7 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 components/isceobj/RtcProc/runGeocode.py diff --git a/README.md b/README.md index a8787ba..b14851e 100644 --- a/README.md +++ b/README.md @@ -630,13 +630,16 @@ The inputs are Sentinel GRD zipfiles /Users/data/sentinel1 - 20 sentinel1 + 100 + [VV, VH] + 32618 + 100 + bilinear $dir$/rtcApp/data/S1A_IW_GRDH_1SDV_20181221T225104_20181221T225129_025130_02C664_B46C.zip $dir$/orbits $dir$/rtcApp/output - [VV, VH] diff --git a/applications/SConscript b/applications/SConscript index 4f8eddb..0bf0773 100644 --- a/applications/SConscript +++ b/applications/SConscript @@ -59,6 +59,7 @@ listFiles = ['mdx.py', # 'extractHDROrbit.py', # 'formSLC.py', # 'viewMetadata.py', + 'rtcApp.py', 'make_raw.py', '__init__.py', 'isceApp.py', diff --git a/applications/rtcApp.py b/applications/rtcApp.py index 05d4575..333d99a 100755 --- a/applications/rtcApp.py +++ b/applications/rtcApp.py @@ -100,6 +100,28 @@ GEOCODE_BOX = Application.Parameter( doc='Bounding box for geocoding - South, North, West, East in degrees' ) +EPSG = Application.Parameter( + 'epsg', + public_name='epsg id', + default = '', + type=str, + doc='epsg code for roi' + ) + +GSPACING = Application.Parameter('gspacing', + public_name='geocode spacing', + default = 100.0, + type = float, + doc = 'Desired grid spacing of geocoded product in meters, in the specified UTM grid.' + ) + +INTMETHOD = Application.Parameter('intmethod', + public_name='geocode interpolation method', + default = 'bilinear', + type = str, + doc = 'Desired grid spacing of geocoded product in meters, in the specified UTM grid.' + ) + PICKLE_DUMPER_DIR = Application.Parameter( 'pickleDumpDir', public_name='pickle dump directory', @@ -149,10 +171,10 @@ NUMBER_RANGE_LOOKS = Application.Parameter('numberRangeLooks', POSTING = Application.Parameter('posting', public_name='posting', - default = 20.0, + default = 10.0, type = float, mandatory = False, - doc = 'Posting of data used to determine looks') + doc = 'Posting of data. This can be any integer multiple of the product resolution. Used to determine looks') POLARIZATIONS = Application.Parameter('polarizations', public_name='polarizations', @@ -215,6 +237,9 @@ class GRDSAR(Application): NUMBER_RANGE_LOOKS, POSTING, GEOCODE_BOX, + EPSG, + GSPACING, + INTMETHOD, PICKLE_DUMPER_DIR, PICKLE_LOAD_DIR, RENDERER, @@ -357,7 +382,7 @@ class GRDSAR(Application): self.multilook = RtcProc.createLooks(self) self.runTopo = RtcProc.createTopo(self) self.runNormalize = RtcProc.createNormalize(self) -# self.runGeocode = RtcProc.createGeocode(self) + self.runGeocode = RtcProc.createGeocode(self) return None @@ -390,8 +415,8 @@ class GRDSAR(Application): self.step('normalize', func=self.runNormalize) # Geocode -# self.step('geocode', func=self.runGeocode, -# args=(self.geocode_list, self.do_unwrap, self.geocode_bbox)) + self.step('geocode', func=self.runGeocode, + args=(self.geocode_list, self.geocode_bbox)) return None @@ -417,12 +442,8 @@ class GRDSAR(Application): ##Run normalize to get gamma0 self.runNormalize() - ###Compute covariance -# self.runEstimateCovariance() - # Geocode -# self.runGeocode(self.geocode_list, self.do_unwrap, self.geocode_bbox) - + self.runGeocode() timeEnd = time.time() logger.info("Total Time: %i seconds" %(timeEnd - timeStart)) diff --git a/components/isceobj/RtcProc/Factories.py b/components/isceobj/RtcProc/Factories.py index 038f1f7..b83c531 100644 --- a/components/isceobj/RtcProc/Factories.py +++ b/components/isceobj/RtcProc/Factories.py @@ -47,5 +47,5 @@ createVerifyDEM = _factory("runVerifyDEM") createLooks = _factory("runLooks") createTopo = _factory("runTopo") createNormalize = _factory("runNormalize") -#createGeocode = _factory("runGeocode") +createGeocode = _factory("runGeocode") diff --git a/components/isceobj/RtcProc/SConscript b/components/isceobj/RtcProc/SConscript index fe05705..a048140 100644 --- a/components/isceobj/RtcProc/SConscript +++ b/components/isceobj/RtcProc/SConscript @@ -40,7 +40,7 @@ project = 'RtcProc' install = os.path.join(envisceobj['PRJ_SCONS_INSTALL'],package,project) -listFiles = ['__init__.py', 'Factories.py', 'RtcProc.py', 'runPreprocessor.py', 'runVerifyDEM.py', 'runLooks.py', 'runTopo.py'] +listFiles = ['__init__.py', 'Factories.py', 'RtcProc.py', 'runPreprocessor.py', 'runVerifyDEM.py', 'runLooks.py', 'runNormalize.py', 'runTopo.py', 'runGeocode.py'] envisceobj.Install(install,listFiles) envisceobj.Alias('install',install) diff --git a/components/isceobj/RtcProc/runGeocode.py b/components/isceobj/RtcProc/runGeocode.py new file mode 100644 index 0000000..cb44398 --- /dev/null +++ b/components/isceobj/RtcProc/runGeocode.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Author: Simon Kraatz +# Copyright 2016 + +import logging +import isceobj +import os +import numpy as np +from isceobj.Util.decorators import use_api +from osgeo import gdal, ogr, osr + +logger = logging.getLogger('isce.grdsar.looks') + +def runGeocode(self): + ''' + Geocode a swath file using corresponding lat, lon files + ''' + sourcexmltmpl = ''' + {0} + {1} + ''' + + gcl = [f for f in os.listdir(self._grd.outputFolder) if f.startswith('gamma') and f.endswith('.vrt')] + a, b = os.path.split(self._grd.outputFolder) + latfile = os.path.join(a,self._grd.geometryFolder,'lat.rdr.vrt') + lonfile = os.path.join(a,self._grd.geometryFolder,'lon.rdr.vrt') + + outsrs = 'EPSG:'+str(self.epsg) + gspacing = self.gspacing + method = self.intmethod + insrs = 4326 + fmt = 'GTiff' + fl = len(gcl) + + for num, val in enumerate(gcl): + print('****Geocoding file %s out of %s: %s****' %(num+1, fl, val)) + infile = os.path.join(a, self._grd.outputFolder, val) + outfile = os.path.join(a, self._grd.outputFolder, val[:-3]+'tif') + + driver = gdal.GetDriverByName('VRT') + tempvrtname = os.path.join(a, self._grd.outputFolder, 'geocode.vrt') + + inds = gdal.OpenShared(infile, gdal.GA_ReadOnly) + tempds = driver.Create(tempvrtname, inds.RasterXSize, inds.RasterYSize, 0) + + for ii in range(inds.RasterCount): + band = inds.GetRasterBand(1) + tempds.AddBand(band.DataType) + tempds.GetRasterBand(ii+1).SetMetadata({'source_0': sourcexmltmpl.format(infile, ii+1)}, 'vrt_sources') + + sref = osr.SpatialReference() + sref.ImportFromEPSG(insrs) + srswkt = sref.ExportToWkt() + + tempds.SetMetadata({'SRS' : srswkt, + 'X_DATASET': lonfile, + 'X_BAND' : '1', + 'Y_DATASET': latfile, + 'Y_BAND' : '1', + 'PIXEL_OFFSET' : '0', + 'LINE_OFFSET' : '0', + 'PIXEL_STEP' : '1', + 'LINE_STEP' : '1'}, 'GEOLOCATION') + + band = None + tempds = None + inds = None + bounds = None + + spacing = [gspacing, gspacing] + + warpOptions = gdal.WarpOptions(format=fmt, + xRes=spacing[0], yRes=spacing[1], + dstSRS=outsrs, + outputBounds = bounds, + resampleAlg=method, geoloc=True) + gdal.Warp(outfile, tempvrtname, options=warpOptions) + + return diff --git a/components/isceobj/RtcProc/runTopo.py b/components/isceobj/RtcProc/runTopo.py index fde83c3..4c6a4cf 100755 --- a/components/isceobj/RtcProc/runTopo.py +++ b/components/isceobj/RtcProc/runTopo.py @@ -110,4 +110,3 @@ def runSimamp(outdir, hname='z.rdr'): hgtImage.finalizeImage() simImage.finalizeImage() -