Bump autoRIFT to 1.4.0
parent
816459c954
commit
580a9d4081
|
@ -1,241 +0,0 @@
|
|||
# autoRIFT (autonomous Repeat Image Feature Tracking)
|
||||
|
||||
|
||||
|
||||
[](https://www.python.org/)
|
||||
[](https://github.com/leiyangleon/autoRIFT/releases)
|
||||
[](https://github.com/leiyangleon/autoRIFT/blob/master/LICENSE)
|
||||
[](https://doi.org/10.5281/zenodo.4211013)
|
||||
|
||||
|
||||
|
||||
**A Python module of a fast and intelligent algorithm for finding the pixel displacement between two images**
|
||||
|
||||
**autoRIFT can be installed as a standalone Python module (only supports Cartesian coordinates) either manually or as a conda install (https://github.com/conda-forge/autorift-feedstock). To allow support for both Cartesian and radar coordinates, autoRIFT must be installed with the InSAR Scientific Computing Environment (ISCE: https://github.com/isce-framework/isce2)**
|
||||
|
||||
**Use cases include all dense feature tracking applications, including the measurement of surface displacements occurring between two repeat satellite images as a result of glacier flow, large earthquake displacements, and land slides**
|
||||
|
||||
**autoRIFT can be used for dense feature tracking between two images over a grid defined in an arbitrary geographic Cartesian (northing/easting) coordinate projection when used in combination with the sister Geogrid Python module (https://github.com/leiyangleon/Geogrid). Example applications include searching radar-coordinate imagery on a polar stereographic grid and searching Universal Transverse Mercator (UTM) imagery at a specified geographic Cartesian (northing/easting) coordinate grid**
|
||||
|
||||
|
||||
Copyright (C) 2019 California Institute of Technology. Government Sponsorship Acknowledged.
|
||||
|
||||
Link: https://github.com/leiyangleon/autoRIFT
|
||||
|
||||
Citation: https://doi.org/10.5281/zenodo.4211013
|
||||
|
||||
|
||||
## 1. Authors
|
||||
|
||||
Alex Gardner (JPL/Caltech; alex.s.gardner@jpl.nasa.gov) first described the algorithm "auto-RIFT" in (Gardner et al., 2018) and developed the first version in MATLAB;
|
||||
|
||||
Yang Lei (GPS/Caltech; ylei@caltech.edu) translated it to Python, further optimized and incoporated to the ISCE software;
|
||||
|
||||
Piyush Agram (JPL/Caltech; piyush.agram@jpl.nasa.gov) set up the installation as a standalone module and further cleaned the code.
|
||||
|
||||
Reference: Gardner, A. S., Moholdt, G., Scambos, T., Fahnstock, M., Ligtenberg, S., van den Broeke, M., & Nilsson, J. (2018). Increased West Antarctic and unchanged East Antarctic ice discharge over the last 7 years. The Cryosphere, 12(2), 521–547. https://doi.org/10.5194/tc-12-521-2018
|
||||
|
||||
|
||||
## 2. Acknowledgement
|
||||
|
||||
This effort was funded by the NASA MEaSUREs program in contribution to the Inter-mission Time Series of Land Ice Velocity and Elevation (ITS_LIVE) project (https://its-live.jpl.nasa.gov/) and through Alex Gardner’s participation in the NASA NISAR Science Team
|
||||
|
||||
|
||||
## 3. Features
|
||||
|
||||
* fast algorithm that finds displacement between the two images (where source and template image patches are extracted and correlated) using sparse search and iteratively progressive chip (template) sizes
|
||||
* for intelligent use, user can specify unstructured spatially-varying search centers (center of the source image patch), search offsets (center displacement of the template image patch compared to the source image patch), chip sizes (size of template image patch), search ranges (size of the source image patch)
|
||||
* faster than the conventional dense feature tracking "ampcor"/"denseampcor" algorithm included in ISCE by nearly 2 orders of magnitude
|
||||
* supports various preprocessing modes for specified image pair, e.g. either the raw image (both texture and topography) or the texture only (high-frequency components without the topography) can be used with various choices of the high-pass filter options
|
||||
* supports image data format of unsigned integer 8 (uint8; faster) and single-precision float (float32)
|
||||
* user can adjust all of the relevant parameters, as detailed below in the instructions
|
||||
* a Normalized Displacement Coherence (NDC) filter is developed (Gardner et al., 2018) to filter the chip displacemnt results based on displacement difference thresholds that are scaled to the local search range
|
||||
* a sparse integer displacement search is used to narrow the template search range and to eliminate areas of "low coherence" for fine decimal displacement search and following chip size iterations
|
||||
* novel nested grid design allows chip size progressively increase iteratively where a smaller chip size failed
|
||||
* a light interpolation is done to fill the missing (unreliable) chip displacement results using median filtering and bicubic-mode interpolation (that can remove pixel discrepancy when using other modes) and an interpolation mask is returned
|
||||
* the core displacement estimator (normalized cross correlation) and image pre-processing call OpenCV's Python and/or C++ functions for efficiency
|
||||
* sub-pixel displacement estimation using a fast Gaussian pyramid upsampling algorithm that is robust to sub-pixel locking; the intelligent (chip size-dependent) selection of oversampling ratio is also supported for a tradeoff between efficiency and accuracy
|
||||
* the current version can be installed with the ISCE software (that supports both Cartesian and radar coordinates) or as a standalone Python module (Cartesian coordinates only)
|
||||
* when used in combination with the Geogrid Python module (https://github.com/leiyangleon/Geogrid), autoRIFT can be used for feature tracking between image pair over a grid defined in an arbitrary geographic Cartesian (northing/easting) coordinate projection
|
||||
* when the grid is provided in geographic Cartesian (northing/easting) coordinates, outputs are returned in geocoded GeoTIFF image file format with the same EPSG projection code as input search grid
|
||||
* **[NEW]** the program now supports fetching optical images (Landsat-8 GeoTIFF and Sentinel-2 COG formats are included) as well as other inputs (e.g. DEM, slope, etc; all in GeoTIFF format) from either local machine or URL links. See the changes on the Geogrid [commands](https://github.com/leiyangleon/Geogrid). When using the autoRIFT commands below, users need to append a url flag: "-urlflag 1" for using URL links and performing coregistration, and "-urlflag 0" (default; can be omitted) for using coregistered files on local machine.
|
||||
|
||||
## 4. Possible Future Development
|
||||
|
||||
* for radar (SAR) images, it is yet to include the complex correlation of the two images, i.e. the current version only uses the amplitude correlation
|
||||
* the current version works for single-core CPU while the multi-core parallelization or GPU implementation would be useful to extend
|
||||
|
||||
|
||||
## 5. Demo
|
||||
|
||||
### 5.1 Optical image over regular grid in imaging coordinates
|
||||
|
||||
<img src="https://github.com/isce-framework/autoRIFT/blob/main/figures/regular_grid_optical.png" width="100%">
|
||||
|
||||
***Output of "autoRIFT" module for a pair of Landsat-8 images (20170708-20170724; same as the Demo dataset at https://github.com/leiyangleon/Geogrid) in Greenland over a regular-spacing grid: (a) estimated horizontal pixel displacement, (b) estimated vertical pixel displacement, (c) chip size used, (d) light interpolation mask.***
|
||||
|
||||
This is done by implementing the following command line:
|
||||
|
||||
Standalone:
|
||||
|
||||
testautoRIFT.py -m I1 -s I2 -fo 1
|
||||
|
||||
With ISCE:
|
||||
|
||||
testautoRIFT_ISCE.py -m I1 -s I2 -fo 1
|
||||
|
||||
where "I1" and "I2" are the reference and test images as defined in the instructions below. The "-fo" option indicates whether or not to read optical image data.
|
||||
|
||||
|
||||
### 5.2 Optical image over user-defined geographic Cartesian coordinate grid
|
||||
|
||||
<img src="https://github.com/isce-framework/autoRIFT/blob/main/figures/autorift1_opt.png" width="100%">
|
||||
|
||||
***Output of "autoRIFT" module for a pair of Landsat-8 images (20170708-20170724; same as the Demo dataset at https://github.com/leiyangleon/Geogrid) in Greenland over user-defined geographic Cartesian (northing/easting) coordinate grid (same grid used in the Demo at https://github.com/leiyangleon/Geogrid): (a) estimated horizontal pixel displacement, (b) estimated vertical pixel displacement, (c) light interpolation mask, (d) chip size used. Notes: all maps are established exactly over the same geographic Cartesian coordinate grid from input.***
|
||||
|
||||
This is done by implementing the following command line:
|
||||
|
||||
Standalone:
|
||||
|
||||
testautoRIFT.py -m I1 -s I2 -g winlocname -o winoffname -sr winsrname -csmin wincsminname -csmax wincsmaxname -vx winro2vxname -vy winro2vyname -fo 1
|
||||
|
||||
With ISCE:
|
||||
|
||||
testautoRIFT_ISCE.py -m I1 -s I2 -g winlocname -o winoffname -sr winsrname -csmin wincsminname -csmax wincsmaxname -vx winro2vxname -vy winro2vyname -fo 1
|
||||
|
||||
where "I1" and "I2" are the reference and test images as defined in the instructions below, and the optional inputs "winlocname", "winoffname", "winsrname", "wincsminname", "wincsmaxname", "winro2vxname", "winro2vyname" are outputs from running "testGeogrid_ISCE.py" or "testGeogridOptical.py" as defined at https://github.com/leiyangleon/Geogrid. When "winlocname" (grid location) is specified, each of the rest optional input ("win * name") can be either used or omitted.
|
||||
|
||||
|
||||
<img src="https://github.com/isce-framework/autoRIFT/blob/main/figures/autorift2_opt.png" width="100%">
|
||||
|
||||
***Final motion velocity results by combining outputs from "Geogrid" (i.e. matrix of conversion coefficients from the Demo at https://github.com/leiyangleon/Geogrid) and "autoRIFT" modules: (a) estimated motion velocity from Landsat-8 data (x-direction; in m/yr), (b) motion velocity from input data (x-direction; in m/yr), (c) estimated motion velocity from Landsat-8 data (y-direction; in m/yr), (d) motion velocity from input data (y-direction; in m/yr). Notes: all maps are established exactly over the same geographic Cartesian (northing/easting) coordinate grid from input.***
|
||||
|
||||
|
||||
### 5.3 Radar image over regular grid in imaging coordinates
|
||||
|
||||
<img src="https://github.com/isce-framework/autoRIFT/blob/main/figures/regular_grid_new.png" width="100%">
|
||||
|
||||
***Output of "autoRIFT" module for a pair of Sentinel-1A/B images (20170221-20170227; same as the Demo dataset at https://github.com/leiyangleon/Geogrid) at Jakobshavn Glacier of Greenland over a regular-spacing grid: (a) estimated range pixel displacement, (b) estimated azimuth pixel displacement, (c) chip size used, (d) light interpolation mask.***
|
||||
|
||||
|
||||
This is obtained by implementing the following command line:
|
||||
|
||||
With ISCE:
|
||||
|
||||
testautoRIFT_ISCE.py -m I1 -s I2
|
||||
|
||||
where "I1" and "I2" are the reference and test images as defined in the instructions below.
|
||||
|
||||
|
||||
### 5.4 Radar image over user-defined geographic Cartesian coordinate grid
|
||||
|
||||
<img src="https://github.com/isce-framework/autoRIFT/blob/main/figures/autorift1.png" width="100%">
|
||||
|
||||
***Output of "autoRIFT" module for a pair of Sentinel-1A/B images (20170221-20170227; same as the Demo dataset at https://github.com/leiyangleon/Geogrid) at Jakobshavn Glacier of Greenland over user-defined geographic Cartesian (northing/easting) coordinate grid (same grid used in the Demo at https://github.com/leiyangleon/Geogrid): (a) estimated range pixel displacement, (b) estimated azimuth pixel displacement, (c) light interpolation mask, (d) chip size used. Notes: all maps are established exactly over the same geographic Cartesian coordinate grid from input.***
|
||||
|
||||
This is done by implementing the following command line:
|
||||
|
||||
With ISCE:
|
||||
|
||||
testautoRIFT_ISCE.py -m I1 -s I2 -g winlocname -o winoffname -sr winsrname -csmin wincsminname -csmax wincsmaxname -vx winro2vxname -vy winro2vyname
|
||||
|
||||
where "I1" and "I2" are the reference and test images as defined in the instructions below, and the optional inputs "winlocname", "winoffname", "winsrname", "wincsminname", "wincsmaxname", "winro2vxname", "winro2vyname" are outputs from running "testGeogrid.py" as defined at https://github.com/leiyangleon/Geogrid. When "winlocname" (grid location) is specified, each of the rest optional input ("win * name") can be either used or omitted.
|
||||
|
||||
**Runtime comparison for this test (on an OS X system with 2.9GHz Intel Core i7 processor and 16GB RAM):**
|
||||
* __autoRIFT (single core): 10 mins__
|
||||
* __Dense ampcor from ISCE (8 cores): 90 mins__
|
||||
|
||||
|
||||
<img src="https://github.com/isce-framework/autoRIFT/blob/main/figures/autorift2.png" width="100%">
|
||||
|
||||
***Final motion velocity results by combining outputs from "Geogrid" (i.e. matrix of conversion coefficients from the Demo at https://github.com/leiyangleon/Geogrid) and "autoRIFT" modules: (a) estimated motion velocity from Sentinel-1 data (x-direction; in m/yr), (b) motion velocity from input data (x-direction; in m/yr), (c) estimated motion velocity from Sentinel-1 data (y-direction; in m/yr), (d) motion velocity from input data (y-direction; in m/yr). Notes: all maps are established exactly over the same geographic Cartesian (northing/easting) coordinate grid from input.***
|
||||
|
||||
|
||||
## 6. Instructions
|
||||
|
||||
**Note:**
|
||||
|
||||
* When the grid is provided in geographic Cartesian (northing/easting) coordinates (geographic coordinates lat/lon is not supported), it is required to run the "Geogrid" module (https://github.com/leiyangleon/Geogrid) first before running "autoRIFT". In other words, the outputs from "testGeogrid_ISCE.py" or "testGeogridOptical.py" (a.k.a "winlocname", "winoffname", "winsrname", "wincsminname", "wincsmaxname", "winro2vxname", "winro2vyname") will serve as optional inputs for running "autoRIFT" at a geographic grid, which is required to generate the final motion velocity maps.
|
||||
* When the outputs from running the "Geogrid" module are not provided, a regular grid in the imaging coordinates will be automatically assigned
|
||||
|
||||
**For quick use:**
|
||||
|
||||
* Refer to the file "testautoRIFT.py" (standalone) and "testautoRIFT_ISCE.py" (with ISCE) for the usage of the module and modify it for your own purpose
|
||||
* Input files include the reference image (required), test image (required), and the outputs from running "testGeogrid_ISCE.py" or "testGeogridOptical.py" (optional; a.k.a "winlocname", "winoffname", "winsrname", "wincsminname", "wincsmaxname", "winro2vxname", "winro2vyname"). When "winlocname" (grid location) is specified, each of the rest optional input ("win * name") can be either used or omitted.
|
||||
* Output files include 1) estimated horizontal displacement (equivalent to range for radar), 2) estimated vertical displacement (equivalent to minus azimuth for radar), 3) light interpolation mask, 4) iteratively progressive chip size used.
|
||||
|
||||
_Note: These four output files will be stored in a file named "offset.mat" that can be viewed in Python and MATLAB. When the grid is provided in geographic Cartesian (northing/easting) coordinates, a 4-band GeoTIFF with the same EPSG code as input grid will be created as well and named "offset.tif"; a 2-band GeoTIFF of the final converted motion velocity in geographic x- (easting) and y- (northing) coordinates will be created and named "velocity.tif". Also, it is possible to save the outputs in netCDF standard format by adding the "-nc" option to the "testautoRIFT.py" (standalone) and "testautoRIFT_ISCE.py" (with ISCE) command._
|
||||
|
||||
**For modular use:**
|
||||
|
||||
* In Python environment, type the following to import the "autoRIFT" module and initialize the "autoRIFT" object
|
||||
|
||||
_With ISCE:_
|
||||
|
||||
import isce
|
||||
from contrib.geo_autoRIFT.autoRIFT import autoRIFT_ISCE
|
||||
obj = autoRIFT_ISCE()
|
||||
obj.configure()
|
||||
|
||||
_Standalone:_
|
||||
|
||||
from autoRIFT import autoRIFT
|
||||
obj = autoRIFT()
|
||||
|
||||
* The "autoRIFT" object has several inputs that have to be assigned (listed below; can also be obtained by referring to "testautoRIFT.py"):
|
||||
|
||||
------------------input------------------
|
||||
I1 reference image (extracted image patches defined as "source")
|
||||
I2 test image (extracted image patches defined as "template"; displacement = motion vector of I2 relative to I1)
|
||||
xGrid [units = integer image pixels] horizontal pixel index at each grid point
|
||||
yGrid [units = integer image pixels] vertical pixel index at each grid point
|
||||
(if xGrid and yGrid not provided, a regular grid spanning the entire image will be automatically set up, which is similar to the conventional ISCE module, "ampcor" or "denseampcor")
|
||||
Dx0 [units = integer image pixels] horizontal "downstream" reach location (that specifies the horizontal pixel displacement of the template's search center relative to the source's) at each grid point
|
||||
Dy0 [units = integer image pixels] vertical "downstream" reach location (that specifies the vertical pixel displacement of the template's search center relative to the source's) at each grid point
|
||||
(if Dx0 and Dy0 not provided, an array with zero values will be automatically assigned and there will be no offsets of the search centers)
|
||||
|
||||
* After the inputs are specified, run the module as below
|
||||
|
||||
obj.preprocess_filt_XXX() or obj.preprocess_db()
|
||||
obj.uniform_data_type()
|
||||
obj.runAutorift()
|
||||
|
||||
where "XXX" can be "wal" for the Wallis filter, "hps" for the trivial high-pass filter, "sob" for the Sobel filter, "lap" for the Laplacian filter, and also a logarithmic operator without filtering is adopted for occasions where low-frequency components (i.e. topography) are desired, i.e. "obj.preprocess_db()".
|
||||
|
||||
* The "autoRIFT" object has the following four outputs:
|
||||
|
||||
------------------output------------------
|
||||
Dx [units = decimal image pixels] estimated horizontal pixel displacement
|
||||
Dy [units = decimal image pixels] estimated vertical pixel displacement
|
||||
InterpMask [unitless; boolean data type] light interpolation mask
|
||||
ChipSizeX [units = integer image pixels] iteratively progressive chip size in horizontal direction (different chip size allowed for vertical)
|
||||
|
||||
* The "autoRIFT" object has many parameters that can be flexibly tweaked by the users for their own purpose (listed below; can also be obtained by referring to "geo_autoRIFT/autoRIFT/autoRIFT_ISCE.py"):
|
||||
|
||||
------------------parameter list: general function------------------
|
||||
ChipSizeMinX [units = integer image pixels] Minimum size (in horizontal direction) of the template (chip) to correlate (default = 32; could be scalar or array with same dimension as xGrid)
|
||||
ChipSizeMaxX [units = integer image pixels] Maximum size (in horizontal direction) of the template (chip) to correlate (default = 64; could be scalar or array with same dimension as xGrid)
|
||||
ChipSize0X [units = integer image pixels] Minimum acceptable size (in horizontal direction) of the template (chip) to correlate (default = 32)
|
||||
ScaleChipSizeY [unitless; integer data type] Scaling factor to get the vertically-directed chip size in reference to the horizontally-directed size (default = 1)
|
||||
SearchLimitX [units = integer image pixels] Range (in horizontal direction) to search for displacement in the source (default = 25; could be scalar or array with same dimension as xGrid; when provided in array, set its elements to 0 if excluded for finding displacement)
|
||||
SearchLimitY [units = integer image pixels] Range (in vertical direction) to search for displacement in the source (default = 25; could be scalar or array with same dimension as xGrid; when provided in array, set its elements to 0 if excluded for finding displacement)
|
||||
SkipSampleX [units = integer image pixels] Number of samples to skip between search windows in horizontal direction for automatically-created grid if not specified by the user (default = 32)
|
||||
SkipSampleY [units = integer image pixels] Number of lines to skip between search windows in vertical direction for automatically-created grid if not specified by the user (default = 32)
|
||||
minSearch [units = integer image pixels] Minimum search limit (default = 6)
|
||||
|
||||
------------------parameter list: about Normalized Displacement Coherence (NDC) filter ------------------
|
||||
FracValid Fraction of valid displacements (default = 8/25) to be multiplied by filter window size "FiltWidth^2" and then used for thresholding the number of chip displacements that have passed the "FracSearch" disparity filtering
|
||||
FracSearch Fraction of search limit used as threshold for disparity filtering of the chip displacement difference that is normalized by the search limit (default = 0.25)
|
||||
FiltWidth Disparity filter width (default = 5)
|
||||
Iter Number of iterations (default = 3)
|
||||
MadScalar Scalar to be multiplied by Mad used as threshold for disparity filtering of the chip displacement deviation from the median (default = 4)
|
||||
|
||||
------------------parameter list: miscellaneous------------------
|
||||
WallisFilterWidth Width of the filter to be used for the preprocessing (default = 21)
|
||||
fillFiltWidth Light interpolation filling filter width (default = 3)
|
||||
sparseSearchSampleRate downsampling rate for sparse search (default = 4)
|
||||
BuffDistanceC Buffer coarse correlation mask by this many pixels for use as fine search mask (default = 8)
|
||||
CoarseCorCutoff Coarse correlation search cutoff (default = 0.01)
|
||||
OverSampleRatio Factor for pyramid upsampling for sub-pixel level offset refinement (default = 16; can be scalar or Python dictionary for intelligent use, i.e. chip size-dependent, such as {ChipSize_1:OverSampleRatio_1,..., ChipSize_N:OverSampleRatio_N})
|
||||
DataTypeInput Image data type: 0 -> uint8, 1 -> float32 (default = 0)
|
||||
zeroMask Force the margin (no data) to zeros which is useful for Wallis-filter-preprocessed images (default = None; 1 for Wallis filter)
|
|
@ -34,4 +34,4 @@ autorift='autoRIFT/SConscript'
|
|||
SConscript(autorift)
|
||||
|
||||
geogrid='geogrid/SConscript'
|
||||
SConscript(geogrid)
|
||||
SConscript(geogrid)
|
|
@ -12,3 +12,5 @@ try:
|
|||
except ImportError:
|
||||
# this means ISCE support not available. Don't raise error. Allow standalone use
|
||||
pass
|
||||
|
||||
__version__ = '1.4.0'
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
# authority as may be required before exporting this software to any 'EAR99'
|
||||
# embargoed foreign country or citizen of those countries.
|
||||
#
|
||||
# Author: Yang Lei
|
||||
# Author: Yang Lei, Alex S. Gardner
|
||||
#
|
||||
# Note: this is based on the MATLAB code, "auto-RIFT", written by Alex Gardner,
|
||||
# Note: this is based on the MATLAB code, "auto-RIFT", written by Alex S. Gardner,
|
||||
# and has been translated to Python and further optimized.
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -105,7 +105,7 @@ class autoRIFT:
|
|||
#
|
||||
# self.I2 = (self.I2 - lp)
|
||||
|
||||
|
||||
|
||||
def preprocess_filt_hps(self):
|
||||
'''
|
||||
Do the pre processing using (orig - low-pass filter) = high-pass filter filter (3.9/5.3 min).
|
||||
|
@ -205,7 +205,7 @@ class autoRIFT:
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
def uniform_data_type(self):
|
||||
|
||||
import numpy as np
|
||||
|
@ -324,6 +324,35 @@ class autoRIFT:
|
|||
Dy.fill(np.nan)
|
||||
|
||||
Flag = 3
|
||||
|
||||
|
||||
if self.ChipSize0X > self.GridSpacingX:
|
||||
if np.mod(self.ChipSize0X,self.GridSpacingX) != 0:
|
||||
sys.exit('when GridSpacing < smallest allowable chip size (ChipSize0), ChipSize0 must be integer multiples of GridSpacing')
|
||||
else:
|
||||
ChipSize0_GridSpacing_oversample_ratio = int(self.ChipSize0X / self.GridSpacingX)
|
||||
else:
|
||||
ChipSize0_GridSpacing_oversample_ratio = 1
|
||||
|
||||
|
||||
DispFiltC = DISP_FILT()
|
||||
overlap_c = np.max((1 - self.sparseSearchSampleRate / ChipSize0_GridSpacing_oversample_ratio,0))
|
||||
DispFiltC.FracValid = self.FracValid * (1 - overlap_c) + overlap_c**2
|
||||
DispFiltC.FracSearch = self.FracSearch
|
||||
DispFiltC.FiltWidth = (self.FiltWidth - 1) * ChipSize0_GridSpacing_oversample_ratio + 1
|
||||
DispFiltC.Iter = self.Iter - 1
|
||||
DispFiltC.MadScalar = self.MadScalar
|
||||
DispFiltC.colfiltChunkSize = self.colfiltChunkSize
|
||||
|
||||
DispFiltF = DISP_FILT()
|
||||
overlap_f = 1 - 1 / ChipSize0_GridSpacing_oversample_ratio
|
||||
DispFiltF.FracValid = self.FracValid * (1 - overlap_f) + overlap_f**2
|
||||
DispFiltF.FracSearch = self.FracSearch
|
||||
DispFiltF.FiltWidth = (self.FiltWidth - 1) * ChipSize0_GridSpacing_oversample_ratio + 1
|
||||
DispFiltF.Iter = self.Iter
|
||||
DispFiltF.MadScalar = self.MadScalar
|
||||
DispFiltF.colfiltChunkSize = self.colfiltChunkSize
|
||||
|
||||
|
||||
for i in range(ChipSizeUniX.__len__()):
|
||||
|
||||
|
@ -342,13 +371,13 @@ class autoRIFT:
|
|||
yGrid0 = np.round(yGrid0)
|
||||
|
||||
M0 = (ChipSizeX == 0) & (self.ChipSizeMinX <= ChipSizeUniX[i]) & (self.ChipSizeMaxX >= ChipSizeUniX[i])
|
||||
M0 = colfilt(M0.copy(), (int(1/Scale*6), int(1/Scale*6)), 0)
|
||||
M0 = colfilt(M0.copy(), (int(1/Scale*6), int(1/Scale*6)), 0, self.colfiltChunkSize)
|
||||
M0 = cv2.resize(np.logical_not(M0).astype(np.uint8),dstShape[::-1],interpolation=cv2.INTER_NEAREST).astype(np.bool)
|
||||
|
||||
SearchLimitX0 = colfilt(self.SearchLimitX.copy(), (int(1/Scale), int(1/Scale)), 0) + colfilt(self.Dx0.copy(), (int(1/Scale), int(1/Scale)), 4)
|
||||
SearchLimitY0 = colfilt(self.SearchLimitY.copy(), (int(1/Scale), int(1/Scale)), 0) + colfilt(self.Dy0.copy(), (int(1/Scale), int(1/Scale)), 4)
|
||||
Dx00 = colfilt(self.Dx0.copy(), (int(1/Scale), int(1/Scale)), 2)
|
||||
Dy00 = colfilt(self.Dy0.copy(), (int(1/Scale), int(1/Scale)), 2)
|
||||
SearchLimitX0 = colfilt(self.SearchLimitX.copy(), (int(1/Scale), int(1/Scale)), 0, self.colfiltChunkSize) + colfilt(self.Dx0.copy(), (int(1/Scale), int(1/Scale)), 4, self.colfiltChunkSize)
|
||||
SearchLimitY0 = colfilt(self.SearchLimitY.copy(), (int(1/Scale), int(1/Scale)), 0, self.colfiltChunkSize) + colfilt(self.Dy0.copy(), (int(1/Scale), int(1/Scale)), 4, self.colfiltChunkSize)
|
||||
Dx00 = colfilt(self.Dx0.copy(), (int(1/Scale), int(1/Scale)), 2, self.colfiltChunkSize)
|
||||
Dy00 = colfilt(self.Dy0.copy(), (int(1/Scale), int(1/Scale)), 2, self.colfiltChunkSize)
|
||||
|
||||
SearchLimitX0 = np.ceil(cv2.resize(SearchLimitX0,dstShape[::-1]))
|
||||
SearchLimitY0 = np.ceil(cv2.resize(SearchLimitY0,dstShape[::-1]))
|
||||
|
@ -377,25 +406,25 @@ class autoRIFT:
|
|||
SearchLimitX0[(np.logical_not(idxZero)) & (SearchLimitX0 < self.minSearch)] = self.minSearch
|
||||
SearchLimitY0[(np.logical_not(idxZero)) & (SearchLimitY0 < self.minSearch)] = self.minSearch
|
||||
|
||||
if ((xGrid0.shape[0] - 2)/self.sparseSearchSampleRate < 5) | ((xGrid0.shape[1] - 2)/self.sparseSearchSampleRate < 5):
|
||||
if ((xGrid0.shape[0] - 2)/(self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio) < 5) | ((xGrid0.shape[1] - 2)/(self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio) < 5):
|
||||
Flag = 2
|
||||
return Flag
|
||||
|
||||
# Setup for coarse search: sparse sampling / resize
|
||||
rIdxC = slice(self.sparseSearchSampleRate-1,xGrid0.shape[0],self.sparseSearchSampleRate)
|
||||
cIdxC = slice(self.sparseSearchSampleRate-1,xGrid0.shape[1],self.sparseSearchSampleRate)
|
||||
rIdxC = slice((self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio)-1,xGrid0.shape[0],(self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio))
|
||||
cIdxC = slice((self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio)-1,xGrid0.shape[1],(self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio))
|
||||
xGrid0C = xGrid0[rIdxC,cIdxC]
|
||||
yGrid0C = yGrid0[rIdxC,cIdxC]
|
||||
|
||||
# pdb.set_trace()
|
||||
|
||||
if np.remainder(self.sparseSearchSampleRate,2) == 0:
|
||||
filtWidth = self.sparseSearchSampleRate + 1
|
||||
if np.remainder((self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio),2) == 0:
|
||||
filtWidth = (self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio) + 1
|
||||
else:
|
||||
filtWidth = self.sparseSearchSampleRate
|
||||
filtWidth = (self.sparseSearchSampleRate * ChipSize0_GridSpacing_oversample_ratio)
|
||||
|
||||
SearchLimitX0C = colfilt(SearchLimitX0.copy(), (int(filtWidth), int(filtWidth)), 0)
|
||||
SearchLimitY0C = colfilt(SearchLimitY0.copy(), (int(filtWidth), int(filtWidth)), 0)
|
||||
SearchLimitX0C = colfilt(SearchLimitX0.copy(), (int(filtWidth), int(filtWidth)), 0, self.colfiltChunkSize)
|
||||
SearchLimitY0C = colfilt(SearchLimitY0.copy(), (int(filtWidth), int(filtWidth)), 0, self.colfiltChunkSize)
|
||||
SearchLimitX0C = SearchLimitX0C[rIdxC,cIdxC]
|
||||
SearchLimitY0C = SearchLimitY0C[rIdxC,cIdxC]
|
||||
|
||||
|
@ -426,14 +455,6 @@ class autoRIFT:
|
|||
# M0C is the mask for reliable estimates after coarse search, MC is the mask after disparity filtering, MC2 is the mask after area closing for fine search
|
||||
M0C = np.logical_not(np.isnan(DxC))
|
||||
|
||||
DispFiltC = DISP_FILT()
|
||||
if ChipSizeUniX[i] == ChipSizeUniX[0]:
|
||||
DispFiltC.FracValid = self.FracValid
|
||||
DispFiltC.FracSearch = self.FracSearch
|
||||
DispFiltC.FiltWidth = self.FiltWidth
|
||||
DispFiltC.Iter = self.Iter
|
||||
DispFiltC.MadScalar = self.MadScalar
|
||||
DispFiltC.Iter = DispFiltC.Iter - 1
|
||||
MC = DispFiltC.filtDisp(DxC.copy(), DyC.copy(), SearchLimitX0C.copy(), SearchLimitY0C.copy(), M0C.copy(), overSampleRatio)
|
||||
|
||||
MC[np.logical_not(M0C)] = False
|
||||
|
@ -444,7 +465,7 @@ class autoRIFT:
|
|||
continue
|
||||
|
||||
MC2 = ndimage.distance_transform_edt(np.logical_not(MC)) < self.BuffDistanceC
|
||||
dstShape = (int(MC2.shape[0]*self.sparseSearchSampleRate),int(MC2.shape[1]*self.sparseSearchSampleRate))
|
||||
dstShape = (int(MC2.shape[0]*(self.sparseSearchSampleRate*ChipSize0_GridSpacing_oversample_ratio)),int(MC2.shape[1]*(self.sparseSearchSampleRate*ChipSize0_GridSpacing_oversample_ratio)))
|
||||
|
||||
MC2 = cv2.resize(MC2.astype(np.uint8),dstShape[::-1],interpolation=cv2.INTER_NEAREST).astype(np.bool)
|
||||
# pdb.set_trace()
|
||||
|
@ -473,14 +494,6 @@ class autoRIFT:
|
|||
|
||||
# pdb.set_trace()
|
||||
|
||||
DispFiltF = DISP_FILT()
|
||||
if ChipSizeUniX[i] == ChipSizeUniX[0]:
|
||||
DispFiltF.FracValid = self.FracValid
|
||||
DispFiltF.FracSearch = self.FracSearch
|
||||
DispFiltF.FiltWidth = self.FiltWidth
|
||||
DispFiltF.Iter = self.Iter
|
||||
DispFiltF.MadScalar = self.MadScalar
|
||||
|
||||
|
||||
M0 = DispFiltF.filtDisp(DxF.copy(), DyF.copy(), SearchLimitX0.copy(), SearchLimitY0.copy(), np.logical_not(np.isnan(DxF)), overSampleRatio)
|
||||
# pdb.set_trace()
|
||||
|
@ -488,8 +501,8 @@ class autoRIFT:
|
|||
DyF[np.logical_not(M0)] = np.nan
|
||||
|
||||
# Light interpolation with median filtered values: DxFM (filtered) and DxF (unfiltered)
|
||||
DxFM = colfilt(DxF.copy(), (self.fillFiltWidth, self.fillFiltWidth), 3)
|
||||
DyFM = colfilt(DyF.copy(), (self.fillFiltWidth, self.fillFiltWidth), 3)
|
||||
DxFM = colfilt(DxF.copy(), (self.fillFiltWidth, self.fillFiltWidth), 3, self.colfiltChunkSize)
|
||||
DyFM = colfilt(DyF.copy(), (self.fillFiltWidth, self.fillFiltWidth), 3, self.colfiltChunkSize)
|
||||
|
||||
# M0 is mask for original valid estimates, MF is mask for filled ones, MM is mask where filtered ones exist for filling
|
||||
MF = np.zeros(M0.shape, dtype=np.bool)
|
||||
|
@ -518,16 +531,16 @@ class autoRIFT:
|
|||
|
||||
# DxF0 (filtered) / Dx (unfiltered) is the result from earlier iterations, DxFM (filtered) / DxF (unfiltered) is that of the current iteration
|
||||
# first colfilt nans within 2-by-2 area (otherwise 1 nan will contaminate all 4 points)
|
||||
DxF0 = colfilt(Dx.copy(),(int(Scale+1),int(Scale+1)),2)
|
||||
DxF0 = colfilt(Dx.copy(),(int(Scale+1),int(Scale+1)),2, self.colfiltChunkSize)
|
||||
# then resize to half size using area (similar to averaging) to match the current iteration
|
||||
DxF0 = cv2.resize(DxF0,dstShape[::-1],interpolation=cv2.INTER_AREA)
|
||||
DyF0 = colfilt(Dy.copy(),(int(Scale+1),int(Scale+1)),2)
|
||||
DyF0 = colfilt(Dy.copy(),(int(Scale+1),int(Scale+1)),2, self.colfiltChunkSize)
|
||||
DyF0 = cv2.resize(DyF0,dstShape[::-1],interpolation=cv2.INTER_AREA)
|
||||
|
||||
# Note this DxFM is almost the same as DxFM (same variable) in the light interpolation (only slightly better); however, only small portion of it will be used later at locations specified by M0 and MF that are determined in the light interpolation. So even without the following two lines, the final Dx and Dy result is still the same.
|
||||
# to fill out all of the missing values in DxF
|
||||
DxFM = colfilt(DxF.copy(), (5,5), 3)
|
||||
DyFM = colfilt(DyF.copy(), (5,5), 3)
|
||||
DxFM = colfilt(DxF.copy(), (5,5), 3, self.colfiltChunkSize)
|
||||
DyFM = colfilt(DyF.copy(), (5,5), 3, self.colfiltChunkSize)
|
||||
|
||||
# fill the current-iteration result with previously determined reliable estimates that are not searched in the current iteration
|
||||
idx = np.isnan(DxF) & np.logical_not(np.isnan(DxF0))
|
||||
|
@ -567,7 +580,7 @@ class autoRIFT:
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
def runAutorift(self):
|
||||
'''
|
||||
quick processing routine which calls autorift main function (user can define their own way by mimicing the workflow here).
|
||||
|
@ -636,6 +649,7 @@ class autoRIFT:
|
|||
self.ChipSizeMinX = 32
|
||||
self.ChipSizeMaxX = 64
|
||||
self.ChipSize0X = 32
|
||||
self.GridSpacingX = 32
|
||||
self.ScaleChipSizeY = 1
|
||||
self.SearchLimitX = 25
|
||||
self.SearchLimitY = 25
|
||||
|
@ -645,10 +659,11 @@ class autoRIFT:
|
|||
self.minSearch = 6
|
||||
self.sparseSearchSampleRate = 4
|
||||
self.FracValid = 8/25
|
||||
self.FracSearch = 0.25
|
||||
self.FracSearch = 0.20
|
||||
self.FiltWidth = 5
|
||||
self.Iter = 3
|
||||
self.MadScalar = 4
|
||||
self.colfiltChunkSize = 4
|
||||
self.BuffDistanceC = 8
|
||||
self.CoarseCorCutoff = 0.01
|
||||
self.OverSampleRatio = 16
|
||||
|
@ -1095,7 +1110,8 @@ def arImgDisp_s(I1, I2, xGrid, yGrid, ChipSizeX, ChipSizeY, SearchLimitX, Search
|
|||
|
||||
import numpy as np
|
||||
from . import autoriftcore
|
||||
|
||||
import multiprocessing as mp
|
||||
|
||||
core = AUTO_RIFT_CORE()
|
||||
if core._autoriftcore is not None:
|
||||
autoriftcore.destroyAutoRiftCore_Py(core._autoriftcore)
|
||||
|
@ -1333,44 +1349,93 @@ def arImgDisp_s(I1, I2, xGrid, yGrid, ChipSizeX, ChipSizeY, SearchLimitX, Search
|
|||
|
||||
|
||||
|
||||
def colfilt(A, kernelSize, option):
|
||||
|
||||
################## Chunked version of column filter
|
||||
def colfilt(A, kernelSize, option, chunkSize=4):
|
||||
|
||||
from skimage.util import view_as_windows as viewW
|
||||
import numpy as np
|
||||
|
||||
A = np.lib.pad(A,((int((kernelSize[0]-1)/2),int((kernelSize[0]-1)/2)),(int((kernelSize[1]-1)/2),int((kernelSize[1]-1)/2))),mode='constant',constant_values=np.nan)
|
||||
chunkInds = int(A.shape[1]/chunkSize)
|
||||
chunkRem = A.shape[1] - chunkSize * chunkInds
|
||||
|
||||
B = viewW(A, kernelSize).reshape(-1,kernelSize[0]*kernelSize[1]).T[:,::1]
|
||||
O = 0
|
||||
|
||||
output_size = (A.shape[0]-kernelSize[0]+1,A.shape[1]-kernelSize[1]+1)
|
||||
C = np.zeros(output_size,dtype=A.dtype)
|
||||
if option == 0:# max
|
||||
C = np.nanmax(B,axis=0).reshape(output_size)
|
||||
elif option == 1:# min
|
||||
C = np.nanmin(B,axis=0).reshape(output_size)
|
||||
elif option == 2:# mean
|
||||
C = np.nanmean(B,axis=0).reshape(output_size)
|
||||
elif option == 3:# median
|
||||
C = np.nanmedian(B,axis=0).reshape(output_size)
|
||||
elif option == 4:# range
|
||||
C = np.nanmax(B,axis=0).reshape(output_size) - np.nanmin(B,axis=0).reshape(output_size)
|
||||
elif option == 6:# MAD (Median Absolute Deviation)
|
||||
m = B.shape[0]
|
||||
D = np.abs(B - np.dot(np.ones((m,1),dtype=A.dtype), np.array([np.nanmedian(B,axis=0)])))
|
||||
C = np.nanmedian(D,axis=0).reshape(output_size)
|
||||
elif option[0] == 5:# displacement distance count with option[1] being the threshold
|
||||
m = B.shape[0]
|
||||
c = int(np.round((m + 1) / 2)-1)
|
||||
# c = 0
|
||||
D = np.abs(B - np.dot(np.ones((m,1),dtype=A.dtype), np.array([B[c,:]])))
|
||||
C = np.sum(D<option[1],axis=0).reshape(output_size)
|
||||
else:
|
||||
sys.exit('invalid option for columnwise neighborhood filtering')
|
||||
for ii in range(chunkSize):
|
||||
startInds = ii*chunkInds
|
||||
if ii == chunkSize-1:
|
||||
endInds = (ii+1)*chunkInds + chunkRem
|
||||
else:
|
||||
endInds = (ii+1)*chunkInds
|
||||
|
||||
if (ii == 0)&(ii == chunkSize-1):
|
||||
A1 = np.lib.pad(A[:,startInds:endInds],((int((kernelSize[0]-1)/2),int((kernelSize[0]-1)/2)),(int((kernelSize[1]-1)/2),int((kernelSize[1]-1)/2))),mode='constant',constant_values=np.nan)
|
||||
else:
|
||||
if ii == 0:
|
||||
A1 = np.lib.pad(A[:,startInds:np.min((endInds+int((kernelSize[1]-1)/2),A.shape[1]-1))],((int((kernelSize[0]-1)/2),int((kernelSize[0]-1)/2)),(int((kernelSize[1]-1)/2),np.max((0,endInds+int((kernelSize[1]-1)/2)-A.shape[1]+1)))),mode='constant',constant_values=np.nan)
|
||||
elif ii == chunkSize-1:
|
||||
A1 = np.lib.pad(A[:,np.max((0,startInds-int((kernelSize[1]-1)/2))):endInds],((int((kernelSize[0]-1)/2),int((kernelSize[0]-1)/2)),(np.max((0,0-startInds+int((kernelSize[1]-1)/2))),int((kernelSize[1]-1)/2))),mode='constant',constant_values=np.nan)
|
||||
else:
|
||||
A1 = np.lib.pad(A[:,np.max((0,startInds-int((kernelSize[1]-1)/2))):np.min((endInds+int((kernelSize[1]-1)/2),A.shape[1]-1))],((int((kernelSize[0]-1)/2),int((kernelSize[0]-1)/2)),(np.max((0,0-startInds+int((kernelSize[1]-1)/2))),np.max((0,endInds+int((kernelSize[1]-1)/2)-A.shape[1]+1)))),mode='constant',constant_values=np.nan)
|
||||
|
||||
C = C.astype(A.dtype)
|
||||
B = viewW(A1, kernelSize).reshape(-1,kernelSize[0]*kernelSize[1]).T[:,::1]
|
||||
|
||||
return C
|
||||
Adtype = A1.dtype
|
||||
Ashape = A1.shape
|
||||
del A1
|
||||
|
||||
output_size = (Ashape[0]-kernelSize[0]+1,Ashape[1]-kernelSize[1]+1)
|
||||
C = np.zeros((B.shape[1],),dtype=Adtype)
|
||||
|
||||
if option == 0:# max
|
||||
C = np.nanmax(B,axis=0)
|
||||
del B
|
||||
C = C.reshape(output_size)
|
||||
elif option == 1:# min
|
||||
C = np.nanmin(B,axis=0)
|
||||
del B
|
||||
C = C.reshape(output_size)
|
||||
elif option == 2:# mean
|
||||
C = np.nanmean(B,axis=0)
|
||||
del B
|
||||
C = C.reshape(output_size)
|
||||
elif option == 3:# median
|
||||
C = np.nanmedian(B,axis=0, overwrite_input=True)
|
||||
del B
|
||||
C = C.reshape(output_size)
|
||||
elif option == 4:# range
|
||||
C = np.nanmax(B,axis=0) - np.nanmin(B,axis=0)
|
||||
del B
|
||||
C = C.reshape(output_size)
|
||||
elif option == 6:# MAD (Median Absolute Deviation)
|
||||
m = B.shape[0]
|
||||
D = np.zeros((B.shape[1],),dtype=Adtype)
|
||||
D = np.nanmedian(B,axis=0)
|
||||
D = np.abs(B - np.dot(np.ones((m,1),dtype=Adtype), np.array([D])))
|
||||
del B
|
||||
C = np.nanmedian(D,axis=0, overwrite_input=True)
|
||||
del D
|
||||
C = C.reshape(output_size)
|
||||
elif option[0] == 5:# displacement distance count with option[1] being the threshold
|
||||
m = B.shape[0]
|
||||
c = int(np.round((m + 1) / 2)-1)
|
||||
# c = 0
|
||||
D = np.abs(B - np.dot(np.ones((m,1),dtype=Adtype), np.array([B[c,:]])))
|
||||
del B
|
||||
C = np.sum(D<option[1],axis=0)
|
||||
del D
|
||||
C = C.reshape(output_size)
|
||||
else:
|
||||
sys.exit('invalid option for columnwise neighborhood filtering')
|
||||
|
||||
C = C.astype(Adtype)
|
||||
|
||||
if np.isscalar(O):
|
||||
O = C.copy()
|
||||
else:
|
||||
O = np.append(O,C,axis=1)
|
||||
|
||||
return O
|
||||
|
||||
|
||||
|
||||
|
@ -1380,15 +1445,20 @@ class DISP_FILT:
|
|||
##filter parameters; try different parameters to decide how much fine-resolution estimates we keep, which can make the final images smoother
|
||||
|
||||
self.FracValid = 8/25
|
||||
self.FracSearch = 0.25
|
||||
self.FracSearch = 0.20
|
||||
self.FiltWidth = 5
|
||||
self.Iter = 3
|
||||
self.MadScalar = 4
|
||||
self.colfiltChunkSize = 4
|
||||
|
||||
|
||||
def filtDisp(self, Dx, Dy, SearchLimitX, SearchLimitY, M, OverSampleRatio):
|
||||
|
||||
import numpy as np
|
||||
|
||||
if np.mod(self.FiltWidth,2) == 0:
|
||||
sys.exit('NDC filter width must be an odd number')
|
||||
|
||||
dToleranceX = self.FracValid * self.FiltWidth**2
|
||||
dToleranceY = self.FracValid * self.FiltWidth**2
|
||||
# pdb.set_trace()
|
||||
|
@ -1403,8 +1473,8 @@ class DISP_FILT:
|
|||
for i in range(self.Iter):
|
||||
Dx[np.logical_not(M)] = np.nan
|
||||
Dy[np.logical_not(M)] = np.nan
|
||||
M = (colfilt(Dx.copy(), (self.FiltWidth, self.FiltWidth), (5,self.FracSearch)) >= dToleranceX) & (colfilt(Dy.copy(), (self.FiltWidth, self.FiltWidth), (5,self.FracSearch)) >= dToleranceY)
|
||||
|
||||
M = (colfilt(Dx.copy(), (self.FiltWidth, self.FiltWidth), (5,self.FracSearch), self.colfiltChunkSize) >= dToleranceX) & (colfilt(Dy.copy(), (self.FiltWidth, self.FiltWidth), (5,self.FracSearch), self.colfiltChunkSize) >= dToleranceY)
|
||||
|
||||
# if self.Iter == 3:
|
||||
# pdb.set_trace()
|
||||
|
||||
|
@ -1412,12 +1482,13 @@ class DISP_FILT:
|
|||
Dx[np.logical_not(M)] = np.nan
|
||||
Dy[np.logical_not(M)] = np.nan
|
||||
|
||||
DxMad = colfilt(Dx.copy(), (self.FiltWidth, self.FiltWidth), 6)
|
||||
DyMad = colfilt(Dy.copy(), (self.FiltWidth, self.FiltWidth), 6)
|
||||
|
||||
DxM = colfilt(Dx.copy(), (self.FiltWidth, self.FiltWidth), 3)
|
||||
DyM = colfilt(Dy.copy(), (self.FiltWidth, self.FiltWidth), 3)
|
||||
DxMad = colfilt(Dx.copy(), (self.FiltWidth, self.FiltWidth), 6, self.colfiltChunkSize)
|
||||
DyMad = colfilt(Dy.copy(), (self.FiltWidth, self.FiltWidth), 6, self.colfiltChunkSize)
|
||||
|
||||
DxM = colfilt(Dx.copy(), (self.FiltWidth, self.FiltWidth), 3, self.colfiltChunkSize)
|
||||
DyM = colfilt(Dy.copy(), (self.FiltWidth, self.FiltWidth), 3, self.colfiltChunkSize)
|
||||
|
||||
|
||||
M = (np.abs(Dx - DxM) <= np.maximum(self.MadScalar * DxMad, DxMadmin)) & (np.abs(Dy - DyM) <= np.maximum(self.MadScalar * DyMad, DyMadmin)) & M
|
||||
|
||||
return M
|
||||
|
@ -1442,5 +1513,3 @@ def bwareaopen(image,size1):
|
|||
return image
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -65,7 +65,14 @@ CHIP_SIZE_0X = Component.Parameter('ChipSize0X',
|
|||
default = 32,
|
||||
type = int,
|
||||
mandatory = False,
|
||||
doc = 'Minimum acceptable size (in X direction) of the reference data window to be used for correlation')
|
||||
doc = 'Minimum acceptable size (in X direction) of the reference data window to be used for correlation without resampling the grid; if a chip size greater than this value is provided, need to resize the sampling grid')
|
||||
|
||||
GRID_SPACING_X = Component.Parameter('GridSpacingX',
|
||||
public_name='GRID_SPACING_X',
|
||||
default = 32,
|
||||
type = int,
|
||||
mandatory = False,
|
||||
doc = 'Spacing (in X direction) of the sampling grid')
|
||||
|
||||
SCALE_CHIP_SIZE_Y = Component.Parameter('ScaleChipSizeY',
|
||||
public_name='SCALE_CHIP_SIZE_Y',
|
||||
|
@ -132,7 +139,7 @@ FRAC_VALID = Component.Parameter('FracValid',
|
|||
|
||||
FRAC_SEARCH = Component.Parameter('FracSearch',
|
||||
public_name = 'FRAC_SEARCH',
|
||||
default = 0.25,
|
||||
default = 0.20,
|
||||
type = float,
|
||||
mandatory=False,
|
||||
doc = 'Fraction of search')
|
||||
|
@ -158,6 +165,13 @@ MAD_SCALAR = Component.Parameter('MadScalar',
|
|||
mandatory=False,
|
||||
doc = 'Mad Scalar')
|
||||
|
||||
COLFILT_CHUNK_SIZE = Component.Parameter('colfiltChunkSize',
|
||||
public_name = 'COLFILT_CHUNK_SIZE',
|
||||
default = 4,
|
||||
type = int,
|
||||
mandatory=False,
|
||||
doc = 'column filter chunk size')
|
||||
|
||||
BUFF_DISTANCE_C = Component.Parameter('BuffDistanceC',
|
||||
public_name = 'BUFF_DISTANCE_C',
|
||||
default = 8,
|
||||
|
@ -214,6 +228,7 @@ class autoRIFT_ISCE(autoRIFT, Component):
|
|||
CHIP_SIZE_MIN_X,
|
||||
CHIP_SIZE_MAX_X,
|
||||
CHIP_SIZE_0X,
|
||||
GRID_SPACING_X,
|
||||
SCALE_CHIP_SIZE_Y,
|
||||
SEARCH_LIMIT_X,
|
||||
SEARCH_LIMIT_Y,
|
||||
|
@ -227,6 +242,7 @@ class autoRIFT_ISCE(autoRIFT, Component):
|
|||
FILT_WIDTH,
|
||||
ITER,
|
||||
MAD_SCALAR,
|
||||
COLFILT_CHUNK_SIZE,
|
||||
BUFF_DISTANCE_C,
|
||||
COARSE_COR_CUTOFF,
|
||||
OVER_SAMPLE_RATIO,
|
||||
|
|
|
@ -63,12 +63,35 @@ class Geogrid(Component):
|
|||
##Create and set parameters
|
||||
self.setState()
|
||||
|
||||
##check parameters
|
||||
self.checkState()
|
||||
|
||||
##Run
|
||||
geogrid.geogrid_Py(self._geogrid)
|
||||
self.get_center_latlon()
|
||||
|
||||
##Get parameters
|
||||
self.getState()
|
||||
|
||||
##Clean up
|
||||
self.finalize()
|
||||
|
||||
def get_center_latlon(self):
|
||||
'''
|
||||
Get center lat/lon of the image.
|
||||
'''
|
||||
from osgeo import gdal
|
||||
self.epsg = 4326
|
||||
self.determineBbox()
|
||||
if gdal.__version__[0] == '2':
|
||||
self.cen_lat = (self._ylim[0] + self._ylim[1]) / 2
|
||||
self.cen_lon = (self._xlim[0] + self._xlim[1]) / 2
|
||||
else:
|
||||
self.cen_lon = (self._ylim[0] + self._ylim[1]) / 2
|
||||
self.cen_lat = (self._xlim[0] + self._xlim[1]) / 2
|
||||
print("Scene-center lat/lon: " + str(self.cen_lat) + " " + str(self.cen_lon))
|
||||
|
||||
|
||||
def getProjectionSystem(self):
|
||||
'''
|
||||
Testing with Greenland.
|
||||
|
@ -77,10 +100,7 @@ class Geogrid(Component):
|
|||
raise Exception('At least the DEM parameter must be set for geogrid')
|
||||
|
||||
from osgeo import gdal, osr
|
||||
if self.urlflag == 1:
|
||||
ds = gdal.Open('/vsicurl/%s' %(self.demname))
|
||||
else:
|
||||
ds = gdal.Open(self.demname, gdal.GA_ReadOnly)
|
||||
ds = gdal.Open(self.demname, gdal.GA_ReadOnly)
|
||||
srs = osr.SpatialReference()
|
||||
srs.ImportFromWkt(ds.GetProjection())
|
||||
srs.AutoIdentifyEPSG()
|
||||
|
@ -96,10 +116,7 @@ class Geogrid(Component):
|
|||
else:
|
||||
raise Exception('Non-standard coordinate system encountered')
|
||||
if not epsgstr: #Empty string->use shell command gdalsrsinfo for last trial
|
||||
if self.urlflag == 1:
|
||||
cmd = 'gdalsrsinfo -o epsg /vsicurl/{0}'.format(self.demname)
|
||||
else:
|
||||
cmd = 'gdalsrsinfo -o epsg {0}'.format(self.demname)
|
||||
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]
|
||||
|
@ -219,7 +236,6 @@ class Geogrid(Component):
|
|||
|
||||
self.incidenceAngle = np.mean(thetas)
|
||||
|
||||
|
||||
def getDEM(self, bbox):
|
||||
'''
|
||||
Look up database and return values.
|
||||
|
@ -227,6 +243,16 @@ class Geogrid(Component):
|
|||
|
||||
return "", "", "", "", ""
|
||||
|
||||
def getState(self):
|
||||
from components.contrib.geo_autoRIFT.geogrid import geogrid
|
||||
|
||||
self.pOff = geogrid.getXOff_Py(self._geogrid)
|
||||
self.lOff = geogrid.getYOff_Py(self._geogrid)
|
||||
self.pCount = geogrid.getXCount_Py(self._geogrid)
|
||||
self.lCount = geogrid.getYCount_Py(self._geogrid)
|
||||
self.X_res = geogrid.getXPixelSize_Py(self._geogrid)
|
||||
self.Y_res = geogrid.getYPixelSize_Py(self._geogrid)
|
||||
|
||||
def setState(self):
|
||||
'''
|
||||
Create C object and populate.
|
||||
|
@ -242,10 +268,16 @@ class Geogrid(Component):
|
|||
geogrid.setRangeParameters_Py( self._geogrid, self.startingRange, self.rangePixelSize)
|
||||
geogrid.setAzimuthParameters_Py( self._geogrid, DTU.seconds_since_midnight(self.sensingStart), self.prf)
|
||||
geogrid.setRepeatTime_Py(self._geogrid, self.repeatTime)
|
||||
|
||||
geogrid.setDtUnity_Py( self._geogrid, self.srs_dt_unity)
|
||||
geogrid.setMaxFactor_Py( self._geogrid, self.srs_max_scale)
|
||||
geogrid.setUpperThreshold_Py( self._geogrid, self.srs_max_search)
|
||||
geogrid.setLowerThreshold_Py(self._geogrid, self.srs_min_search)
|
||||
|
||||
geogrid.setEPSG_Py(self._geogrid, self.epsg)
|
||||
geogrid.setIncidenceAngle_Py(self._geogrid, self.incidenceAngle)
|
||||
geogrid.setChipSizeX0_Py(self._geogrid, self.chipSizeX0)
|
||||
geogrid.setGridSpacingX_Py(self._geogrid, self.gridSpacingX)
|
||||
|
||||
geogrid.setXLimits_Py(self._geogrid, self._xlim[0], self._xlim[1])
|
||||
geogrid.setYLimits_Py(self._geogrid, self._ylim[0], self._ylim[1])
|
||||
|
@ -280,13 +312,17 @@ class Geogrid(Component):
|
|||
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)
|
||||
|
||||
def checkState(self):
|
||||
'''
|
||||
Create C object and populate.
|
||||
'''
|
||||
if self.repeatTime < 0:
|
||||
raise Exception('Input image 1 must be older than input image 2')
|
||||
|
||||
def finalize(self):
|
||||
'''
|
||||
Clean up all the C pointers.
|
||||
|
@ -316,6 +352,7 @@ class Geogrid(Component):
|
|||
self.repeatTime = None
|
||||
self.incidenceAngle = None
|
||||
self.chipSizeX0 = None
|
||||
self.gridSpacingX = None
|
||||
|
||||
##Input related parameters
|
||||
self.demname = None
|
||||
|
@ -330,8 +367,7 @@ class Geogrid(Component):
|
|||
self.csmaxxname = None
|
||||
self.csmaxyname = None
|
||||
self.ssmname = None
|
||||
self.urlflag = None
|
||||
|
||||
|
||||
##Output related parameters
|
||||
self.winlocname = None
|
||||
self.winoffname = None
|
||||
|
@ -341,8 +377,12 @@ class Geogrid(Component):
|
|||
self.winssmname = None
|
||||
self.winro2vxname = None
|
||||
self.winro2vyname = None
|
||||
|
||||
|
||||
|
||||
##dt-varying search range scale (srs) rountine parameters
|
||||
self.srs_dt_unity = 182
|
||||
self.srs_max_scale = 5
|
||||
self.srs_max_search = 20000
|
||||
self.srs_min_search = 0
|
||||
|
||||
##Coordinate system
|
||||
self.epsg = None
|
||||
|
@ -353,3 +393,11 @@ class Geogrid(Component):
|
|||
##Pointer to C
|
||||
self._geogrid = None
|
||||
self._orbit = None
|
||||
|
||||
##parameters for autoRIFT
|
||||
self.pOff = None
|
||||
self.lOff = None
|
||||
self.pCount = None
|
||||
self.lCount = None
|
||||
self.X_res = None
|
||||
self.Y_res = None
|
||||
|
|
|
@ -46,20 +46,51 @@ class GeogridOptical():
|
|||
'''
|
||||
Do the actual processing.
|
||||
'''
|
||||
|
||||
from . import geogridOptical
|
||||
|
||||
##Determine appropriate EPSG system
|
||||
self.epsgDem = self.getProjectionSystem(self.demname, self.urlflag)
|
||||
self.epsgDat = self.getProjectionSystem(self.dat1name, self.urlflag)
|
||||
|
||||
self.epsgDem = self.getProjectionSystem(self.demname)
|
||||
self.epsgDat = self.getProjectionSystem(self.dat1name)
|
||||
|
||||
###Determine extent of data needed
|
||||
bbox = self.determineBbox()
|
||||
|
||||
|
||||
##Create and set parameters
|
||||
self.setState()
|
||||
|
||||
##check parameters
|
||||
self.checkState()
|
||||
|
||||
##Run
|
||||
self.geogrid()
|
||||
geogridOptical.geogridOptical_Py(self._geogridOptical)
|
||||
self.get_center_latlon()
|
||||
|
||||
##Get parameters
|
||||
self.getState()
|
||||
|
||||
##Clean up
|
||||
self.finalize()
|
||||
|
||||
def get_center_latlon(self):
|
||||
'''
|
||||
Get center lat/lon of the image.
|
||||
'''
|
||||
from osgeo import gdal
|
||||
gdal.AllRegister()
|
||||
self.epsgDem = 4326
|
||||
self.epsgDat = self.getProjectionSystem(self.dat1name)
|
||||
self.determineBbox()
|
||||
if gdal.__version__[0] == '2':
|
||||
self.cen_lat = (self._ylim[0] + self._ylim[1]) / 2
|
||||
self.cen_lon = (self._xlim[0] + self._xlim[1]) / 2
|
||||
else:
|
||||
self.cen_lon = (self._ylim[0] + self._ylim[1]) / 2
|
||||
self.cen_lat = (self._xlim[0] + self._xlim[1]) / 2
|
||||
print("Scene-center lat/lon: " + str(self.cen_lat) + " " + str(self.cen_lon))
|
||||
|
||||
|
||||
|
||||
def getProjectionSystem(self, filename, urlflag):
|
||||
def getProjectionSystem(self, filename):
|
||||
'''
|
||||
Testing with Greenland.
|
||||
'''
|
||||
|
@ -67,10 +98,7 @@ class GeogridOptical():
|
|||
raise Exception('File {0} does not exist'.format(filename))
|
||||
|
||||
from osgeo import gdal, osr
|
||||
if urlflag == 1:
|
||||
ds = gdal.Open('/vsicurl/%s' %(filename))
|
||||
else:
|
||||
ds = gdal.Open(filename, gdal.GA_ReadOnly)
|
||||
ds = gdal.Open(filename, gdal.GA_ReadOnly)
|
||||
srs = osr.SpatialReference()
|
||||
srs.ImportFromWkt(ds.GetProjection())
|
||||
srs.AutoIdentifyEPSG()
|
||||
|
@ -86,10 +114,7 @@ class GeogridOptical():
|
|||
else:
|
||||
raise Exception('Non-standard coordinate system encountered')
|
||||
if not epsgstr: #Empty string->use shell command gdalsrsinfo for last trial
|
||||
if urlflag == 1:
|
||||
cmd = 'gdalsrsinfo -o epsg /vsicurl/{0}'.format(filename)
|
||||
else:
|
||||
cmd = 'gdalsrsinfo -o epsg {0}'.format(filename)
|
||||
cmd = 'gdalsrsinfo -o epsg {0}'.format(filename)
|
||||
epsgstr = subprocess.check_output(cmd, shell=True)
|
||||
# pdb.set_trace()
|
||||
epsgstr = re.findall("EPSG:(\d+)", str(epsgstr))[0]
|
||||
|
@ -108,31 +133,31 @@ class GeogridOptical():
|
|||
import numpy as np
|
||||
import datetime
|
||||
from osgeo import osr
|
||||
|
||||
|
||||
# import pdb
|
||||
# pdb.set_trace()
|
||||
|
||||
|
||||
samples = self.startingX + np.array([0, self.numberOfSamples]) * self.XSize
|
||||
lines = self.startingY + np.array([0, self.numberOfLines]) * self.YSize
|
||||
samples = self.startingX + np.array([0, self.numberOfSamples-1]) * self.XSize
|
||||
lines = self.startingY + np.array([0, self.numberOfLines-1]) * self.YSize
|
||||
|
||||
coordDat = osr.SpatialReference()
|
||||
if self.epsgDat:
|
||||
coordDat.ImportFromEPSG(self.epsgDat)
|
||||
else:
|
||||
raise Exception('EPSG code does not exist for image data')
|
||||
|
||||
|
||||
|
||||
coordDem = osr.SpatialReference()
|
||||
if self.epsgDem:
|
||||
coordDem.ImportFromEPSG(self.epsgDem)
|
||||
else:
|
||||
raise Exception('EPSG code does not exist for DEM')
|
||||
|
||||
|
||||
|
||||
|
||||
trans = osr.CoordinateTransformation(coordDat, coordDem)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
utms = []
|
||||
xyzs = []
|
||||
|
@ -152,669 +177,151 @@ class GeogridOptical():
|
|||
self._xlim = [np.min(xyzs[:,0]), np.max(xyzs[:,0])]
|
||||
self._ylim = [np.min(xyzs[:,1]), np.max(xyzs[:,1])]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def getState(self):
|
||||
|
||||
from . import geogridOptical
|
||||
|
||||
self.pOff = geogridOptical.getXOff_Py(self._geogridOptical)
|
||||
self.lOff = geogridOptical.getYOff_Py(self._geogridOptical)
|
||||
self.pCount = geogridOptical.getXCount_Py(self._geogridOptical)
|
||||
self.lCount = geogridOptical.getYCount_Py(self._geogridOptical)
|
||||
self.X_res = geogridOptical.getXPixelSize_Py(self._geogridOptical)
|
||||
self.Y_res = geogridOptical.getYPixelSize_Py(self._geogridOptical)
|
||||
|
||||
def setState(self):
|
||||
'''
|
||||
Create C object and populate.
|
||||
'''
|
||||
|
||||
from . import geogridOptical
|
||||
|
||||
if self._geogridOptical is not None:
|
||||
geogridOptical.destroyGeoGridOptical_Py(self._geogridOptical)
|
||||
|
||||
def geogrid(self):
|
||||
self._geogridOptical = geogridOptical.createGeoGridOptical_Py()
|
||||
geogridOptical.setOpticalImageDimensions_Py( self._geogridOptical, self.numberOfSamples, self.numberOfLines)
|
||||
geogridOptical.setXParameters_Py( self._geogridOptical, self.startingX, self.XSize)
|
||||
geogridOptical.setYParameters_Py( self._geogridOptical, self.startingY, self.YSize)
|
||||
geogridOptical.setRepeatTime_Py(self._geogridOptical, self.repeatTime)
|
||||
|
||||
# For now print inputs that were obtained
|
||||
geogridOptical.setDtUnity_Py( self._geogridOptical, self.srs_dt_unity)
|
||||
geogridOptical.setMaxFactor_Py( self._geogridOptical, self.srs_max_scale)
|
||||
geogridOptical.setUpperThreshold_Py( self._geogridOptical, self.srs_max_search)
|
||||
geogridOptical.setLowerThreshold_Py(self._geogridOptical, self.srs_min_search)
|
||||
|
||||
urlflag = self.urlflag
|
||||
geogridOptical.setEPSG_Py(self._geogridOptical, self.epsgDem, self.epsgDat)
|
||||
geogridOptical.setChipSizeX0_Py(self._geogridOptical, self.chipSizeX0)
|
||||
geogridOptical.setGridSpacingX_Py(self._geogridOptical, self.gridSpacingX)
|
||||
|
||||
geogridOptical.setXLimits_Py(self._geogridOptical, self._xlim[0], self._xlim[1])
|
||||
geogridOptical.setYLimits_Py(self._geogridOptical, self._ylim[0], self._ylim[1])
|
||||
if self.demname:
|
||||
geogridOptical.setDEM_Py(self._geogridOptical, self.demname)
|
||||
|
||||
if (self.dhdxname is not None) and (self.dhdyname is not None):
|
||||
geogridOptical.setSlopes_Py(self._geogridOptical, self.dhdxname, self.dhdyname)
|
||||
|
||||
if (self.vxname is not None) and (self.vyname is not None):
|
||||
geogridOptical.setVelocities_Py(self._geogridOptical, self.vxname, self.vyname)
|
||||
|
||||
if (self.srxname is not None) and (self.sryname is not None):
|
||||
geogridOptical.setSearchRange_Py(self._geogridOptical, self.srxname, self.sryname)
|
||||
|
||||
if (self.csminxname is not None) and (self.csminyname is not None):
|
||||
geogridOptical.setChipSizeMin_Py(self._geogridOptical, self.csminxname, self.csminyname)
|
||||
|
||||
if (self.csmaxxname is not None) and (self.csmaxyname is not None):
|
||||
geogridOptical.setChipSizeMax_Py(self._geogridOptical, self.csmaxxname, self.csmaxyname)
|
||||
|
||||
if (self.ssmname is not None):
|
||||
geogridOptical.setStableSurfaceMask_Py(self._geogridOptical, self.ssmname)
|
||||
|
||||
geogridOptical.setWindowLocationsFilename_Py( self._geogridOptical, self.winlocname)
|
||||
geogridOptical.setWindowOffsetsFilename_Py( self._geogridOptical, self.winoffname)
|
||||
geogridOptical.setWindowSearchRangeFilename_Py( self._geogridOptical, self.winsrname)
|
||||
geogridOptical.setWindowChipSizeMinFilename_Py( self._geogridOptical, self.wincsminname)
|
||||
geogridOptical.setWindowChipSizeMaxFilename_Py( self._geogridOptical, self.wincsmaxname)
|
||||
geogridOptical.setWindowStableSurfaceMaskFilename_Py( self._geogridOptical, self.winssmname)
|
||||
geogridOptical.setRO2VXFilename_Py( self._geogridOptical, self.winro2vxname)
|
||||
geogridOptical.setRO2VYFilename_Py( self._geogridOptical, self.winro2vyname)
|
||||
geogridOptical.setNodataOut_Py(self._geogridOptical, self.nodata_out)
|
||||
|
||||
if urlflag == 1:
|
||||
print("\nReading input images into memory directly from URL's")
|
||||
else:
|
||||
print("\nReading input images locally from files")
|
||||
|
||||
print("\nOptical Image parameters: ")
|
||||
print("X-direction coordinate: " + str(self.startingX) + " " + str(self.XSize))
|
||||
print("Y-direction coordinate: " + str(self.startingY) + " " + str(self.YSize))
|
||||
print("Dimensions: " + str(self.numberOfSamples) + " " + str(self.numberOfLines) + "\n")
|
||||
def checkState(self):
|
||||
'''
|
||||
Create C object and populate.
|
||||
'''
|
||||
if self.repeatTime < 0:
|
||||
raise Exception('Input image 1 must be older than input image 2')
|
||||
|
||||
|
||||
def finalize(self):
|
||||
'''
|
||||
Clean up all the C pointers.
|
||||
'''
|
||||
|
||||
from . import geogridOptical
|
||||
|
||||
print("Map inputs: ")
|
||||
print("EPSG: " + str(self.epsgDem))
|
||||
print("Smallest Allowable Chip Size in m: " + str(self.chipSizeX0))
|
||||
print("Repeat Time: " + str(self.repeatTime))
|
||||
print("XLimits: " + str(self._xlim[0]) + " " + str(self._xlim[1]))
|
||||
print("YLimits: " + str(self._ylim[0]) + " " + str(self._ylim[1]))
|
||||
print("Extent in km: " + str((self._xlim[1]-self._xlim[0])/1000.0) + " " + str((self._ylim[1]-self._ylim[0])/1000.0))
|
||||
if (self.demname != ""):
|
||||
print("DEM: " + str(self.demname))
|
||||
if (self.dhdxname != ""):
|
||||
print("Slopes: " + str(self.dhdxname) + " " + str(self.dhdyname))
|
||||
if (self.vxname != ""):
|
||||
print("Velocities: " + str(self.vxname) + " " + str(self.vyname))
|
||||
if (self.srxname != ""):
|
||||
print("Search Range: " + str(self.srxname) + " " + str(self.sryname))
|
||||
if (self.csminxname != ""):
|
||||
print("Chip Size Min: " + str(self.csminxname) + " " + str(self.csminyname))
|
||||
if (self.csmaxxname != ""):
|
||||
print("Chip Size Max: " + str(self.csmaxxname) + " " + str(self.csmaxyname))
|
||||
if (self.ssmname != ""):
|
||||
print("Stable Surface Mask: " + str(self.ssmname))
|
||||
geogridOptical.destroyGeoGridOptical_Py(self._geogridOptical)
|
||||
self._geogridOptical = None
|
||||
|
||||
|
||||
print("\nOutputs: ")
|
||||
|
||||
print("Window locations: " + str(self.winlocname))
|
||||
|
||||
if (self.dhdxname != ""):
|
||||
if (self.vxname != ""):
|
||||
print("Window offsets: " + str(self.winoffname))
|
||||
|
||||
print("Window rdr_off2vel_x vector: " + str(self.winro2vxname))
|
||||
print("Window rdr_off2vel_y vector: " + str(self.winro2vyname))
|
||||
|
||||
if (self.srxname != ""):
|
||||
print("Window search range: " + str(self.winsrname))
|
||||
|
||||
if (self.csminxname != ""):
|
||||
print("Window chip size min: " + str(self.wincsminname))
|
||||
if (self.csmaxxname != ""):
|
||||
print("Window chip size max: " + str(self.wincsmaxname))
|
||||
if (self.ssmname != ""):
|
||||
print("Window stable surface mask: " + str(self.winssmname))
|
||||
|
||||
print("Output Nodata Value: " + str(self.nodata_out) + "\n")
|
||||
|
||||
|
||||
|
||||
print("Starting processing .... ")
|
||||
|
||||
|
||||
|
||||
|
||||
from osgeo import gdal, osr
|
||||
import numpy as np
|
||||
import struct
|
||||
|
||||
# pdb.set_trace()
|
||||
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 != ""):
|
||||
sxDS = gdal.Open(self.dhdxname, gdal.GA_ReadOnly)
|
||||
syDS = gdal.Open(self.dhdyname, gdal.GA_ReadOnly)
|
||||
|
||||
if (self.vxname != ""):
|
||||
vxDS = gdal.Open(self.vxname, gdal.GA_ReadOnly)
|
||||
vyDS = gdal.Open(self.vyname, gdal.GA_ReadOnly)
|
||||
|
||||
if (self.srxname != ""):
|
||||
srxDS = gdal.Open(self.srxname, gdal.GA_ReadOnly)
|
||||
sryDS = gdal.Open(self.sryname, gdal.GA_ReadOnly)
|
||||
|
||||
if (self.csminxname != ""):
|
||||
csminxDS = gdal.Open(self.csminxname, gdal.GA_ReadOnly)
|
||||
csminyDS = gdal.Open(self.csminyname, gdal.GA_ReadOnly)
|
||||
|
||||
if (self.csmaxxname != ""):
|
||||
csmaxxDS = gdal.Open(self.csmaxxname, gdal.GA_ReadOnly)
|
||||
csmaxyDS = gdal.Open(self.csmaxyname, gdal.GA_ReadOnly)
|
||||
|
||||
if (self.ssmname != ""):
|
||||
ssmDS = gdal.Open(self.ssmname, gdal.GA_ReadOnly)
|
||||
|
||||
if demDS is None:
|
||||
raise Exception('Error opening DEM file {0}'.format(self.demname))
|
||||
|
||||
if (self.dhdxname != ""):
|
||||
if (sxDS is None):
|
||||
raise Exception('Error opening x-direction slope file {0}'.format(self.dhdxname))
|
||||
if (syDS is None):
|
||||
raise Exception('Error opening y-direction slope file {0}'.format(self.dhdyname))
|
||||
|
||||
if (self.vxname != ""):
|
||||
if (vxDS is None):
|
||||
raise Exception('Error opening x-direction velocity file {0}'.format(self.vxname))
|
||||
if (vyDS is None):
|
||||
raise Exception('Error opening y-direction velocity file {0}'.format(self.vyname))
|
||||
|
||||
if (self.srxname != ""):
|
||||
if (srxDS is None):
|
||||
raise Exception('Error opening x-direction search range file {0}'.format(self.srxname))
|
||||
if (sryDS is None):
|
||||
raise Exception('Error opening y-direction search range file {0}'.format(self.sryname))
|
||||
|
||||
if (self.csminxname != ""):
|
||||
if (csminxDS is None):
|
||||
raise Exception('Error opening x-direction chip size min file {0}'.format(self.csminxname))
|
||||
if (csminyDS is None):
|
||||
raise Exception('Error opening y-direction chip size min file {0}'.format(self.csminyname))
|
||||
|
||||
if (self.csmaxxname != ""):
|
||||
if (csmaxxDS is None):
|
||||
raise Exception('Error opening x-direction chip size max file {0}'.format(self.csmaxxname))
|
||||
if (csmaxyDS is None):
|
||||
raise Exception('Error opening y-direction chip size max file {0}'.format(self.csmaxyname))
|
||||
|
||||
if (self.ssmname != ""):
|
||||
if (ssmDS is None):
|
||||
raise Exception('Error opening stable surface mask file {0}'.format(self.ssmname))
|
||||
|
||||
geoTrans = demDS.GetGeoTransform()
|
||||
demXSize = demDS.RasterXSize
|
||||
demYSize = demDS.RasterYSize
|
||||
|
||||
|
||||
# Get offsets and size to read from DEM
|
||||
lOff = int(np.max( [np.floor((self._ylim[1] - geoTrans[3])/geoTrans[5]), 0.]))
|
||||
# pdb.set_trace()
|
||||
lCount = int(np.min([ np.ceil((self._ylim[0] - geoTrans[3])/geoTrans[5]), demYSize-1.]) - lOff)
|
||||
|
||||
pOff = int(np.max([ np.floor((self._xlim[0] - geoTrans[0])/geoTrans[1]), 0.]))
|
||||
pCount = int(np.min([ np.ceil((self._xlim[1] - geoTrans[0])/geoTrans[1]), demXSize-1.]) - pOff)
|
||||
|
||||
print("Xlimits : " + str(geoTrans[0] + pOff * geoTrans[1]) + " " + str(geoTrans[0] + (pOff + pCount) * geoTrans[1]))
|
||||
|
||||
print("Ylimits : " + str(geoTrans[3] + (lOff + lCount) * geoTrans[5]) + " " + str(geoTrans[3] + lOff * geoTrans[5]))
|
||||
|
||||
print("Origin index (in DEM) of geogrid: " + str(pOff) + " " + str(lOff))
|
||||
|
||||
print("Dimensions of geogrid: " + str(pCount) + " x " + str(lCount))
|
||||
|
||||
projDem = osr.SpatialReference()
|
||||
if self.epsgDem:
|
||||
projDem.ImportFromEPSG(self.epsgDem)
|
||||
else:
|
||||
raise Exception('EPSG code does not exist for DEM')
|
||||
|
||||
projDat = osr.SpatialReference()
|
||||
if self.epsgDat:
|
||||
projDat.ImportFromEPSG(self.epsgDat)
|
||||
else:
|
||||
raise Exception('EPSG code does not exist for image data')
|
||||
|
||||
fwdTrans = osr.CoordinateTransformation(projDem, projDat)
|
||||
invTrans = osr.CoordinateTransformation(projDat, projDem)
|
||||
|
||||
if (self.vxname != ""):
|
||||
nodata = vxDS.GetRasterBand(1).GetNoDataValue()
|
||||
else:
|
||||
nodata = 0
|
||||
|
||||
nodata_out = self.nodata_out
|
||||
|
||||
|
||||
pszFormat = "GTiff"
|
||||
adfGeoTransform = ( geoTrans[0] + pOff * geoTrans[1], geoTrans[1], 0, geoTrans[3] + lOff * geoTrans[5], 0, geoTrans[5] )
|
||||
oSRS = osr.SpatialReference()
|
||||
pszSRS_WKT = projDem.ExportToWkt()
|
||||
|
||||
|
||||
|
||||
poDriver = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriver is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilename = self.winlocname
|
||||
poDstDS = poDriver.Create(pszDstFilename, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Int32)
|
||||
poDstDS.SetGeoTransform( adfGeoTransform )
|
||||
poDstDS.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1 = poDstDS.GetRasterBand(1)
|
||||
poBand2 = poDstDS.GetRasterBand(2)
|
||||
poBand1.SetNoDataValue(nodata_out)
|
||||
poBand2.SetNoDataValue(nodata_out)
|
||||
|
||||
|
||||
|
||||
if ((self.dhdxname != "")&(self.vxname != "")):
|
||||
poDriverOff = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverOff is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameOff = self.winoffname
|
||||
poDstDSOff = poDriverOff.Create(pszDstFilenameOff, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Int32)
|
||||
poDstDSOff.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSOff.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1Off = poDstDSOff.GetRasterBand(1)
|
||||
poBand2Off = poDstDSOff.GetRasterBand(2)
|
||||
poBand1Off.SetNoDataValue(nodata_out)
|
||||
poBand2Off.SetNoDataValue(nodata_out)
|
||||
|
||||
|
||||
if ((self.dhdxname != "")&(self.srxname != "")):
|
||||
poDriverSch = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverSch is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameSch = self.winsrname
|
||||
poDstDSSch = poDriverSch.Create(pszDstFilenameSch, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Int32)
|
||||
poDstDSSch.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSSch.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1Sch = poDstDSSch.GetRasterBand(1)
|
||||
poBand2Sch = poDstDSSch.GetRasterBand(2)
|
||||
poBand1Sch.SetNoDataValue(nodata_out)
|
||||
poBand2Sch.SetNoDataValue(nodata_out)
|
||||
|
||||
if (self.csminxname != ""):
|
||||
poDriverMin = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverMin is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameMin = self.wincsminname
|
||||
poDstDSMin = poDriverMin.Create(pszDstFilenameMin, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Int32)
|
||||
poDstDSMin.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSMin.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1Min = poDstDSMin.GetRasterBand(1)
|
||||
poBand2Min = poDstDSMin.GetRasterBand(2)
|
||||
poBand1Min.SetNoDataValue(nodata_out)
|
||||
poBand2Min.SetNoDataValue(nodata_out)
|
||||
|
||||
if (self.csmaxxname != ""):
|
||||
poDriverMax = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverMax is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameMax = self.wincsmaxname
|
||||
poDstDSMax = poDriverMax.Create(pszDstFilenameMax, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Int32)
|
||||
poDstDSMax.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSMax.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1Max = poDstDSMax.GetRasterBand(1)
|
||||
poBand2Max = poDstDSMax.GetRasterBand(2)
|
||||
poBand1Max.SetNoDataValue(nodata_out)
|
||||
poBand2Max.SetNoDataValue(nodata_out)
|
||||
|
||||
|
||||
if (self.ssmname != ""):
|
||||
poDriverMsk = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverMsk is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameMsk = self.winssmname
|
||||
poDstDSMsk = poDriverMsk.Create(pszDstFilenameMsk, xsize=pCount, ysize=lCount, bands=1, eType=gdal.GDT_Int32)
|
||||
poDstDSMsk.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSMsk.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1Msk = poDstDSMsk.GetRasterBand(1)
|
||||
poBand1Msk.SetNoDataValue(nodata_out)
|
||||
|
||||
|
||||
|
||||
|
||||
if (self.dhdxname != ""):
|
||||
poDriverRO2VX = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverRO2VX is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameRO2VX = self.winro2vxname
|
||||
poDstDSRO2VX = poDriverRO2VX.Create(pszDstFilenameRO2VX, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Float64)
|
||||
poDstDSRO2VX.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSRO2VX.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1RO2VX = poDstDSRO2VX.GetRasterBand(1)
|
||||
poBand2RO2VX = poDstDSRO2VX.GetRasterBand(2)
|
||||
poBand1RO2VX.SetNoDataValue(nodata_out)
|
||||
poBand2RO2VX.SetNoDataValue(nodata_out)
|
||||
|
||||
|
||||
poDriverRO2VY = gdal.GetDriverByName(pszFormat)
|
||||
if( poDriverRO2VY is None ):
|
||||
raise Exception('Cannot create gdal driver for output')
|
||||
|
||||
pszDstFilenameRO2VY = self.winro2vyname
|
||||
poDstDSRO2VY = poDriverRO2VY.Create(pszDstFilenameRO2VY, xsize=pCount, ysize=lCount, bands=2, eType=gdal.GDT_Float64)
|
||||
poDstDSRO2VY.SetGeoTransform( adfGeoTransform )
|
||||
poDstDSRO2VY.SetProjection( pszSRS_WKT )
|
||||
|
||||
poBand1RO2VY = poDstDSRO2VY.GetRasterBand(1)
|
||||
poBand2RO2VY = poDstDSRO2VY.GetRasterBand(2)
|
||||
poBand1RO2VY.SetNoDataValue(nodata_out)
|
||||
poBand2RO2VY.SetNoDataValue(nodata_out)
|
||||
|
||||
|
||||
|
||||
raster1 = np.zeros(pCount,dtype=np.int32)
|
||||
raster2 = np.zeros(pCount,dtype=np.int32)
|
||||
raster11 = np.zeros(pCount,dtype=np.int32)
|
||||
raster22 = np.zeros(pCount,dtype=np.int32)
|
||||
sr_raster11 = np.zeros(pCount,dtype=np.int32)
|
||||
sr_raster22 = np.zeros(pCount,dtype=np.int32)
|
||||
csmin_raster11 = np.zeros(pCount,dtype=np.int32)
|
||||
csmin_raster22 = np.zeros(pCount,dtype=np.int32)
|
||||
csmax_raster11 = np.zeros(pCount,dtype=np.int32)
|
||||
csmax_raster22 = np.zeros(pCount,dtype=np.int32)
|
||||
ssm_raster = np.zeros(pCount,dtype=np.int32)
|
||||
raster1a = np.zeros(pCount,dtype=np.float64)
|
||||
raster1b = np.zeros(pCount,dtype=np.float64)
|
||||
raster2a = np.zeros(pCount,dtype=np.float64)
|
||||
raster2b = np.zeros(pCount,dtype=np.float64)
|
||||
|
||||
|
||||
|
||||
# X- and Y-direction pixel size
|
||||
X_res = np.abs(self.XSize)
|
||||
Y_res = np.abs(self.YSize)
|
||||
print("X-direction pixel size: " + str(X_res))
|
||||
print("Y-direction pixel size: " + str(Y_res))
|
||||
|
||||
ChipSizeX0_PIX_X = np.ceil(self.chipSizeX0 / X_res / 4) * 4
|
||||
ChipSizeX0_PIX_Y = np.ceil(self.chipSizeX0 / Y_res / 4) * 4
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for ii in range(lCount):
|
||||
y = geoTrans[3] + (lOff+ii+0.5) * geoTrans[5]
|
||||
demLine = demDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
demLine = struct.unpack('d' * pCount, demLine)
|
||||
|
||||
if (self.dhdxname != ""):
|
||||
sxLine = sxDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
sxLine = struct.unpack('d' * pCount, sxLine)
|
||||
syLine = syDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
syLine = struct.unpack('d' * pCount, syLine)
|
||||
|
||||
if (self.vxname != ""):
|
||||
vxLine = vxDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
vxLine = struct.unpack('d' * pCount, vxLine)
|
||||
vyLine = vyDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
vyLine = struct.unpack('d' * pCount, vyLine)
|
||||
|
||||
if (self.srxname != ""):
|
||||
srxLine = srxDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
srxLine = struct.unpack('d' * pCount, srxLine)
|
||||
sryLine = sryDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
sryLine = struct.unpack('d' * pCount, sryLine)
|
||||
|
||||
if (self.csminxname != ""):
|
||||
csminxLine = csminxDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
csminxLine = struct.unpack('d' * pCount, csminxLine)
|
||||
csminyLine = csminyDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
csminyLine = struct.unpack('d' * pCount, csminyLine)
|
||||
|
||||
if (self.csmaxxname != ""):
|
||||
csmaxxLine = csmaxxDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
csmaxxLine = struct.unpack('d' * pCount, csmaxxLine)
|
||||
csmaxyLine = csmaxyDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
csmaxyLine = struct.unpack('d' * pCount, csmaxyLine)
|
||||
|
||||
if (self.ssmname != ""):
|
||||
ssmLine = ssmDS.GetRasterBand(1).ReadRaster(xoff=pOff, yoff=lOff+ii, xsize=pCount, ysize=1, buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
ssmLine = struct.unpack('d' * pCount, ssmLine)
|
||||
|
||||
for jj in range(pCount):
|
||||
xyzs = np.array([geoTrans[0] + (jj+pOff+0.5)*geoTrans[1], y, demLine[jj]])
|
||||
targxyz0 = xyzs.copy()
|
||||
if (self.dhdxname != ""):
|
||||
slp = np.array([sxLine[jj], syLine[jj], -1.0])
|
||||
if (self.vxname != ""):
|
||||
vel = np.array([vxLine[jj], vyLine[jj], 0.0])
|
||||
else:
|
||||
vel = np.array([0., 0., 0.])
|
||||
if (self.srxname != ""):
|
||||
schrng1 = np.array([srxLine[jj], sryLine[jj], 0.0])
|
||||
schrng2 = np.array([-srxLine[jj], sryLine[jj], 0.0])
|
||||
targutm0 = np.array(fwdTrans.TransformPoint(targxyz0[0],targxyz0[1],targxyz0[2]))
|
||||
xind = np.round((targutm0[0] - self.startingX) / self.XSize) + 1.
|
||||
yind = np.round((targutm0[1] - self.startingY) / self.YSize) + 1.
|
||||
|
||||
# x-direction vector
|
||||
targutm = targutm0.copy()
|
||||
targutm[0] = targutm0[0] + self.XSize
|
||||
targxyz = np.array(invTrans.TransformPoint(targutm[0],targutm[1],targutm[2]))
|
||||
xunit = (targxyz-targxyz0) / np.linalg.norm(targxyz-targxyz0)
|
||||
|
||||
# y-direction vector
|
||||
targutm = targutm0.copy()
|
||||
targutm[1] = targutm0[1] + self.YSize
|
||||
targxyz = np.array(invTrans.TransformPoint(targutm[0],targutm[1],targutm[2]))
|
||||
yunit = (targxyz-targxyz0) / np.linalg.norm(targxyz-targxyz0)
|
||||
|
||||
# local normal vector
|
||||
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 ((xind > self.numberOfSamples)|(xind < 1)|(yind > self.numberOfLines)|(yind < 1)):
|
||||
# pdb.set_trace()
|
||||
raster1[jj] = nodata_out
|
||||
raster2[jj] = nodata_out
|
||||
raster11[jj] = nodata_out
|
||||
raster22[jj] = nodata_out
|
||||
|
||||
sr_raster11[jj] = nodata_out
|
||||
sr_raster22[jj] = nodata_out
|
||||
csmin_raster11[jj] = nodata_out
|
||||
csmin_raster22[jj] = nodata_out
|
||||
csmax_raster11[jj] = nodata_out
|
||||
csmax_raster22[jj] = nodata_out
|
||||
ssm_raster[jj] = nodata_out
|
||||
|
||||
raster1a[jj] = nodata_out
|
||||
raster1b[jj] = nodata_out
|
||||
raster2a[jj] = nodata_out
|
||||
raster2b[jj] = nodata_out
|
||||
else:
|
||||
raster1[jj] = xind;
|
||||
raster2[jj] = yind;
|
||||
# pdb.set_trace()
|
||||
# if ((self.vxname != "")&(vel[0] != nodata)):
|
||||
## pdb.set_trace()
|
||||
# raster11[jj] = np.round(np.dot(vel,xunit)*self.repeatTime/self.XSize/365.0/24.0/3600.0*1)
|
||||
# raster22[jj] = np.round(np.dot(vel,yunit)*self.repeatTime/self.YSize/365.0/24.0/3600.0*1)
|
||||
# else:
|
||||
# raster11[jj] = 0.
|
||||
# raster22[jj] = 0.
|
||||
if (self.dhdxname != ""):
|
||||
|
||||
if (self.vxname != ""):
|
||||
if (vel[0] == nodata):
|
||||
raster11[jj] = 0.
|
||||
raster22[jj] = 0.
|
||||
else:
|
||||
raster11[jj] = np.round(np.dot(vel,xunit)*self.repeatTime/self.XSize/365.0/24.0/3600.0*1)
|
||||
raster22[jj] = np.round(np.dot(vel,yunit)*self.repeatTime/self.YSize/365.0/24.0/3600.0*1)
|
||||
|
||||
cross = np.cross(xunit,yunit)
|
||||
cross = cross / np.linalg.norm(cross)
|
||||
cross_check = np.abs(np.arccos(np.dot(normal,cross))/np.pi*180.0-90.0)
|
||||
|
||||
if (cross_check > 1.0):
|
||||
raster1a[jj] = normal[2]/(self.repeatTime/self.XSize/365.0/24.0/3600.0)*(normal[2]*yunit[1]-normal[1]*yunit[2])/((normal[2]*xunit[0]-normal[0]*xunit[2])*(normal[2]*yunit[1]-normal[1]*yunit[2])-(normal[2]*yunit[0]-normal[0]*yunit[2])*(normal[2]*xunit[1]-normal[1]*xunit[2]));
|
||||
raster1b[jj] = -normal[2]/(self.repeatTime/self.YSize/365.0/24.0/3600.0)*(normal[2]*xunit[1]-normal[1]*xunit[2])/((normal[2]*xunit[0]-normal[0]*xunit[2])*(normal[2]*yunit[1]-normal[1]*yunit[2])-(normal[2]*yunit[0]-normal[0]*yunit[2])*(normal[2]*xunit[1]-normal[1]*xunit[2]));
|
||||
raster2a[jj] = -normal[2]/(self.repeatTime/self.XSize/365.0/24.0/3600.0)*(normal[2]*yunit[0]-normal[0]*yunit[2])/((normal[2]*xunit[0]-normal[0]*xunit[2])*(normal[2]*yunit[1]-normal[1]*yunit[2])-(normal[2]*yunit[0]-normal[0]*yunit[2])*(normal[2]*xunit[1]-normal[1]*xunit[2]));
|
||||
raster2b[jj] = normal[2]/(self.repeatTime/self.YSize/365.0/24.0/3600.0)*(normal[2]*xunit[0]-normal[0]*xunit[2])/((normal[2]*xunit[0]-normal[0]*xunit[2])*(normal[2]*yunit[1]-normal[1]*yunit[2])-(normal[2]*yunit[0]-normal[0]*yunit[2])*(normal[2]*xunit[1]-normal[1]*xunit[2]));
|
||||
else:
|
||||
raster1a[jj] = nodata_out
|
||||
raster1b[jj] = nodata_out
|
||||
raster2a[jj] = nodata_out
|
||||
raster2b[jj] = nodata_out
|
||||
|
||||
if (self.srxname != ""):
|
||||
if ((self.vxname != "")&(vel[0] == nodata)):
|
||||
sr_raster11[jj] = 0
|
||||
sr_raster22[jj] = 0
|
||||
else:
|
||||
sr_raster11[jj] = np.abs(np.round(np.dot(schrng1,xunit)*self.repeatTime/self.XSize/365.0/24.0/3600.0*1))
|
||||
sr_raster22[jj] = np.abs(np.round(np.dot(schrng1,yunit)*self.repeatTime/self.YSize/365.0/24.0/3600.0*1))
|
||||
if (np.abs(np.round(np.dot(schrng2,xunit)*self.repeatTime/self.XSize/365.0/24.0/3600.0*1)) > sr_raster11[jj]):
|
||||
sr_raster11[jj] = np.abs(np.round(np.dot(schrng2,xunit)*self.repeatTime/self.XSize/365.0/24.0/3600.0*1))
|
||||
if (np.abs(np.round(np.dot(schrng2,yunit)*self.repeatTime/self.YSize/365.0/24.0/3600.0*1)) > sr_raster22[jj]):
|
||||
sr_raster22[jj] = np.abs(np.round(np.dot(schrng2,yunit)*self.repeatTime/self.YSize/365.0/24.0/3600.0*1))
|
||||
if (sr_raster11[jj] == 0):
|
||||
sr_raster11[jj] = 1
|
||||
if (sr_raster22[jj] == 0):
|
||||
sr_raster22[jj] = 1
|
||||
|
||||
if (self.csminxname != ""):
|
||||
csmin_raster11[jj] = csminxLine[jj] / self.chipSizeX0 * ChipSizeX0_PIX_X
|
||||
csmin_raster22[jj] = csminyLine[jj] / self.chipSizeX0 * ChipSizeX0_PIX_Y
|
||||
|
||||
|
||||
if (self.csmaxxname != ""):
|
||||
csmax_raster11[jj] = csmaxxLine[jj] / self.chipSizeX0 * ChipSizeX0_PIX_X
|
||||
csmax_raster22[jj] = csmaxyLine[jj] / self.chipSizeX0 * ChipSizeX0_PIX_Y
|
||||
|
||||
|
||||
|
||||
if (self.ssmname != ""):
|
||||
ssm_raster[jj] = ssmLine[jj]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# pdb.set_trace()
|
||||
|
||||
poBand1.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster1.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
poBand2.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster2.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
if ((self.dhdxname != "")&(self.vxname != "")):
|
||||
poBand1Off.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster11.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
poBand2Off.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster22.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
if ((self.dhdxname != "")&(self.srxname != "")):
|
||||
poBand1Sch.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=sr_raster11.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
poBand2Sch.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=sr_raster22.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
if (self.csminxname != ""):
|
||||
poBand1Min.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=csmin_raster11.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
poBand2Min.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=csmin_raster22.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
if (self.csmaxxname != ""):
|
||||
poBand1Max.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=csmax_raster11.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
poBand2Max.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=csmax_raster22.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
if (self.ssmname != ""):
|
||||
poBand1Msk.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=ssm_raster.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Int32)
|
||||
if (self.dhdxname != ""):
|
||||
poBand1RO2VX.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster1a.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
poBand2RO2VX.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster1b.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
poBand1RO2VY.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster2a.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
poBand2RO2VY.WriteRaster(xoff=0, yoff=ii, xsize=pCount, ysize=1, buf_len=raster2b.tostring(), buf_xsize=pCount, buf_ysize=1, buf_type=gdal.GDT_Float64)
|
||||
|
||||
|
||||
poDstDS = None
|
||||
if ((self.dhdxname != "")&(self.vxname != "")):
|
||||
poDstDSOff = None
|
||||
if ((self.dhdxname != "")&(self.srxname != "")):
|
||||
poDstDSSch = None
|
||||
if (self.csminxname != ""):
|
||||
poDstDSMin = None
|
||||
if (self.csmaxxname != ""):
|
||||
poDstDSMax = None
|
||||
if (self.ssmname != ""):
|
||||
poDstDSMsk = None
|
||||
if (self.dhdxname != ""):
|
||||
poDstDSRO2VX = None
|
||||
|
||||
poDstDSRO2VY = None
|
||||
|
||||
demDS = None
|
||||
|
||||
if (self.dhdxname != ""):
|
||||
sxDS = None
|
||||
syDS = None
|
||||
|
||||
if (self.vxname != ""):
|
||||
vxDS = None
|
||||
vyDS = None
|
||||
|
||||
if (self.srxname != ""):
|
||||
srxDS = None
|
||||
sryDS = None
|
||||
|
||||
if (self.csminxname != ""):
|
||||
csminxDS = None
|
||||
csminyDS = None
|
||||
|
||||
if (self.csmaxxname != ""):
|
||||
csmaxxDS = None
|
||||
csmaxyDS = None
|
||||
|
||||
if (self.ssmname != ""):
|
||||
ssmDS = None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def coregister(self,in1,in2,urlflag):
|
||||
|
||||
|
||||
def coregister(self,in1,in2):
|
||||
import os
|
||||
import numpy as np
|
||||
|
||||
|
||||
from osgeo import gdal, osr
|
||||
import struct
|
||||
|
||||
if urlflag == 1:
|
||||
DS1 = gdal.Open('/vsicurl/%s' %(in1))
|
||||
else:
|
||||
DS1 = gdal.Open(in1, gdal.GA_ReadOnly)
|
||||
|
||||
DS1 = gdal.Open(in1, gdal.GA_ReadOnly)
|
||||
trans1 = DS1.GetGeoTransform()
|
||||
xsize1 = DS1.RasterXSize
|
||||
ysize1 = DS1.RasterYSize
|
||||
|
||||
if urlflag == 1:
|
||||
DS2 = gdal.Open('/vsicurl/%s' %(in2))
|
||||
else:
|
||||
DS2 = gdal.Open(in2, gdal.GA_ReadOnly)
|
||||
epsg1 = self.getProjectionSystem(in1)
|
||||
|
||||
DS2 = gdal.Open(in2, gdal.GA_ReadOnly)
|
||||
trans2 = DS2.GetGeoTransform()
|
||||
xsize2 = DS2.RasterXSize
|
||||
ysize2 = DS2.RasterYSize
|
||||
epsg2 = self.getProjectionSystem(in2)
|
||||
|
||||
if epsg1 != epsg2:
|
||||
raise Exception('The current version of geo_autoRIFT assumes the two images are in the same projection, i.e. it cannot handle two different projections; the users are thus recommended to do the tranformation themselves before running geo_autoRIFT.')
|
||||
|
||||
|
||||
|
||||
W = np.max([trans1[0],trans2[0]])
|
||||
N = np.min([trans1[3],trans2[3]])
|
||||
E = np.min([trans1[0]+xsize1*trans1[1],trans2[0]+xsize2*trans2[1]])
|
||||
S = np.max([trans1[3]+ysize1*trans1[5],trans2[3]+ysize2*trans2[5]])
|
||||
|
||||
E = np.min([trans1[0]+(xsize1-1)*trans1[1],trans2[0]+(xsize2-1)*trans2[1]])
|
||||
S = np.max([trans1[3]+(ysize1-1)*trans1[5],trans2[3]+(ysize2-1)*trans2[5]])
|
||||
|
||||
x1a = int(np.round((W-trans1[0])/trans1[1]))
|
||||
x1b = int(np.round((E-trans1[0])/trans1[1]))
|
||||
y1a = int(np.round((N-trans1[3])/trans1[5]))
|
||||
y1b = int(np.round((S-trans1[3])/trans1[5]))
|
||||
|
||||
|
||||
x2a = int(np.round((W-trans2[0])/trans2[1]))
|
||||
x2b = int(np.round((E-trans2[0])/trans2[1]))
|
||||
y2a = int(np.round((N-trans2[3])/trans2[5]))
|
||||
y2b = int(np.round((S-trans2[3])/trans2[5]))
|
||||
|
||||
x1a = np.min([x1a, xsize1-1])
|
||||
x1b = np.min([x1b, xsize1-1])
|
||||
y1a = np.min([y1a, ysize1-1])
|
||||
y1b = np.min([y1b, ysize1-1])
|
||||
x2a = np.min([x2a, xsize2-1])
|
||||
x2b = np.min([x2b, xsize2-1])
|
||||
y2a = np.min([y2a, ysize2-1])
|
||||
y2b = np.min([y2b, ysize2-1])
|
||||
|
||||
x1a = np.max([x1a, 0])
|
||||
x1b = np.max([x1b, 0])
|
||||
y1a = np.max([y1a, 0])
|
||||
y1b = np.max([y1b, 0])
|
||||
x2a = np.max([x2a, 0])
|
||||
x2b = np.max([x2b, 0])
|
||||
y2a = np.max([y2a, 0])
|
||||
y2b = np.max([y2b, 0])
|
||||
|
||||
if (x1a > (xsize1-1))|(x1b > (xsize1-1))|(x2a > (xsize2-1))|(x2b > (xsize2-1))|(y1a > (ysize1-1))|(y1b > (ysize1-1))|(y2a > (ysize2-1))|(y2b > (ysize2-1)):
|
||||
raise Exception('Uppper bound of coregistered image index should be <= size of image1 (and image2) minus 1')
|
||||
|
||||
if (x1a < 0)|(x1b < 0)|(x2a < 0)|(x2b < 0)|(y1a < 0)|(y1b < 0)|(y2a < 0)|(y2b < 0):
|
||||
raise Exception('Lower bound of coregistered image index should be >= 0')
|
||||
|
||||
if ((x1b-x1a) != (x2b-x2a))|((y1b-y1a) != (y2b-y2a)):
|
||||
raise Exception('Coregistered image size mismatch between image1 and image2')
|
||||
|
||||
x1a = int(x1a)
|
||||
x1b = int(x1b)
|
||||
y1a = int(y1a)
|
||||
|
@ -826,34 +333,14 @@ class GeogridOptical():
|
|||
|
||||
trans = (W, trans1[1], 0.0, N, 0.0, trans1[5])
|
||||
|
||||
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)
|
||||
|
||||
fileformat = "GTiff"
|
||||
driver = gdal.GetDriverByName(fileformat)
|
||||
|
||||
DST1 = driver.Create(os.path.basename(in1), xsize=(x1b-x1a+1), ysize=(y1b-y1a+1), bands=1, eType=gdal.GDT_UInt16)
|
||||
DST1.SetGeoTransform(trans)
|
||||
DST1.SetProjection(DS1.GetProjectionRef())
|
||||
DST1.GetRasterBand(1).WriteArray(I1)
|
||||
DST1 = None
|
||||
|
||||
DST2 = driver.Create(os.path.basename(in2), xsize=(x2b-x2a+1), ysize=(y2b-y2a+1), bands=1, eType=gdal.GDT_UInt16)
|
||||
DST2.SetGeoTransform(trans)
|
||||
DST2.SetProjection(DS2.GetProjectionRef())
|
||||
DST2.GetRasterBand(1).WriteArray(I2)
|
||||
DST2 = None
|
||||
|
||||
return x1a, y1a, x1b-x1a+1, y1b-y1a+1, x2a, y2a, x2b-x2a+1, y2b-y2a+1, trans
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super(GeogridOptical, self).__init__()
|
||||
|
@ -867,7 +354,7 @@ class GeogridOptical():
|
|||
self.numberOfLines = None
|
||||
self.repeatTime = None
|
||||
self.chipSizeX0 = None
|
||||
self.urlflag = None
|
||||
self.gridSpacingX = None
|
||||
|
||||
##Input related parameters
|
||||
self.dat1name = None
|
||||
|
@ -883,7 +370,7 @@ class GeogridOptical():
|
|||
self.csmaxxname = None
|
||||
self.csmaxyname = None
|
||||
self.ssmname = None
|
||||
|
||||
|
||||
##Output related parameters
|
||||
self.winlocname = None
|
||||
self.winoffname = None
|
||||
|
@ -893,6 +380,12 @@ class GeogridOptical():
|
|||
self.winssmname = None
|
||||
self.winro2vxname = None
|
||||
self.winro2vyname = None
|
||||
|
||||
##dt-varying search range scale (srs) rountine parameters
|
||||
self.srs_dt_unity = 182
|
||||
self.srs_max_scale = 5
|
||||
self.srs_max_search = 20000
|
||||
self.srs_min_search = 0
|
||||
|
||||
##Coordinate system
|
||||
self.epsgDem = None
|
||||
|
@ -900,5 +393,14 @@ class GeogridOptical():
|
|||
self._xlim = None
|
||||
self._ylim = None
|
||||
self.nodata_out = None
|
||||
|
||||
##Pointer to C
|
||||
self._geogridOptical = None
|
||||
|
||||
|
||||
##parameters for autoRIFT
|
||||
self.pOff = None
|
||||
self.lOff = None
|
||||
self.pCount = None
|
||||
self.lCount = None
|
||||
self.X_res = None
|
||||
self.Y_res = None
|
||||
|
|
|
@ -26,13 +26,28 @@ if not os.path.exists(initFile):
|
|||
fout.write("#!/usr/bin/env python3")
|
||||
fout.close()
|
||||
|
||||
|
||||
listFiles = ['Geogrid.py','GeogridOptical.py',initFile]
|
||||
envgeogrid.Install(install,listFiles)
|
||||
envgeogrid.Alias('install',install)
|
||||
Export('envgeogrid')
|
||||
|
||||
|
||||
|
||||
|
||||
bindingsScons = 'bindings/SConscript'
|
||||
SConscript(bindingsScons,variant_dir = envgeogrid['PRJ_SCONS_BUILD'] + '/' + package + '/' + project + '/bindings')
|
||||
includeScons = 'include/SConscript'
|
||||
SConscript(includeScons)
|
||||
srcScons = 'src/SConscript'
|
||||
SConscript(srcScons,variant_dir = envgeogrid['PRJ_SCONS_BUILD'] + '/' + package + '/' + project + '/src')
|
||||
|
||||
|
||||
|
||||
bindingsScons1 = 'bindings/SConscript1'
|
||||
SConscript(bindingsScons1,variant_dir = envgeogrid['PRJ_SCONS_BUILD'] + '/' + package + '/' + project + '/bindings')
|
||||
includeScons1 = 'include/SConscript1'
|
||||
SConscript(includeScons1)
|
||||
srcScons1 = 'src/SConscript1'
|
||||
SConscript(srcScons1,variant_dir = envgeogrid['PRJ_SCONS_BUILD'] + '/' + package + '/' + project + '/src')
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# from .splitSpectrum import PySplitRangeSpectrum
|
||||
# return PySplitRangeSpectrum()
|
||||
|
||||
|
||||
# should always work - standalone or with ISCE
|
||||
from .GeogridOptical import GeogridOptical
|
||||
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# Author: Piyush Agram
|
||||
# Copyright 2019, by the California Institute of Technology. ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
|
||||
# Any commercial use must be negotiated with the Office of Technology Transfer at the California Institute of Technology.
|
||||
#
|
||||
# This software may be subject to U.S. export control laws. By accepting this software, the user agrees to comply with all applicable U.S.
|
||||
# export laws and regulations. User has the responsibility to obtain export licenses, or other export authority as may be required before
|
||||
# exporting such information to foreign countries or providing access to foreign persons.
|
||||
#
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
import os
|
||||
|
||||
Import('envgeogrid')
|
||||
package = envgeogrid['PACKAGE']
|
||||
project = envgeogrid['PROJECT']
|
||||
install = envgeogrid['PRJ_SCONS_INSTALL'] + '/' + package + '/' + project
|
||||
build = envgeogrid['PRJ_SCONS_BUILD'] + '/' + package + '/' + project
|
||||
libList = ['gomp','geogridOptical','combinedLib','gdal']
|
||||
envgeogrid.PrependUnique(LIBS = libList)
|
||||
module = envgeogrid.LoadableModule(target = 'geogridOptical.abi3.so', source = 'geogridOpticalmodule.cpp')
|
||||
envgeogrid.Install(install,module)
|
||||
envgeogrid.Alias('install',install)
|
||||
envgeogrid.Install(build,module)
|
||||
envgeogrid.Alias('build',build)
|
|
@ -0,0 +1,567 @@
|
|||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Copyright 2019 California Institute of Technology. ALL RIGHTS RESERVED.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* United States Government Sponsorship acknowledged. This software is subject to
|
||||
* U.S. export control laws and regulations and has been classified as 'EAR99 NLR'
|
||||
* (No [Export] License Required except when exporting to an embargoed country,
|
||||
* end user, or in support of a prohibited end use). By downloading this software,
|
||||
* the user agrees to comply with all applicable U.S. export laws and regulations.
|
||||
* The user has the responsibility to obtain export licenses, or other export
|
||||
* authority as may be required before exporting this software to any 'EAR99'
|
||||
* embargoed foreign country or citizen of those countries.
|
||||
*
|
||||
* Authors: Piyush Agram, Yang Lei
|
||||
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
#include <string>
|
||||
#include "geogridOptical.h"
|
||||
#include "geogridOpticalmodule.h"
|
||||
|
||||
static const char * const __doc__ = "Python extension for geogrid";
|
||||
|
||||
PyModuleDef moduledef = {
|
||||
//header
|
||||
PyModuleDef_HEAD_INIT,
|
||||
//name of the module
|
||||
"geogridOptical",
|
||||
//module documentation string
|
||||
__doc__,
|
||||
//size of the per-interpreter state of the module;
|
||||
-1,
|
||||
geogrid_methods,
|
||||
};
|
||||
|
||||
//Initialization function for the module
|
||||
PyMODINIT_FUNC
|
||||
PyInit_geogridOptical()
|
||||
{
|
||||
PyObject* module = PyModule_Create(&moduledef);
|
||||
if (!module)
|
||||
{
|
||||
return module;
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
PyObject* createGeoGridOptical(PyObject* self, PyObject *args)
|
||||
{
|
||||
geoGridOptical* ptr = new geoGridOptical;
|
||||
return Py_BuildValue("K", (uint64_t) ptr);
|
||||
}
|
||||
|
||||
PyObject* destroyGeoGridOptical(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (((geoGridOptical*)(ptr))!=NULL)
|
||||
{
|
||||
delete ((geoGridOptical*)(ptr));
|
||||
}
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setEPSG(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
int code1, code2;
|
||||
if (!PyArg_ParseTuple(args, "Kii", &ptr, &code1, &code2))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->epsgDem = code1;
|
||||
((geoGridOptical*)(ptr))->epsgDat = code2;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
|
||||
PyObject* setChipSizeX0(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double chipSizeX0;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &chipSizeX0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->chipSizeX0 = chipSizeX0;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setGridSpacingX(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double gridSpacingX;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &gridSpacingX))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->gridSpacingX = gridSpacingX;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setRepeatTime(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double repeatTime;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &repeatTime))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->dt = repeatTime;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setOpticalImageDimensions(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
int wid, len;
|
||||
if (!PyArg_ParseTuple(args, "Kii", &ptr, &wid, &len))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->nPixels = wid;
|
||||
((geoGridOptical*)(ptr))->nLines = len;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setXParameters(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double r0, rspace;
|
||||
if (!PyArg_ParseTuple(args, "Kdd", &ptr, &r0, &rspace))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->startingX = r0;
|
||||
((geoGridOptical*)(ptr))->XSize = rspace;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setYParameters(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double t0, prf;
|
||||
if (!PyArg_ParseTuple(args, "Kdd", &ptr, &t0, &prf))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->startingY = t0;
|
||||
((geoGridOptical*)(ptr))->YSize = prf;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setXLimits(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double x0, x1;
|
||||
if (!PyArg_ParseTuple(args, "Kdd", &ptr, &x0, &x1))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->xmin = x0;
|
||||
((geoGridOptical*)(ptr))->xmax = x1;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setYLimits(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double x0, x1;
|
||||
if (!PyArg_ParseTuple(args, "Kdd", &ptr, &x0, &x1))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->ymin = x0;
|
||||
((geoGridOptical*)(ptr))->ymax = x1;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setDEM(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->demname = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setVelocities(PyObject *self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char *vx;
|
||||
char *vy;
|
||||
if (!PyArg_ParseTuple(args, "Kss", &ptr, &vx, &vy))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->vxname = std::string(vx);
|
||||
((geoGridOptical*)(ptr))->vyname = std::string(vy);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setSearchRange(PyObject *self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char *srx;
|
||||
char *sry;
|
||||
if (!PyArg_ParseTuple(args, "Kss", &ptr, &srx, &sry))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->srxname = std::string(srx);
|
||||
((geoGridOptical*)(ptr))->sryname = std::string(sry);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setChipSizeMin(PyObject *self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char *csminx;
|
||||
char *csminy;
|
||||
if (!PyArg_ParseTuple(args, "Kss", &ptr, &csminx, &csminy))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->csminxname = std::string(csminx);
|
||||
((geoGridOptical*)(ptr))->csminyname = std::string(csminy);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setChipSizeMax(PyObject *self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char *csmaxx;
|
||||
char *csmaxy;
|
||||
if (!PyArg_ParseTuple(args, "Kss", &ptr, &csmaxx, &csmaxy))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->csmaxxname = std::string(csmaxx);
|
||||
((geoGridOptical*)(ptr))->csmaxyname = std::string(csmaxy);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setStableSurfaceMask(PyObject *self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char *ssm;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &ssm))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->ssmname = std::string(ssm);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setSlopes(PyObject *self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char *sx;
|
||||
char *sy;
|
||||
if (!PyArg_ParseTuple(args, "Kss", &ptr, &sx, &sy))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->dhdxname = std::string(sx);
|
||||
((geoGridOptical*)(ptr))->dhdyname = std::string(sy);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setWindowLocationsFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->pixlinename = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setWindowOffsetsFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->offsetname = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setWindowSearchRangeFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->searchrangename = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setWindowChipSizeMinFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->chipsizeminname = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setWindowChipSizeMaxFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->chipsizemaxname = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setWindowStableSurfaceMaskFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->stablesurfacemaskname = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setRO2VXFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->ro2vx_name = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setRO2VYFilename(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args, "Ks", &ptr, &name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->ro2vy_name = std::string(name);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
|
||||
PyObject* setNodataOut(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
int nodata;
|
||||
if (!PyArg_ParseTuple(args, "Ki", &ptr, &nodata))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->nodata_out = nodata;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject* getXOff(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGridOptical*)(ptr))->pOff;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getYOff(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGridOptical*)(ptr))->lOff;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getXCount(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGridOptical*)(ptr))->pCount;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getYCount(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGridOptical*)(ptr))->lCount;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getXPixelSize(PyObject *self, PyObject *args)
|
||||
{
|
||||
double var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGridOptical*)(ptr))->X_res;
|
||||
return Py_BuildValue("d",var);
|
||||
}
|
||||
|
||||
PyObject* getYPixelSize(PyObject *self, PyObject *args)
|
||||
{
|
||||
double var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGridOptical*)(ptr))->Y_res;
|
||||
return Py_BuildValue("d",var);
|
||||
}
|
||||
|
||||
PyObject* setDtUnity(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double dt_unity;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &dt_unity))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->dt_unity = dt_unity;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setMaxFactor(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double max_factor;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &max_factor))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->max_factor = max_factor;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setUpperThreshold(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double upper_thld;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &upper_thld))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->upper_thld = upper_thld;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setLowerThreshold(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double lower_thld;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &lower_thld))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGridOptical*)(ptr))->lower_thld = lower_thld;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
|
||||
PyObject* geogridOptical(PyObject* self, PyObject* args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((geoGridOptical*)(ptr))->geogridOptical();
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
|
@ -116,6 +116,18 @@ PyObject* setChipSizeX0(PyObject *self, PyObject *args)
|
|||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setGridSpacingX(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double gridSpacingX;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &gridSpacingX))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGrid*)(ptr))->gridSpacingX = gridSpacingX;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setRepeatTime(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
|
@ -430,18 +442,6 @@ 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)
|
||||
{
|
||||
|
@ -455,6 +455,138 @@ PyObject* setOrbit(PyObject *self, PyObject *args)
|
|||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* getXOff(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGrid*)(ptr))->pOff;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getYOff(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGrid*)(ptr))->lOff;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getXCount(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGrid*)(ptr))->pCount;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getYCount(PyObject *self, PyObject *args)
|
||||
{
|
||||
int var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGrid*)(ptr))->lCount;
|
||||
return Py_BuildValue("i",var);
|
||||
}
|
||||
|
||||
PyObject* getXPixelSize(PyObject *self, PyObject *args)
|
||||
{
|
||||
double var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGrid*)(ptr))->grd_res;
|
||||
return Py_BuildValue("d",var);
|
||||
}
|
||||
|
||||
PyObject* getYPixelSize(PyObject *self, PyObject *args)
|
||||
{
|
||||
double var;
|
||||
uint64_t ptr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "K", &ptr))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = ((geoGrid*)(ptr))->azm_res;
|
||||
return Py_BuildValue("d",var);
|
||||
}
|
||||
|
||||
PyObject* setDtUnity(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double dt_unity;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &dt_unity))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGrid*)(ptr))->dt_unity = dt_unity;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setMaxFactor(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double max_factor;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &max_factor))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGrid*)(ptr))->max_factor = max_factor;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setUpperThreshold(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double upper_thld;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &upper_thld))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGrid*)(ptr))->upper_thld = upper_thld;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
PyObject* setLowerThreshold(PyObject *self, PyObject *args)
|
||||
{
|
||||
uint64_t ptr;
|
||||
double lower_thld;
|
||||
if (!PyArg_ParseTuple(args, "Kd", &ptr, &lower_thld))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
((geoGrid*)(ptr))->lower_thld = lower_thld;
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
|
||||
PyObject* geogrid(PyObject* self, PyObject* args)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# Author: Piyush Agram
|
||||
# Copyright 2019, by the California Institute of Technology. ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
|
||||
# Any commercial use must be negotiated with the Office of Technology Transfer at the California Institute of Technology.
|
||||
#
|
||||
# This software may be subject to U.S. export control laws. By accepting this software, the user agrees to comply with all applicable U.S.
|
||||
# export laws and regulations. User has the responsibility to obtain export licenses, or other export authority as may be required before
|
||||
# exporting such information to foreign countries or providing access to foreign persons.
|
||||
#
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
import os
|
||||
|
||||
Import('envgeogrid')
|
||||
package = envgeogrid['PACKAGE']
|
||||
project = envgeogrid['PROJECT']
|
||||
build = envgeogrid['PRJ_SCONS_BUILD'] + '/' + package + '/' + project + '/include'
|
||||
envgeogrid.AppendUnique(CPPPATH = [build])
|
||||
listFiles = ['geogridOptical.h', 'geogridOpticalmodule.h']
|
||||
envgeogrid.Install(build,listFiles)
|
||||
envgeogrid.Alias('build',build)
|
|
@ -53,6 +53,7 @@ struct geoGrid
|
|||
std::string ssmname; //Stable surface mask
|
||||
int epsgcode;
|
||||
double chipSizeX0;
|
||||
double gridSpacingX;
|
||||
|
||||
//Bounding box related
|
||||
double xmin, xmax;
|
||||
|
@ -69,8 +70,14 @@ struct geoGrid
|
|||
int nPixels;
|
||||
int lookSide;
|
||||
int nodata_out;
|
||||
int urlflag;
|
||||
double incidenceAngle;
|
||||
int pOff, lOff, pCount, lCount;
|
||||
double grd_res, azm_res;
|
||||
|
||||
//dt-varying search range rountine parameters
|
||||
double dt_unity;
|
||||
double max_factor;
|
||||
double upper_thld, lower_thld;
|
||||
|
||||
//Output file names
|
||||
std::string pixlinename;
|
||||
|
@ -82,6 +89,7 @@ struct geoGrid
|
|||
std::string ro2vx_name;
|
||||
std::string ro2vy_name;
|
||||
|
||||
|
||||
//Functions
|
||||
void computeBbox(double *);
|
||||
void geogrid();
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Copyright 2019 California Institute of Technology. ALL RIGHTS RESERVED.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* United States Government Sponsorship acknowledged. This software is subject to
|
||||
* U.S. export control laws and regulations and has been classified as 'EAR99 NLR'
|
||||
* (No [Export] License Required except when exporting to an embargoed country,
|
||||
* end user, or in support of a prohibited end use). By downloading this software,
|
||||
* the user agrees to comply with all applicable U.S. export laws and regulations.
|
||||
* The user has the responsibility to obtain export licenses, or other export
|
||||
* authority as may be required before exporting this software to any 'EAR99'
|
||||
* embargoed foreign country or citizen of those countries.
|
||||
*
|
||||
* Authors: Piyush Agram, Yang Lei
|
||||
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
|
||||
#ifndef GEOGRIDOPTICAL_H
|
||||
#define GEOGRIDOPTICAL_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
struct geoGridOptical
|
||||
{
|
||||
//DEM related inputs
|
||||
std::string demname; //DEM
|
||||
std::string dhdxname; //Slope in X
|
||||
std::string dhdyname; //Slope in Y
|
||||
std::string vxname; //Velocity in X
|
||||
std::string vyname; //Velocity in Y
|
||||
std::string srxname; //Search range in X
|
||||
std::string sryname; //Search range in Y
|
||||
std::string csminxname; //Chip size minimum in x
|
||||
std::string csminyname; //Chip size minimum in y
|
||||
std::string csmaxxname; //Chip size maximum in x
|
||||
std::string csmaxyname; //Chip size maximum in y
|
||||
std::string ssmname; //Stable surface mask
|
||||
int epsgDem, epsgDat;
|
||||
double chipSizeX0;
|
||||
double gridSpacingX;
|
||||
|
||||
//Bounding box related
|
||||
double xmin, xmax;
|
||||
double ymin, ymax;
|
||||
|
||||
//Radar image related inputs
|
||||
double startingX, startingY;
|
||||
double XSize, YSize;
|
||||
int nLines, nPixels;
|
||||
double dt;
|
||||
int nodata_out;
|
||||
int pOff, lOff, pCount, lCount;
|
||||
double X_res, Y_res;
|
||||
|
||||
//dt-varying search range rountine parameters
|
||||
double dt_unity;
|
||||
double max_factor;
|
||||
double upper_thld, lower_thld;
|
||||
|
||||
//Output file names
|
||||
std::string pixlinename;
|
||||
std::string offsetname;
|
||||
std::string searchrangename;
|
||||
std::string chipsizeminname;
|
||||
std::string chipsizemaxname;
|
||||
std::string stablesurfacemaskname;
|
||||
std::string ro2vx_name;
|
||||
std::string ro2vy_name;
|
||||
|
||||
//Functions
|
||||
void computeBbox(double *);
|
||||
void geogridOptical();
|
||||
void cross_C(double r_u[3], double r_v[3], double r_w[3]);
|
||||
double dot_C(double r_v[3], double r_w[3]);
|
||||
double norm_C(double a[3]);
|
||||
void unitvec_C(double v[3], double u[3]);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,124 @@
|
|||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Copyright 2019 California Institute of Technology. ALL RIGHTS RESERVED.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* United States Government Sponsorship acknowledged. This software is subject to
|
||||
* U.S. export control laws and regulations and has been classified as 'EAR99 NLR'
|
||||
* (No [Export] License Required except when exporting to an embargoed country,
|
||||
* end user, or in support of a prohibited end use). By downloading this software,
|
||||
* the user agrees to comply with all applicable U.S. export laws and regulations.
|
||||
* The user has the responsibility to obtain export licenses, or other export
|
||||
* authority as may be required before exporting this software to any 'EAR99'
|
||||
* embargoed foreign country or citizen of those countries.
|
||||
*
|
||||
* Authors: Piyush Agram, Yang Lei
|
||||
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
|
||||
|
||||
#ifndef geogridOpticalmodule_h
|
||||
#define geogridOpticalmodule_h
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
PyObject * createGeoGridOptical(PyObject*, PyObject*);
|
||||
PyObject * destroyGeoGridOptical(PyObject*, PyObject*);
|
||||
PyObject * geogridOptical(PyObject *, PyObject *);
|
||||
PyObject * setOpticalImageDimensions(PyObject *, PyObject *);
|
||||
PyObject * setXParameters(PyObject *, PyObject *);
|
||||
PyObject * setYParameters(PyObject*, PyObject *);
|
||||
PyObject * setRepeatTime(PyObject *, PyObject *);
|
||||
|
||||
PyObject * setDEM(PyObject *, PyObject *);
|
||||
PyObject * setVelocities(PyObject*, PyObject*);
|
||||
PyObject * setSearchRange(PyObject*, PyObject*);
|
||||
PyObject * setChipSizeMin(PyObject*, PyObject*);
|
||||
PyObject * setChipSizeMax(PyObject*, PyObject*);
|
||||
PyObject * setStableSurfaceMask(PyObject*, PyObject*);
|
||||
PyObject * setSlopes(PyObject*, PyObject*);
|
||||
PyObject * setNodataOut(PyObject *, PyObject *);
|
||||
|
||||
PyObject * setDtUnity(PyObject *, PyObject *);
|
||||
PyObject * setMaxFactor(PyObject *, PyObject *);
|
||||
PyObject * setUpperThreshold(PyObject*, PyObject *);
|
||||
PyObject * setLowerThreshold(PyObject *, PyObject *);
|
||||
|
||||
PyObject * setWindowLocationsFilename(PyObject *, PyObject *);
|
||||
PyObject * setWindowOffsetsFilename(PyObject *, PyObject *);
|
||||
PyObject * setWindowSearchRangeFilename(PyObject *, PyObject *);
|
||||
PyObject * setWindowChipSizeMinFilename(PyObject *, PyObject *);
|
||||
PyObject * setWindowChipSizeMaxFilename(PyObject *, PyObject *);
|
||||
PyObject * setWindowStableSurfaceMaskFilename(PyObject *, PyObject *);
|
||||
PyObject * setRO2VXFilename(PyObject *, PyObject *);
|
||||
PyObject * setRO2VYFilename(PyObject *, PyObject *);
|
||||
PyObject * setEPSG(PyObject *, PyObject *);
|
||||
PyObject * setChipSizeX0(PyObject *, PyObject *);
|
||||
PyObject * setGridSpacingX(PyObject *, PyObject *);
|
||||
PyObject * setXLimits(PyObject *, PyObject *);
|
||||
PyObject * setYLimits(PyObject *, PyObject *);
|
||||
PyObject * getXPixelSize(PyObject *, PyObject *);
|
||||
PyObject * getYPixelSize(PyObject *, PyObject *);
|
||||
PyObject * getXOff(PyObject *, PyObject *);
|
||||
PyObject * getYOff(PyObject *, PyObject *);
|
||||
PyObject * getXCount(PyObject *, PyObject *);
|
||||
PyObject * getYCount(PyObject *, PyObject *);
|
||||
}
|
||||
|
||||
static PyMethodDef geogrid_methods[] =
|
||||
{
|
||||
{"createGeoGridOptical_Py", createGeoGridOptical, METH_VARARGS, " "},
|
||||
{"destroyGeoGridOptical_Py", destroyGeoGridOptical, METH_VARARGS, " "},
|
||||
{"geogridOptical_Py", geogridOptical, METH_VARARGS, " "},
|
||||
{"setOpticalImageDimensions_Py", setOpticalImageDimensions, METH_VARARGS, " "},
|
||||
{"setXParameters_Py", setXParameters, METH_VARARGS, " "},
|
||||
{"setYParameters_Py", setYParameters, METH_VARARGS, " "},
|
||||
{"setRepeatTime_Py", setRepeatTime, METH_VARARGS, " "},
|
||||
{"setDEM_Py", setDEM, METH_VARARGS, " "},
|
||||
{"setEPSG_Py", setEPSG, METH_VARARGS, " "},
|
||||
{"setChipSizeX0_Py", setChipSizeX0, METH_VARARGS, " "},
|
||||
{"setGridSpacingX_Py", setGridSpacingX, METH_VARARGS, " "},
|
||||
{"setVelocities_Py", setVelocities, METH_VARARGS, " "},
|
||||
{"setSearchRange_Py", setSearchRange, METH_VARARGS, " "},
|
||||
{"setChipSizeMin_Py", setChipSizeMin, METH_VARARGS, " "},
|
||||
{"setChipSizeMax_Py", setChipSizeMax, METH_VARARGS, " "},
|
||||
{"setStableSurfaceMask_Py", setStableSurfaceMask, METH_VARARGS, " "},
|
||||
{"setSlopes_Py", setSlopes, METH_VARARGS, " "},
|
||||
{"setNodataOut_Py", setNodataOut, METH_VARARGS, " "},
|
||||
{"setDtUnity_Py", setDtUnity, METH_VARARGS, " "},
|
||||
{"setMaxFactor_Py", setMaxFactor, METH_VARARGS, " "},
|
||||
{"setUpperThreshold_Py", setUpperThreshold, METH_VARARGS, " "},
|
||||
{"setLowerThreshold_Py", setLowerThreshold, METH_VARARGS, " "},
|
||||
{"setXLimits_Py", setXLimits, METH_VARARGS, " "},
|
||||
{"setYLimits_Py", setYLimits, METH_VARARGS, " "},
|
||||
{"getXPixelSize_Py", getXPixelSize, METH_VARARGS, " "},
|
||||
{"getYPixelSize_Py", getYPixelSize, METH_VARARGS, " "},
|
||||
{"getXOff_Py", getXOff, METH_VARARGS, " "},
|
||||
{"getYOff_Py", getYOff, METH_VARARGS, " "},
|
||||
{"getXCount_Py", getXCount, METH_VARARGS, " "},
|
||||
{"getYCount_Py", getYCount, METH_VARARGS, " "},
|
||||
{"setWindowLocationsFilename_Py", setWindowLocationsFilename, METH_VARARGS, " "},
|
||||
{"setWindowOffsetsFilename_Py", setWindowOffsetsFilename, METH_VARARGS, " "},
|
||||
{"setWindowSearchRangeFilename_Py", setWindowSearchRangeFilename, METH_VARARGS, " "},
|
||||
{"setWindowChipSizeMinFilename_Py", setWindowChipSizeMinFilename, METH_VARARGS, " "},
|
||||
{"setWindowChipSizeMaxFilename_Py", setWindowChipSizeMaxFilename, METH_VARARGS, " "},
|
||||
{"setWindowStableSurfaceMaskFilename_Py", setWindowStableSurfaceMaskFilename, METH_VARARGS, " "},
|
||||
{"setRO2VXFilename_Py", setRO2VXFilename, METH_VARARGS, " "},
|
||||
{"setRO2VYFilename_Py", setRO2VYFilename, METH_VARARGS, " "},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
#endif //geoGridOpticalmodule_h
|
||||
|
|
@ -53,7 +53,11 @@ extern "C"
|
|||
PyObject * setOrbit(PyObject *, PyObject *);
|
||||
PyObject * setLookSide(PyObject *, PyObject *);
|
||||
PyObject * setNodataOut(PyObject *, PyObject *);
|
||||
PyObject * setUrlFlag(PyObject *, PyObject *);
|
||||
|
||||
PyObject * setDtUnity(PyObject *, PyObject *);
|
||||
PyObject * setMaxFactor(PyObject *, PyObject *);
|
||||
PyObject * setUpperThreshold(PyObject*, PyObject *);
|
||||
PyObject * setLowerThreshold(PyObject *, PyObject *);
|
||||
|
||||
PyObject * setWindowLocationsFilename(PyObject *, PyObject *);
|
||||
PyObject * setWindowOffsetsFilename(PyObject *, PyObject *);
|
||||
|
@ -66,8 +70,15 @@ extern "C"
|
|||
PyObject * setEPSG(PyObject *, PyObject *);
|
||||
PyObject * setIncidenceAngle(PyObject *, PyObject *);
|
||||
PyObject * setChipSizeX0(PyObject *, PyObject *);
|
||||
PyObject * setGridSpacingX(PyObject *, PyObject *);
|
||||
PyObject * setXLimits(PyObject *, PyObject *);
|
||||
PyObject * setYLimits(PyObject *, PyObject *);
|
||||
PyObject * getXPixelSize(PyObject *, PyObject *);
|
||||
PyObject * getYPixelSize(PyObject *, PyObject *);
|
||||
PyObject * getXOff(PyObject *, PyObject *);
|
||||
PyObject * getYOff(PyObject *, PyObject *);
|
||||
PyObject * getXCount(PyObject *, PyObject *);
|
||||
PyObject * getYCount(PyObject *, PyObject *);
|
||||
}
|
||||
|
||||
static PyMethodDef geogrid_methods[] =
|
||||
|
@ -83,6 +94,7 @@ static PyMethodDef geogrid_methods[] =
|
|||
{"setEPSG_Py", setEPSG, METH_VARARGS, " "},
|
||||
{"setIncidenceAngle_Py", setIncidenceAngle, METH_VARARGS, " "},
|
||||
{"setChipSizeX0_Py", setChipSizeX0, METH_VARARGS, " "},
|
||||
{"setGridSpacingX_Py", setGridSpacingX, METH_VARARGS, " "},
|
||||
{"setVelocities_Py", setVelocities, METH_VARARGS, " "},
|
||||
{"setSearchRange_Py", setSearchRange, METH_VARARGS, " "},
|
||||
{"setChipSizeMin_Py", setChipSizeMin, METH_VARARGS, " "},
|
||||
|
@ -92,9 +104,18 @@ static PyMethodDef geogrid_methods[] =
|
|||
{"setOrbit_Py", setOrbit, METH_VARARGS, " "},
|
||||
{"setLookSide_Py", setLookSide, METH_VARARGS, " "},
|
||||
{"setNodataOut_Py", setNodataOut, METH_VARARGS, " "},
|
||||
{"setUrlFlag_Py", setUrlFlag, METH_VARARGS, " "},
|
||||
{"setDtUnity_Py", setDtUnity, METH_VARARGS, " "},
|
||||
{"setMaxFactor_Py", setMaxFactor, METH_VARARGS, " "},
|
||||
{"setUpperThreshold_Py", setUpperThreshold, METH_VARARGS, " "},
|
||||
{"setLowerThreshold_Py", setLowerThreshold, METH_VARARGS, " "},
|
||||
{"setXLimits_Py", setXLimits, METH_VARARGS, " "},
|
||||
{"setYLimits_Py", setYLimits, METH_VARARGS, " "},
|
||||
{"getXPixelSize_Py", getXPixelSize, METH_VARARGS, " "},
|
||||
{"getYPixelSize_Py", getYPixelSize, METH_VARARGS, " "},
|
||||
{"getXOff_Py", getXOff, METH_VARARGS, " "},
|
||||
{"getYOff_Py", getYOff, METH_VARARGS, " "},
|
||||
{"getXCount_Py", getXCount, METH_VARARGS, " "},
|
||||
{"getYCount_Py", getYCount, METH_VARARGS, " "},
|
||||
{"setWindowLocationsFilename_Py", setWindowLocationsFilename, METH_VARARGS, " "},
|
||||
{"setWindowOffsetsFilename_Py", setWindowOffsetsFilename, METH_VARARGS, " "},
|
||||
{"setWindowSearchRangeFilename_Py", setWindowSearchRangeFilename, METH_VARARGS, " "},
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# Author: Piyush Agram
|
||||
# Copyright 2019, by the California Institute of Technology. ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
|
||||
# Any commercial use must be negotiated with the Office of Technology Transfer at the California Institute of Technology.
|
||||
#
|
||||
# This software may be subject to U.S. export control laws. By accepting this software, the user agrees to comply with all applicable U.S.
|
||||
# export laws and regulations. User has the responsibility to obtain export licenses, or other export authority as may be required before
|
||||
# exporting such information to foreign countries or providing access to foreign persons.
|
||||
#
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
import os
|
||||
|
||||
Import('envgeogrid')
|
||||
build = envgeogrid['PRJ_LIB_DIR']
|
||||
envgeogrid.AppendUnique(CXXFLAGS = '-fopenmp')
|
||||
envgeogrid.AppendUnique(CXXFLAGS = '-std=c++11')
|
||||
listFiles = ['geogridOptical.cpp']
|
||||
lib = envgeogrid.Library(target = 'geogridOptical', source = listFiles)
|
||||
envgeogrid.Install(build,lib)
|
||||
envgeogrid.Alias('build',build)
|
|
@ -46,15 +46,7 @@ void geoGrid::geogrid()
|
|||
double deg2rad = M_PI/180.0;
|
||||
|
||||
//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";
|
||||
|
@ -64,6 +56,7 @@ void geoGrid::geogrid()
|
|||
std::cout << "\nMap inputs: \n";
|
||||
std::cout << "EPSG: " << epsgcode << "\n";
|
||||
std::cout << "Smallest Allowable Chip Size in m: " << chipSizeX0 << "\n";
|
||||
std::cout << "Grid spacing in m: " << gridSpacingX << "\n";
|
||||
std::cout << "Repeat Time: " << dt << "\n";
|
||||
std::cout << "XLimits: " << xmin << " " << xmax << "\n";
|
||||
std::cout << "YLimits: " << ymin << " " << ymax << "\n";
|
||||
|
@ -152,23 +145,7 @@ 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 != "")
|
||||
{
|
||||
|
@ -308,11 +285,16 @@ void geoGrid::geogrid()
|
|||
|
||||
|
||||
//Get offsets and size to read from DEM
|
||||
int lOff = std::max( std::floor((ymax - geoTrans[3])/geoTrans[5]), 0.);
|
||||
int lCount = std::min( std::ceil((ymin - geoTrans[3])/geoTrans[5]), demYSize-1.) - lOff;
|
||||
|
||||
int pOff = std::max( std::floor((xmin - geoTrans[0])/geoTrans[1]), 0.);
|
||||
int pCount = std::min( std::ceil((xmax - geoTrans[0])/geoTrans[1]), demXSize-1.) - pOff;
|
||||
// int lOff = std::max( std::floor((ymax - geoTrans[3])/geoTrans[5]), 0.);
|
||||
// int lCount = std::min( std::ceil((ymin - geoTrans[3])/geoTrans[5]), demYSize-1.) - lOff;
|
||||
//
|
||||
// int pOff = std::max( std::floor((xmin - geoTrans[0])/geoTrans[1]), 0.);
|
||||
// int pCount = std::min( std::ceil((xmax - geoTrans[0])/geoTrans[1]), demXSize-1.) - pOff;
|
||||
lOff = std::max( std::floor((ymax - geoTrans[3])/geoTrans[5]), 0.);
|
||||
lCount = std::min( std::ceil((ymin - geoTrans[3])/geoTrans[5]), demYSize-1.) - lOff;
|
||||
|
||||
pOff = std::max( std::floor((xmin - geoTrans[0])/geoTrans[1]), 0.);
|
||||
pCount = std::min( std::ceil((xmax - geoTrans[0])/geoTrans[1]), demXSize-1.) - pOff;
|
||||
|
||||
|
||||
std::cout << "Xlimits : " << geoTrans[0] + pOff * geoTrans[1] << " "
|
||||
|
@ -397,11 +379,13 @@ void geoGrid::geogrid()
|
|||
|
||||
double raster1a[pCount];
|
||||
double raster1b[pCount];
|
||||
// double raster1c[pCount];
|
||||
double raster1c[pCount];
|
||||
|
||||
double raster2a[pCount];
|
||||
double raster2b[pCount];
|
||||
// double raster2c[pCount];
|
||||
double raster2c[pCount];
|
||||
|
||||
|
||||
|
||||
GDALRasterBand *poBand1 = NULL;
|
||||
GDALRasterBand *poBand2 = NULL;
|
||||
|
@ -418,6 +402,9 @@ void geoGrid::geogrid()
|
|||
GDALRasterBand *poBand1RO2VY = NULL;
|
||||
GDALRasterBand *poBand2RO2VX = NULL;
|
||||
GDALRasterBand *poBand2RO2VY = NULL;
|
||||
GDALRasterBand *poBand3RO2VX = NULL;
|
||||
GDALRasterBand *poBand3RO2VY = NULL;
|
||||
|
||||
|
||||
GDALDataset *poDstDS = NULL;
|
||||
GDALDataset *poDstDSOff = NULL;
|
||||
|
@ -427,6 +414,7 @@ void geoGrid::geogrid()
|
|||
GDALDataset *poDstDSMsk = NULL;
|
||||
GDALDataset *poDstDSRO2VX = NULL;
|
||||
GDALDataset *poDstDSRO2VY = NULL;
|
||||
|
||||
|
||||
|
||||
double nodata;
|
||||
|
@ -620,7 +608,7 @@ void geoGrid::geogrid()
|
|||
|
||||
str = ro2vx_name;
|
||||
const char * pszDstFilenameRO2VX = str.c_str();
|
||||
poDstDSRO2VX = poDriverRO2VX->Create( pszDstFilenameRO2VX, pCount, lCount, 2, GDT_Float64,
|
||||
poDstDSRO2VX = poDriverRO2VX->Create( pszDstFilenameRO2VX, pCount, lCount, 3, GDT_Float64,
|
||||
papszOptions );
|
||||
|
||||
poDstDSRO2VX->SetGeoTransform( adfGeoTransform );
|
||||
|
@ -632,10 +620,10 @@ void geoGrid::geogrid()
|
|||
// GDALRasterBand *poBand3Los;
|
||||
poBand1RO2VX = poDstDSRO2VX->GetRasterBand(1);
|
||||
poBand2RO2VX = poDstDSRO2VX->GetRasterBand(2);
|
||||
// poBand3Los = poDstDSLos->GetRasterBand(3);
|
||||
poBand3RO2VX = poDstDSRO2VX->GetRasterBand(3);
|
||||
poBand1RO2VX->SetNoDataValue(nodata_out);
|
||||
poBand2RO2VX->SetNoDataValue(nodata_out);
|
||||
// poBand3Los->SetNoDataValue(nodata_out);
|
||||
poBand3RO2VX->SetNoDataValue(nodata_out);
|
||||
|
||||
|
||||
GDALDriver *poDriverRO2VY;
|
||||
|
@ -646,7 +634,7 @@ void geoGrid::geogrid()
|
|||
|
||||
str = ro2vy_name;
|
||||
const char * pszDstFilenameRO2VY = str.c_str();
|
||||
poDstDSRO2VY = poDriverRO2VY->Create( pszDstFilenameRO2VY, pCount, lCount, 2, GDT_Float64,
|
||||
poDstDSRO2VY = poDriverRO2VY->Create( pszDstFilenameRO2VY, pCount, lCount, 3, GDT_Float64,
|
||||
papszOptions );
|
||||
|
||||
poDstDSRO2VY->SetGeoTransform( adfGeoTransform );
|
||||
|
@ -658,10 +646,11 @@ void geoGrid::geogrid()
|
|||
// GDALRasterBand *poBand3Alt;
|
||||
poBand1RO2VY = poDstDSRO2VY->GetRasterBand(1);
|
||||
poBand2RO2VY = poDstDSRO2VY->GetRasterBand(2);
|
||||
// poBand3Alt = poDstDSAlt->GetRasterBand(3);
|
||||
poBand3RO2VY = poDstDSRO2VY->GetRasterBand(3);
|
||||
poBand1RO2VY->SetNoDataValue(nodata_out);
|
||||
poBand2RO2VY->SetNoDataValue(nodata_out);
|
||||
// poBand3Alt->SetNoDataValue(nodata_out);
|
||||
poBand3RO2VY->SetNoDataValue(nodata_out);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -672,7 +661,7 @@ void geoGrid::geogrid()
|
|||
|
||||
|
||||
// ground range and azimuth pixel size
|
||||
double grd_res, azm_res;
|
||||
// double grd_res, azm_res;
|
||||
|
||||
// double incang = 38.0*deg2rad;
|
||||
double incang = incidenceAngle;
|
||||
|
@ -945,12 +934,16 @@ void geoGrid::geogrid()
|
|||
{
|
||||
schrng1[0] = srxLine[jj];
|
||||
schrng1[1] = sryLine[jj];
|
||||
schrng2[0] = -srxLine[jj];
|
||||
schrng2[1] = sryLine[jj];
|
||||
|
||||
schrng1[0] *= std::max(max_factor*((dt_unity-1)*max_factor+(max_factor-1)-(max_factor-1)*dt/24.0/3600.0)/((dt_unity-1)*max_factor),1.0);
|
||||
schrng1[0] = std::min(std::max(schrng1[0],lower_thld),upper_thld);
|
||||
schrng1[1] *= std::max(max_factor*((dt_unity-1)*max_factor+(max_factor-1)-(max_factor-1)*dt/24.0/3600.0)/((dt_unity-1)*max_factor),1.0);
|
||||
schrng1[1] = std::min(std::max(schrng1[1],lower_thld),upper_thld);
|
||||
|
||||
schrng2[0] = -schrng1[0];
|
||||
schrng2[1] = schrng1[1];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Convert from DEM coordinates to LLH inplace
|
||||
fwdTrans->Transform(1, llh, llh+1, llh+2);
|
||||
|
@ -1039,8 +1032,8 @@ void geoGrid::geogrid()
|
|||
// {
|
||||
// std::cout << "\n" << lOff+ii << " " << pOff+jj << " " << demLine[jj] << "\n";
|
||||
// }
|
||||
rgind = std::round((rngpix - startingRange) / dr) + 1.;
|
||||
azind = std::round((tline - sensingStart) * prf) + 1.;
|
||||
rgind = std::round((rngpix - startingRange) / dr) + 0.;
|
||||
azind = std::round((tline - sensingStart) * prf) + 0.;
|
||||
|
||||
|
||||
//*********************Slant-range vector
|
||||
|
@ -1212,7 +1205,7 @@ void geoGrid::geogrid()
|
|||
}
|
||||
|
||||
|
||||
if ((rgind > nPixels)|(rgind < 1)|(azind > nLines)|(azind < 1))
|
||||
if ((rgind > nPixels-1)|(rgind < 1-1)|(azind > nLines-1)|(azind < 1-1))
|
||||
{
|
||||
raster1[jj] = nodata_out;
|
||||
raster2[jj] = nodata_out;
|
||||
|
@ -1229,10 +1222,10 @@ void geoGrid::geogrid()
|
|||
|
||||
raster1a[jj] = nodata_out;
|
||||
raster1b[jj] = nodata_out;
|
||||
// raster1c[jj] = nodata_out;
|
||||
raster1c[jj] = nodata_out;
|
||||
raster2a[jj] = nodata_out;
|
||||
raster2b[jj] = nodata_out;
|
||||
// raster2c[jj] = nodata_out;
|
||||
raster2c[jj] = nodata_out;
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -1277,9 +1270,17 @@ void geoGrid::geogrid()
|
|||
raster2b[jj] = nodata_out;
|
||||
}
|
||||
|
||||
for(int pp=0; pp<3; pp++)
|
||||
{
|
||||
targXYZ[pp] -= xyz[pp];
|
||||
}
|
||||
raster1c[jj] = dr/dt*365.0*24.0*3600.0*1;
|
||||
raster2c[jj] = norm_C(targXYZ)/dt*365.0*24.0*3600.0*1;
|
||||
|
||||
|
||||
if (srxname != "")
|
||||
{
|
||||
if ((vxname != "")&(vel[0] == nodata))
|
||||
if ((schrng1[0] == nodata)|(schrng1[0] == 0))
|
||||
{
|
||||
sr_raster11[jj] = 0;
|
||||
sr_raster22[jj] = 0;
|
||||
|
@ -1313,31 +1314,49 @@ void geoGrid::geogrid()
|
|||
|
||||
if (csminxname != "")
|
||||
{
|
||||
csmin_raster11[jj] = csminxLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_grd;
|
||||
csmin_raster22[jj] = csminyLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_azm;
|
||||
if (csminxLine[jj] == nodata)
|
||||
{
|
||||
csmin_raster11[jj] = nodata_out;
|
||||
csmin_raster22[jj] = nodata_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
csmin_raster11[jj] = csminxLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_grd;
|
||||
csmin_raster22[jj] = csminyLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_azm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (csmaxxname != "")
|
||||
{
|
||||
csmax_raster11[jj] = csmaxxLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_grd;
|
||||
csmax_raster22[jj] = csmaxyLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_azm;
|
||||
if (csmaxxLine[jj] == nodata)
|
||||
{
|
||||
csmax_raster11[jj] = nodata_out;
|
||||
csmax_raster22[jj] = nodata_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
csmax_raster11[jj] = csmaxxLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_grd;
|
||||
csmax_raster22[jj] = csmaxyLine[jj] / ChipSizeX0 * ChipSizeX0_PIX_azm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ssmname != "")
|
||||
{
|
||||
ssm_raster[jj] = ssmLine[jj];
|
||||
if (ssmLine[jj] == nodata)
|
||||
{
|
||||
ssm_raster[jj] = nodata_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
ssm_raster[jj] = ssmLine[jj];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// raster1a[jj] = los[0]*dt/dr/365.0/24.0/3600.0;
|
||||
// raster1b[jj] = los[1]*dt/dr/365.0/24.0/3600.0;
|
||||
// raster1c[jj] = los[2]*dt/dr/365.0/24.0/3600.0;
|
||||
// raster2a[jj] = temp[0]*dt/norm_C(alt)/365.0/24.0/3600.0;
|
||||
// raster2b[jj] = temp[1]*dt/norm_C(alt)/365.0/24.0/3600.0;
|
||||
// raster2c[jj] = temp[2]*dt/norm_C(alt)/365.0/24.0/3600.0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1398,14 +1417,15 @@ void geoGrid::geogrid()
|
|||
raster1a, pCount, 1, GDT_Float64, 0, 0 );
|
||||
poBand2RO2VX->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
raster1b, pCount, 1, GDT_Float64, 0, 0 );
|
||||
// poBand3Los->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
// raster1c, pCount, 1, GDT_Float64, 0, 0 );
|
||||
poBand3RO2VX->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
raster1c, pCount, 1, GDT_Float64, 0, 0 );
|
||||
poBand1RO2VY->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
raster2a, pCount, 1, GDT_Float64, 0, 0 );
|
||||
poBand2RO2VY->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
raster2b, pCount, 1, GDT_Float64, 0, 0 );
|
||||
// poBand3Alt->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
// raster2c, pCount, 1, GDT_Float64, 0, 0 );
|
||||
poBand3RO2VY->RasterIO( GF_Write, 0, ii, pCount, 1,
|
||||
raster2c, pCount, 1, GDT_Float64, 0, 0 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1451,6 +1471,7 @@ void geoGrid::geogrid()
|
|||
|
||||
/* Once we're done, close properly the dataset */
|
||||
GDALClose( (GDALDatasetH) poDstDSRO2VY );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue