diff --git a/mintpy/defaults/smallbaselineApp.cfg b/mintpy/defaults/smallbaselineApp.cfg index 453857cd5..3de1be1d7 100644 --- a/mintpy/defaults/smallbaselineApp.cfg +++ b/mintpy/defaults/smallbaselineApp.cfg @@ -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 diff --git a/mintpy/defaults/smallbaselineApp_auto.cfg b/mintpy/defaults/smallbaselineApp_auto.cfg index a7819d6ac..2067d586a 100644 --- a/mintpy/defaults/smallbaselineApp_auto.cfg +++ b/mintpy/defaults/smallbaselineApp_auto.cfg @@ -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 diff --git a/mintpy/load_data.py b/mintpy/load_data.py index 29f288115..ffd6c5d53 100755 --- a/mintpy/load_data.py +++ b/mintpy/load_data.py @@ -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]) @@ -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']: @@ -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 = { **GEOMETRY_DSET_NAME2TEMPLATE_KEY, **IFGRAM_DSET_NAME2TEMPLATE_KEY, @@ -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) diff --git a/mintpy/objects/stackDict.py b/mintpy/objects/stackDict.py index f27b36ecc..2ac1eff86 100644 --- a/mintpy/objects/stackDict.py +++ b/mintpy/objects/stackDict.py @@ -28,7 +28,7 @@ utils0 as ut, attribute as attr, ) - +from mintpy import multilook as mlk ######################################################################################## class ifgramStackDict: @@ -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: @@ -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, @@ -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 @@ -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 @@ -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]):