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

View File

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

View File

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