Skip to content

Commit

Permalink
Merge pull request #14 from leiyangleon/autoRIFT_v1.1.0
Browse files Browse the repository at this point in the history
upgrade to v1.1.0
  • Loading branch information
leiyangleon authored Jan 7, 2021
2 parents 9317ecc + 7da07ca commit 3bf089c
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 194 deletions.
559 changes: 456 additions & 103 deletions geo_autoRIFT/autoRIFT/autoRIFT.py

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion geo_autoRIFT/autoRIFT/autoRIFT_ISCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@
mandatory=False,
doc = 'Input data type: 0 -> uint8, 1 -> float32')

MULTI_THREAD = Component.Parameter('MultiThread',
public_name = 'MULTI_THREAD',
default = 0,
type = int,
mandatory=False,
doc = 'Number of Threads; default specified by 0 uses single core and surpasses the multithreading routine')


try:
# Try Autorift within ISCE first
Expand Down Expand Up @@ -223,7 +230,8 @@ class autoRIFT_ISCE(autoRIFT, Component):
BUFF_DISTANCE_C,
COARSE_COR_CUTOFF,
OVER_SAMPLE_RATIO,
DATA_TYPE)
DATA_TYPE,
MULTI_THREAD)



Expand Down
14 changes: 12 additions & 2 deletions geo_autoRIFT/geogrid/Geogrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def getProjectionSystem(self):
raise Exception('At least the DEM parameter must be set for geogrid')

from osgeo import gdal, osr
ds = gdal.Open(self.demname, gdal.GA_ReadOnly)
if self.urlflag == 1:
ds = gdal.Open('/vsicurl/%s' %(self.demname))
else:
ds = gdal.Open(self.demname, gdal.GA_ReadOnly)
srs = osr.SpatialReference()
srs.ImportFromWkt(ds.GetProjection())
srs.AutoIdentifyEPSG()
Expand All @@ -93,7 +96,10 @@ def getProjectionSystem(self):
else:
raise Exception('Non-standard coordinate system encountered')
if not epsgstr: #Empty string->use shell command gdalsrsinfo for last trial
cmd = 'gdalsrsinfo -o epsg {0}'.format(self.demname)
if self.urlflag == 1:
cmd = 'gdalsrsinfo -o epsg /vsicurl/{0}'.format(self.demname)
else:
cmd = 'gdalsrsinfo -o epsg {0}'.format(self.demname)
epsgstr = subprocess.check_output(cmd, shell=True)
# pdb.set_trace()
epsgstr = re.findall("EPSG:(\d+)", str(epsgstr))[0]
Expand Down Expand Up @@ -274,6 +280,9 @@ def setState(self):
geogrid.setRO2VYFilename_Py( self._geogrid, self.winro2vyname)
geogrid.setLookSide_Py(self._geogrid, self.lookSide)
geogrid.setNodataOut_Py(self._geogrid, self.nodata_out)
if self.urlflag is None:
self.urlflag = 0
geogrid.setUrlFlag_Py(self._geogrid, self.urlflag)

self._orbit = self.orbit.exportToC()
geogrid.setOrbit_Py(self._geogrid, self._orbit)
Expand Down Expand Up @@ -321,6 +330,7 @@ def __init__(self):
self.csmaxxname = None
self.csmaxyname = None
self.ssmname = None
self.urlflag = None

##Output related parameters
self.winlocname = None
Expand Down
77 changes: 33 additions & 44 deletions geo_autoRIFT/geogrid/GeogridOptical.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def getProjectionSystem(self, filename, urlflag):
raise Exception('File {0} does not exist'.format(filename))

from osgeo import gdal, osr
if urlflag is 1:
if urlflag == 1:
ds = gdal.Open('/vsicurl/%s' %(filename))
else:
ds = gdal.Open(filename, gdal.GA_ReadOnly)
Expand All @@ -86,7 +86,7 @@ def getProjectionSystem(self, filename, urlflag):
else:
raise Exception('Non-standard coordinate system encountered')
if not epsgstr: #Empty string->use shell command gdalsrsinfo for last trial
if urlflag is 1:
if urlflag == 1:
cmd = 'gdalsrsinfo -o epsg /vsicurl/{0}'.format(filename)
else:
cmd = 'gdalsrsinfo -o epsg {0}'.format(filename)
Expand Down Expand Up @@ -163,7 +163,7 @@ def geogrid(self):

urlflag = self.urlflag

if urlflag is 1:
if urlflag == 1:
print("\nReading input images into memory directly from URL's")
else:
print("\nReading input images locally from files")
Expand Down Expand Up @@ -231,56 +231,45 @@ def geogrid(self):
import struct

