nasa-jpl / autoRIFT

A Python module of a fast and intelligent algorithm for finding the pixel displacement between two images
Apache License 2.0
216 stars 52 forks source link

GeogridOptical.py Divide by zero error in search range creation if slope is not specified #20

Closed forrestfwilliams closed 3 years ago

forrestfwilliams commented 3 years ago

If testGeogrid_ISCE.py is run with search range files but not slope files, a divide by zero error occurs. Looking at lines 565-576 of GeogridOptical.py:

if (self.dhdxname != ""):
    normal = -slp / np.linalg.norm(slp)
else:
    normal = np.array([0., 0., 0.])

if (self.vxname != ""):
    vel[2] = -(vel[0]*normal[0]+vel[1]*normal[1])/normal[2]

if (self.srxname != ""):
    schrng1[2] = -(schrng1[0]*normal[0]+schrng1[1]*normal[1])/normal[2]
    schrng2[2] = -(schrng2[0]*normal[0]+schrng2[1]*normal[1])/normal[2]

If self.dhdxname is not specified, the normal vector is set to an array of zeroes, which results in divide by zero errors at lines 575 and 576 if self.srxname is specified. Must slope always be specified if the search range option is used?

leiyangleon commented 3 years ago

@forrestfwilliams thanks for the question. We really need to update the documentation which is outdated. Geogrid can be used with several combination of input files. The possible combinations can be found here. When certain conditions are met, corresponding output variables will be written to a file (e.g. window_*.tif) otherwise, they will be discarded. For your particular question, yes, slope must be provided in order for search range to be outputted, which is enforced by this check. If only search range is provided without slope, although you might see warnings of divide by zero, the program runs through without crashing, i.e. other variables are outputted properly but search range just won't be written to a file because it is meaningless (divide by zero).

The math behind this can be found in this paper. Refer to Eq 4 (derivation in Appendix A) that converts between velocity (and search range of velocity that is also in unit of m/yr) and pixel offset (and search range in the number of pixels).

So, slope is is a must-have for Geogrid to generate search range. However, it is strictly required for radar images with range/azimuth geometry; for optical images, both DEM and slope can be all-zero-value images.

forrestfwilliams commented 3 years ago

Thank you for this explanation @leiyangleon. I am happy for this issue to be closed now.