Hide rubbersheeting scipy/astropy imports

Recent rubbersheeting changes added scipy and astropy imports which
are not otherwise needed. Due to isce2's eager import behavior this
causes errors when using unrelated functionality. We can fix this
by tucking these imports away inside their function definitions.

To reproduce:
`python3 -c "import isce; from stripmapApp import Insar"`
(without scipy/astropy installed)
LT1AB
Ryan Burns 2019-12-14 12:20:41 -08:00
parent 54d7237329
commit 537bae03d9
3 changed files with 31 additions and 10 deletions

View File

@ -6,7 +6,6 @@
import isce import isce
import isceobj import isceobj
from osgeo import gdal from osgeo import gdal
from scipy import ndimage
import numpy as np import numpy as np
import os import os
@ -24,6 +23,9 @@ def fill(data, invalid=None):
Output: Output:
Return a filled array. Return a filled array.
""" """
from scipy import ndimage
if invalid is None: invalid = np.isnan(data) if invalid is None: invalid = np.isnan(data)
ind = ndimage.distance_transform_edt(invalid, ind = ndimage.distance_transform_edt(invalid,
@ -35,6 +37,8 @@ def fill(data, invalid=None):
def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName):
#masking and Filtering #masking and Filtering
from scipy import ndimage
##Read in the offset file ##Read in the offset file
ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly)
Offset = ds.GetRasterBand(1).ReadAsArray() Offset = ds.GetRasterBand(1).ReadAsArray()

View File

@ -9,14 +9,14 @@
import isce import isce
import isceobj import isceobj
from osgeo import gdal from osgeo import gdal
from scipy import ndimage
from astropy.convolution import convolve
import numpy as np import numpy as np
import os import os
def mask_filterNoSNR(denseOffsetFile,filterSize,outName): def mask_filterNoSNR(denseOffsetFile,filterSize,outName):
# Masking the offsets with a data-based approach # Masking the offsets with a data-based approach
from scipy import ndimage
# Open the offsets # Open the offsets
ds = gdal.Open(denseOffsetFile+'.vrt',gdal.GA_ReadOnly) ds = gdal.Open(denseOffsetFile+'.vrt',gdal.GA_ReadOnly)
off_az = ds.GetRasterBand(1).ReadAsArray() off_az = ds.GetRasterBand(1).ReadAsArray()
@ -79,6 +79,9 @@ def mask_filterNoSNR(denseOffsetFile,filterSize,outName):
def off_masking(off,filterSize,thre=2): def off_masking(off,filterSize,thre=2):
from scipy import ndimage
# Define the mask to fill the offsets # Define the mask to fill the offsets
vram = ndimage.median_filter(off.real, filterSize) vram = ndimage.median_filter(off.real, filterSize)
vazm = ndimage.median_filter(off.imag, filterSize) vazm = ndimage.median_filter(off.imag, filterSize)
@ -112,6 +115,8 @@ def fill(data, invalid=None):
def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName):
#masking and Filtering #masking and Filtering
from scipy import ndimage
##Read in the offset file ##Read in the offset file
ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly)
Offset = ds.GetRasterBand(band).ReadAsArray() Offset = ds.GetRasterBand(band).ReadAsArray()
@ -155,6 +160,8 @@ def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outNam
def fill_with_smoothed(off,filterSize): def fill_with_smoothed(off,filterSize):
from astropy.convolution import convolve
off_2filt=np.copy(off) off_2filt=np.copy(off)
kernel = np.ones((filterSize,filterSize),np.float32)/(filterSize*filterSize) kernel = np.ones((filterSize,filterSize),np.float32)/(filterSize*filterSize)
loop = 0 loop = 0

View File

@ -9,15 +9,14 @@
import isce import isce
import isceobj import isceobj
from osgeo import gdal from osgeo import gdal
from scipy import ndimage
import numpy as np import numpy as np
import os import os
from astropy.convolution import convolve
def mask_filterNoSNR(denseOffsetFile,filterSize,outName): def mask_filterNoSNR(denseOffsetFile,filterSize,outName):
# Masking the offsets with a data-based approach # Masking the offsets with a data-based approach
from scipy import ndimage
# Open the offsets # Open the offsets
ds = gdal.Open(denseOffsetFile+'.vrt',gdal.GA_ReadOnly) ds = gdal.Open(denseOffsetFile+'.vrt',gdal.GA_ReadOnly)
off_az = ds.GetRasterBand(1).ReadAsArray() off_az = ds.GetRasterBand(1).ReadAsArray()
@ -78,6 +77,9 @@ def mask_filterNoSNR(denseOffsetFile,filterSize,outName):
return return
def off_masking(off,filterSize,thre=2): def off_masking(off,filterSize,thre=2):
from scipy import ndimage
vram = ndimage.median_filter(off.real, filterSize) vram = ndimage.median_filter(off.real, filterSize)
vazm = ndimage.median_filter(off.imag, filterSize) vazm = ndimage.median_filter(off.imag, filterSize)
@ -100,6 +102,8 @@ def fill(data, invalid=None):
Output: Output:
Return a filled array. Return a filled array.
""" """
from scipy import ndimage
if invalid is None: invalid = np.isnan(data) if invalid is None: invalid = np.isnan(data)
ind = ndimage.distance_transform_edt(invalid, ind = ndimage.distance_transform_edt(invalid,
@ -109,6 +113,8 @@ def fill(data, invalid=None):
def fill_with_smoothed(off,filterSize): def fill_with_smoothed(off,filterSize):
from astropy.convolution import convolve
off_2filt=np.copy(off) off_2filt=np.copy(off)
kernel = np.ones((filterSize,filterSize),np.float32)/(filterSize*filterSize) kernel = np.ones((filterSize,filterSize),np.float32)/(filterSize*filterSize)
loop = 0 loop = 0
@ -131,6 +137,8 @@ def fill_with_smoothed(off,filterSize):
def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName):
#masking and Filtering #masking and Filtering
from scipy import ndimage
##Read in the offset file ##Read in the offset file
ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly)
Offset = ds.GetRasterBand(band).ReadAsArray() Offset = ds.GetRasterBand(band).ReadAsArray()
@ -236,6 +244,8 @@ def resampleOffset(maskedFiltOffset, geometryOffset, outName):
def runRubbersheetRange(self): def runRubbersheetRange(self):
from scipy import ndimage
if not self.doRubbersheetingRange: if not self.doRubbersheetingRange:
print('Rubber sheeting in azimuth not requested ... skipping') print('Rubber sheeting in azimuth not requested ... skipping')
return return