# pdb.set_trace()
if urlflag is 1:
demDS = gdal.Open('/vsicurl/%s' %(self.demname))
else:
demDS = gdal.Open(self.demname, gdal.GA_ReadOnly)
if urlflag == 1:
self.demname = '/vsicurl/%s' %(self.demname)
self.dhdxname = '/vsicurl/%s' %(self.dhdxname)
self.dhdyname = '/vsicurl/%s' %(self.dhdyname)
self.vxname = '/vsicurl/%s' %(self.vxname)
self.vyname = '/vsicurl/%s' %(self.vyname)
self.srxname = '/vsicurl/%s' %(self.srxname)
self.sryname = '/vsicurl/%s' %(self.sryname)
self.csminxname = '/vsicurl/%s' %(self.csminxname)
self.csminyname = '/vsicurl/%s' %(self.csminyname)
self.csmaxxname = '/vsicurl/%s' %(self.csmaxxname)
self.csmaxyname = '/vsicurl/%s' %(self.csmaxyname)
self.ssmname = '/vsicurl/%s' %(self.ssmname)


demDS = gdal.Open(self.demname, gdal.GA_ReadOnly)

if (self.dhdxname != ""):
if urlflag is 1:
sxDS = gdal.Open('/vsicurl/%s' %(self.dhdxname))
syDS = gdal.Open('/vsicurl/%s' %(self.dhdyname))
else:
sxDS = gdal.Open(self.dhdxname, gdal.GA_ReadOnly)
syDS = gdal.Open(self.dhdyname, gdal.GA_ReadOnly)
sxDS = gdal.Open(self.dhdxname, gdal.GA_ReadOnly)
syDS = gdal.Open(self.dhdyname, gdal.GA_ReadOnly)

if (self.vxname != ""):
if urlflag is 1:
vxDS = gdal.Open('/vsicurl/%s' %(self.vxname))
vyDS = gdal.Open('/vsicurl/%s' %(self.vyname))
else:
vxDS = gdal.Open(self.vxname, gdal.GA_ReadOnly)
vyDS = gdal.Open(self.vyname, gdal.GA_ReadOnly)
vxDS = gdal.Open(self.vxname, gdal.GA_ReadOnly)
vyDS = gdal.Open(self.vyname, gdal.GA_ReadOnly)

if (self.srxname != ""):
if urlflag is 1:
srxDS = gdal.Open('/vsicurl/%s' %(self.srxname))
sryDS = gdal.Open('/vsicurl/%s' %(self.sryname))
else:
srxDS = gdal.Open(self.srxname, gdal.GA_ReadOnly)
sryDS = gdal.Open(self.sryname, gdal.GA_ReadOnly)
srxDS = gdal.Open(self.srxname, gdal.GA_ReadOnly)
sryDS = gdal.Open(self.sryname, gdal.GA_ReadOnly)

if (self.csminxname != ""):
if urlflag is 1:
csminxDS = gdal.Open('/vsicurl/%s' %(self.csminxname))
csminyDS = gdal.Open('/vsicurl/%s' %(self.csminyname))
else:
csminxDS = gdal.Open(self.csminxname, gdal.GA_ReadOnly)
csminyDS = gdal.Open(self.csminyname, gdal.GA_ReadOnly)
csminxDS = gdal.Open(self.csminxname, gdal.GA_ReadOnly)
csminyDS = gdal.Open(self.csminyname, gdal.GA_ReadOnly)

if (self.csmaxxname != ""):
if urlflag is 1:
csmaxxDS = gdal.Open('/vsicurl/%s' %(self.csmaxxname))
csmaxyDS = gdal.Open('/vsicurl/%s' %(self.csmaxyname))
else:
csmaxxDS = gdal.Open(self.csmaxxname, gdal.GA_ReadOnly)
csmaxyDS = gdal.Open(self.csmaxyname, gdal.GA_ReadOnly)
csmaxxDS = gdal.Open(self.csmaxxname, gdal.GA_ReadOnly)
csmaxyDS = gdal.Open(self.csmaxyname, gdal.GA_ReadOnly)

if (self.ssmname != ""):
if urlflag is 1:
ssmDS = gdal.Open('/vsicurl/%s' %(self.ssmname))
else:
ssmDS = gdal.Open(self.ssmname, gdal.GA_ReadOnly)
ssmDS = gdal.Open(self.ssmname, gdal.GA_ReadOnly)

if demDS is None:
raise Exception('Error opening DEM file {0}'.format(self.demname))
Expand Down Expand Up @@ -777,15 +766,15 @@ def coregister(self,in1,in2,urlflag):
from osgeo import gdal, osr
import struct

