Skip to content

Commit

Permalink
load_data: multilook x/ystep
Browse files Browse the repository at this point in the history
Allow different options of multilook interpolation while loading data by parsing a method variable
+ 'nearest' method (default)
+ 'mean'    method
+ 'median'  method

Propagate the method variable from the template file named as mintpy.load.stepMethod

Merge and resolve conflicts with insarlab#796
  • Loading branch information
yuankailiu authored and yunjunz committed Jun 21, 2022
1 parent d17c7d9 commit a1ad104
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions mintpy/defaults/smallbaselineApp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mintpy.load.bperpFile = auto #[path pattern of 2D perpendicular baseline
## multilook while loading data with nearest interpolation, to reduce dataset size
mintpy.load.ystep = auto #[int >= 1], auto for 1 - no multilooking
mintpy.load.xstep = auto #[int >= 1], auto for 1 - no multilooking
mintpy.load.stepMethod = auto #[nearest, mean, median], auto for nearest - lines/rows skipping approach
##---------subset (optional):
## if both yx and lalo are specified, use lalo option unless a) no lookup file AND b) dataset is in radar coord
mintpy.subset.yx = auto #[y0:y1,x0:x1 / no], auto for no
Expand Down
1 change: 1 addition & 0 deletions mintpy/defaults/smallbaselineApp_auto.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mintpy.load.compression = no
##---------multilook (optional):
mintpy.load.ystep = 1
mintpy.load.xstep = 1
mintpy.load.stepMethod = nearest
##-------subset (optional)
mintpy.subset.yx = no
mintpy.subset.lalo = no
Expand Down
8 changes: 5 additions & 3 deletions mintpy/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def read_inps2dict(inps):
key_list = [i.split(prefix)[1] for i in template.keys() if i.startswith(prefix)]
for key in key_list:
value = template[prefix+key]
if key in ['processor', 'autoPath', 'updateMode', 'compression']:
if key in ['processor', 'autoPath', 'updateMode', 'compression', 'stepMethod']:
iDict[key] = template[prefix+key]
elif key in ['xstep', 'ystep']:
iDict[key] = int(template[prefix+key])
Expand All @@ -204,6 +204,7 @@ def read_inps2dict(inps):

iDict['xstep'] = iDict.get('xstep', 1)
iDict['ystep'] = iDict.get('ystep', 1)
iDict['stepMethod'] = iDict.get('stepMethod', 'nearest')

# PROJECT_NAME --> PLATFORM
if not iDict['PROJECT_NAME']:
Expand Down Expand Up @@ -895,13 +896,13 @@ def main(iargs=None):
print('-'*50)
print('updateMode : {}'.format(iDict['updateMode']))
print('compression: {}'.format(iDict['compression']))
print('x/ystep: {}/{}'.format(iDict['xstep'], iDict['ystep']))
print('x/ystep: {}/{}; multilook method: {}'.format(iDict['xstep'], iDict['ystep'], iDict['stepMethod']))
kwargs = dict(updateMode=iDict['updateMode'], xstep=iDict['xstep'], ystep=iDict['ystep'])

# read subset info [need the metadata from above]
iDict = read_subset_box(iDict)

# geometry in geo / radar coordinates
# geometry in geo / radar coordinates
geom_dset_name2template_key = {
**GEOM_DSET_NAME2TEMPLATE_KEY,
**IFG_DSET_NAME2TEMPLATE_KEY,
Expand Down Expand Up @@ -957,6 +958,7 @@ def main(iargs=None):
box=iDict['box'],
xstep=iDict['xstep'],
ystep=iDict['ystep'],
ystep=iDict['stepMethod'],
compression=iDict['compression'],
extra_metadata=extraDict,
geom_obj=geom_obj)
Expand Down
35 changes: 22 additions & 13 deletions mintpy/objects/stackDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
utils0 as ut,
attribute as attr,
)

from mintpy import multilook as mlk

########################################################################################
class ifgramStackDict:
Expand Down Expand Up @@ -97,7 +97,7 @@ def get_dataset_data_type(self, dsName):
dataType = dataTypeDict[metadata.get('DATA_TYPE', 'float32').lower()]
return dataType

def write2hdf5(self, outputFile='ifgramStack.h5', access_mode='w', box=None, xstep=1, ystep=1,
def write2hdf5(self, outputFile='ifgramStack.h5', access_mode='w', box=None, xstep=1, ystep=1, method='nearest',
compression=None, extra_metadata=None, geom_obj=None):
"""Save/write an ifgramStackDict object into an HDF5 file with the structure defined in:
Expand Down Expand Up @@ -151,6 +151,9 @@ def write2hdf5(self, outputFile='ifgramStack.h5', access_mode='w', box=None, xst
if dsName in ['connectComponent']:
dsDataType = np.int16
dsCompression = 'lzf'
stepMethod = 'nearest'
else:
stepMethod = str(method)

print(('create dataset /{d:<{w}} of {t:<25} in size of {s}'
' with compression = {c}').format(d=dsName,
Expand Down Expand Up @@ -180,6 +183,7 @@ def write2hdf5(self, outputFile='ifgramStack.h5', access_mode='w', box=None, xst
box=box,
xstep=xstep,
ystep=ystep,
method=stepMethod,
resize2shape=resize2shape)[0]

# special handling for offset covariance file
Expand Down Expand Up @@ -292,13 +296,14 @@ def __init__(self, name='ifgram', datasetDict={}, metadata=None):
for key, value in metadata.items():
setattr(self, key, value)

def read(self, family, box=None, xstep=1, ystep=1, resize2shape=None):
def read(self, family, box=None, xstep=1, ystep=1, method='nearest', resize2shape=None):
"""Read data for the given dataset name.
Parameters: self - ifgramDict object
family - str, dataset name
box - tuple of 4 int, in (x0, y0, x1, y1) with respect to the full resolution
x/ystep - int, number of pixels to skip, with respect to the full resolution
method - str, ['nearest', 'mean', 'median']. Interpolation method. Default is 'nearest' - skipping rows/lines
resize2shape - tuple of 2 int, resize the native matrix to the given shape
Set to None for not resizing
Returns: data - 2D np.ndarray
Expand Down Expand Up @@ -329,16 +334,20 @@ def read(self, family, box=None, xstep=1, ystep=1, resize2shape=None):
data = data[box[1]:box[3],
box[0]:box[2]]

# multilook - nearest resampling
if xstep * ystep > 1:
# output data size
xsize = int(data.shape[1] / xstep)
ysize = int(data.shape[0] / ystep)
# sampling
data = data[int(ystep/2)::ystep,
int(xstep/2)::xstep]
data = data[:ysize, :xsize]

if method == 'nearest':
# multilook - nearest resampling
if xstep * ystep > 1:
# output data size
xsize = int(data.shape[1] / xstep)
ysize = int(data.shape[0] / ystep)
# sampling
data = data[int(ystep/2)::ystep,
int(xstep/2)::xstep]
data = data[:ysize, :xsize]
else:
# multilook - mean or median resampling
if xstep * ystep > 1:
data = mlk.multilook_data(data, lks_y=ystep, lks_x=xstep, method=method)
return data, meta

def get_size(self, family=ifgramDatasetNames[0]):
Expand Down

0 comments on commit a1ad104

Please sign in to comment.