if urlflag is 1:
if urlflag == 1:
DS1 = gdal.Open('/vsicurl/%s' %(in1))
else:
DS1 = gdal.Open(in1, gdal.GA_ReadOnly)
trans1 = DS1.GetGeoTransform()
xsize1 = DS1.RasterXSize
ysize1 = DS1.RasterYSize

if urlflag is 1:
if urlflag == 1:
DS2 = gdal.Open('/vsicurl/%s' %(in2))
else:
DS2 = gdal.Open(in2, gdal.GA_ReadOnly)
Expand Down Expand Up @@ -837,7 +826,7 @@ def coregister(self,in1,in2,urlflag):

trans = (W, trans1[1], 0.0, N, 0.0, trans1[5])

if urlflag is 0:
if urlflag == 0:

I1 = DS1.ReadAsArray(xoff=x1a, yoff=y1a, xsize=x1b-x1a+1, ysize=y1b-y1a+1)
I2 = DS2.ReadAsArray(xoff=x2a, yoff=y2a, xsize=x2b-x2a+1, ysize=y2b-y2a+1)
Expand Down
13 changes: 13 additions & 0 deletions geo_autoRIFT/geogrid/bindings/geogridmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,19 @@ PyObject* setNodataOut(PyObject *self, PyObject *args)
return Py_BuildValue("i", 0);
}

PyObject* setUrlFlag(PyObject *self, PyObject *args)
{
uint64_t ptr;
int urlflag;
if (!PyArg_ParseTuple(args, "Ki", &ptr, &urlflag))
{
return NULL;
}

((geoGrid*)(ptr))->urlflag = urlflag;
return Py_BuildValue("i", 0);
}

PyObject* setOrbit(PyObject *self, PyObject *args)
{
uint64_t ptr, orb;
Expand Down
1 change: 1 addition & 0 deletions geo_autoRIFT/geogrid/include/geogrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct geoGrid
int nPixels;
int lookSide;
int nodata_out;
int urlflag;
double incidenceAngle;

//Output file names
Expand Down
2 changes: 2 additions & 0 deletions geo_autoRIFT/geogrid/include/geogridmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern "C"
PyObject * setOrbit(PyObject *, PyObject *);
PyObject * setLookSide(PyObject *, PyObject *);
PyObject * setNodataOut(PyObject *, PyObject *);
PyObject * setUrlFlag(PyObject *, PyObject *);

PyObject * setWindowLocationsFilename(PyObject *, PyObject *);
PyObject * setWindowOffsetsFilename(PyObject *, PyObject *);
Expand Down Expand Up @@ -91,6 +92,7 @@ static PyMethodDef geogrid_methods[] =
{"setOrbit_Py", setOrbit, METH_VARARGS, " "},
{"setLookSide_Py", setLookSide, METH_VARARGS, " "},
{"setNodataOut_Py", setNodataOut, METH_VARARGS, " "},
{"setUrlFlag_Py", setUrlFlag, METH_VARARGS, " "},
{"setXLimits_Py", setXLimits, METH_VARARGS, " "},
{"setYLimits_Py", setYLimits, METH_VARARGS, " "},
{"setWindowLocationsFilename_Py", setWindowLocationsFilename, METH_VARARGS, " "},
Expand Down
26 changes: 25 additions & 1 deletion geo_autoRIFT/geogrid/src/geogrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ void geoGrid::geogrid()

//For now print inputs that were obtained

if (urlflag == 1){
std::cout << "\nReading input images into memory directly from URL's\n";
}
else
{
std::cout << "\nReading input images locally from files\n";
}

std::cout << "\nRadar parameters: \n";
std::cout << "Range: " << startingRange << " " << dr << "\n";
std::cout << "Azimuth: " << sensingStart << " " << prf << "\n";
Expand Down Expand Up @@ -144,7 +152,23 @@ void geoGrid::geogrid()
GDALDataset* ssmDS = NULL;

double geoTrans[6];


std::string url ("/vsicurl/");
if (urlflag == 1)
{
demname = url + demname;
dhdxname = url + dhdxname;
dhdyname = url + dhdyname;
vxname = url + vxname;
vyname = url + vyname;
srxname = url + srxname;
sryname = url + sryname;
csminxname = url + csminxname;
csminyname = url + csminyname;
csmaxxname = url + csmaxxname;
csmaxyname = url + csmaxyname;
ssmname = url + ssmname;
}
demDS = reinterpret_cast<GDALDataset *>(GDALOpenShared(demname.c_str(), GA_ReadOnly));
if (dhdxname != "")
{
Expand Down
Loading

0 comments on commit 3bf089c

Please sign in to comment.