def read_inps_dict2ifgram_stack_dict_object(inpsDict): """Read input arguments into dict of ifgramStackDict object""" # inpsDict --> dsPathDict print('-'*50) print('searching interferometric pairs info') print('input data files:') maxDigit = max([len(i) for i in list(datasetName2templateKey.keys())]) dsPathDict = {} dsNumDict = {} for dsName in [i for i in ifgramDatasetNames if i in datasetName2templateKey.keys()]: key = datasetName2templateKey[dsName] if key in inpsDict.keys(): files = sorted(glob.glob(str(inpsDict[key]))) if len(files) > 0: dsPathDict[dsName] = files dsNumDict[dsName] = len(files) print('{:<{width}}: {path}'.format(dsName, width=maxDigit, path=inpsDict[key])) # Check 1: required dataset dsName0 = 'unwrapPhase' if dsName0 not in dsPathDict.keys(): print('WARNING: No reqired {} data files found!'.format(dsName0)) return None # Check 2: number of files for all dataset types for key, value in dsNumDict.items(): print('number of {:<{width}}: {num}'.format(key, width=maxDigit, num=value)) dsNumList = list(dsNumDict.values()) if any(i != dsNumList[0] for i in dsNumList): msg = 'WARNING: NOT all types of dataset have the same number of files.' msg += ' -> skip interferograms with missing files and continue.' print(msg) #raise Exception(msg) # Check 3: data dimension for all files # dsPathDict --> pairsDict --> stackObj dsNameList = list(dsPathDict.keys()) pairsDict = {} for dsPath in dsPathDict[dsName0]: dates = ptime.yyyymmdd(readfile.read_attribute(dsPath)['DATE12'].split('-')) ##################################### # A dictionary of data files for a given pair. # One pair may have several types of dataset. # example ifgramPathDict = {'unwrapPhase': /pathToFile/filt.unw, 'iono':/PathToFile/iono.bil} # All path of data file must contain the master and slave date, either in file name or folder name. ifgramPathDict = {} for i in range(len(dsNameList)): dsName = dsNameList[i] dsPath1 = dsPathDict[dsName][0] if all(d[2:8] in dsPath1 for d in dates): ifgramPathDict[dsName] = dsPath1 else: dsPath2 = [i for i in dsPathDict[dsName] if all(d[2:8] in i for d in dates)] if len(dsPath2) > 0: ifgramPathDict[dsName] = dsPath2[0] else: print('WARNING: {} file missing for pair {}'.format(dsName, dates)) ifgramObj = ifgramDict(dates=tuple(dates), datasetDict=ifgramPathDict) pairsDict[tuple(dates)] = ifgramObj if len(pairsDict) > 0: stackObj = ifgramStackDict(pairsDict=pairsDict) else: stackObj = None return stackObj
def read_inps_dict2ifgram_stack_dict_object(iDict): """Read input arguments into dict of ifgramStackDict object""" # iDict --> dsPathDict print('-'*50) print('searching interferometric pairs info') print('input data files:') maxDigit = max([len(i) for i in list(iDict['ds_name2key'].keys())]) dsPathDict = {} for dsName in [i for i in ifgramDatasetNames if i in iDict['ds_name2key'].keys()]: key = iDict['ds_name2key'][dsName] if key in iDict.keys(): files = sorted(glob.glob(str(iDict[key]))) if len(files) > 0: dsPathDict[dsName] = files print('{:<{width}}: {path}'.format(dsName, width=maxDigit, path=iDict[key])) # Check 1: required dataset dsName0s = ['unwrapPhase', 'azimuthOffset'] dsName0 = [i for i in dsName0s if i in dsPathDict.keys()] if len(dsName0) == 0: print('WARNING: No reqired {} data files found!'.format(dsName0s)) return None else: dsName0 = dsName0[0] # Check 2: data dimension for unwrapPhase files dsPathDict = skip_files_with_inconsistent_size(dsPathDict, pix_box=iDict['box'], dsName=dsName0) # Check 3: number of files for all dataset types # dsPathDict --> dsNumDict dsNumDict = {} for key in dsPathDict.keys(): num_file = len(dsPathDict[key]) dsNumDict[key] = num_file print('number of {:<{width}}: {num}'.format(key, width=maxDigit, num=num_file)) dsNumList = list(dsNumDict.values()) if any(i != dsNumList[0] for i in dsNumList): msg = 'WARNING: NOT all types of dataset have the same number of files.' msg += ' -> skip interferograms with missing files and continue.' print(msg) #raise Exception(msg) # dsPathDict --> pairsDict --> stackObj dsNameList = list(dsPathDict.keys()) pairsDict = {} for dsPath in dsPathDict[dsName0]: # date string used in the file/dir path # YYYYMMDDTHHMM for uavsar # YYYYMMDD for all the others date12 = readfile.read_attribute(dsPath)['DATE12'].replace('_','-') dates = ptime.yyyymmdd(date12.split('-')) ##################################### # A dictionary of data files for a given pair. # One pair may have several types of dataset. # example ifgramPathDict = {'unwrapPhase': /pathToFile/filt.unw, # 'ionoPhase' : /PathToFile/iono.bil} # All path of data file must contain the reference and secondary date, either in file name or folder name. ifgramPathDict = {} for i in range(len(dsNameList)): dsName = dsNameList[i] dsPath1 = dsPathDict[dsName][0] if all(d[2:] in dsPath1 for d in dates): ifgramPathDict[dsName] = dsPath1 else: dsPath2 = [i for i in dsPathDict[dsName] if all(d[2:] in i for d in dates)] if len(dsPath2) > 0: ifgramPathDict[dsName] = dsPath2[0] else: print('WARNING: {} file missing for pair {}'.format(dsName, dates)) # initiate ifgramDict object ifgramObj = ifgramDict(datasetDict=ifgramPathDict) # update pairsDict object pairsDict[tuple(dates)] = ifgramObj if len(pairsDict) > 0: stackObj = ifgramStackDict(pairsDict=pairsDict, dsName0=dsName0) else: stackObj = None return stackObj
def read_inps_dict2ifgram_stack_dict_object(iDict): """Read input arguments into dict of ifgramStackDict object""" # iDict --> dsPathDict print('-'*50) print('searching interferometric pairs info') print('input data files:') maxDigit = max([len(i) for i in list(iDict['ds_name2key'].keys())]) dsPathDict = {} for dsName in [i for i in ifgramDatasetNames if i in iDict['ds_name2key'].keys()]: key = iDict['ds_name2key'][dsName] if key in iDict.keys(): files = sorted(glob.glob(str(iDict[key]))) if len(files) > 0: dsPathDict[dsName] = files print('{:<{width}}: {path}'.format(dsName, width=maxDigit, path=iDict[key])) # Check 1: required dataset dsName0s = ['unwrapPhase', 'azimuthOffset'] dsName0 = [i for i in dsName0s if i in dsPathDict.keys()] if len(dsName0) == 0: print('WARNING: No reqired {} data files found!'.format(dsName0s)) return None else: dsName0 = dsName0[0] # Check 2: data dimension for unwrapPhase files dsPathDict = skip_files_with_inconsistent_size(dsPathDict, pix_box=iDict['box'], dsName=dsName0) # Check 3: number of files for all dataset types # dsPathDict --> dsNumDict dsNumDict = {} for key in dsPathDict.keys(): num_file = len(dsPathDict[key]) dsNumDict[key] = num_file print('number of {:<{width}}: {num}'.format(key, width=maxDigit, num=num_file)) dsNumList = list(dsNumDict.values()) if any(i != dsNumList[0] for i in dsNumList): msg = 'WARNING: NOT all types of dataset have the same number of files.' msg += ' -> skip interferograms with missing files and continue.' print(msg) #raise Exception(msg) # dsPathDict --> pairsDict --> stackObj dsNameList = list(dsPathDict.keys()) ##################################### # A dictionary of data file paths for a list of pairs, e.g.: # pairsDict = { # ('date1', 'date2') : ifgramPathDict1, # ('date1', 'date3') : ifgramPathDict2, # ..., # } pairsDict = {} for i, dsPath0 in enumerate(dsPathDict[dsName0]): # date string used in the file/dir path # YYYYDDD for gmtsar [modern Julian date] # YYYYMMDDTHHMM for uavsar # YYYYMMDD for all the others date6s = readfile.read_attribute(dsPath0)['DATE12'].replace('_','-').split('-') if iDict['processor'] == 'gmtsar': date12MJD = os.path.basename(os.path.dirname(dsPath0)) else: date12MJD = None ##################################### # A dictionary of data file paths for a given pair. # One pair may have several types of dataset, e.g.: # ifgramPathDict1 = { # 'unwrapPhase': /dirPathToFile/filt_fine.unw, # 'coherence' : /dirPathToFile/filt_fine.cor, # 'ionoPhase' : /dirPathToFile/iono.bil, # ... # } # All path of data file must contain the reference and secondary date, in file/dir name. ifgramPathDict = {} for dsName in dsNameList: # search the matching data file for the given date12 # 1st guess: file in the same order as the one for dsName0 dsPath1 = dsPathDict[dsName][i] if (all(d6 in dsPath1 for d6 in date6s) or (date12MJD and date12MJD in dsPath1)): ifgramPathDict[dsName] = dsPath1 else: # 2nd guess: any file in the list dsPath2 = [p for p in dsPathDict[dsName] if (all(d6 in p for d6 in date6s) or (date12MJD and date12MJD in dsPath1))] if len(dsPath2) > 0: ifgramPathDict[dsName] = dsPath2[0] else: print('WARNING: {:>18} file missing for pair {}'.format(dsName, date6s)) # initiate ifgramDict object ifgramObj = ifgramDict(datasetDict=ifgramPathDict) # update pairsDict object date8s = ptime.yyyymmdd(date6s) pairsDict[tuple(date8s)] = ifgramObj if len(pairsDict) > 0: stackObj = ifgramStackDict(pairsDict=pairsDict, dsName0=dsName0) else: stackObj = None return stackObj
def read_inps_dict2ifgram_stack_dict_object(inpsDict): """Read input arguments into dict of ifgramStackDict object""" # inpsDict --> dsPathDict print('-'*50) print('searching interferometric pairs info') print('input data files:') maxDigit = max([len(i) for i in list(datasetName2templateKey.keys())]) dsPathDict = {} dsNumDict = {} for dsName in [i for i in ifgramDatasetNames if i in datasetName2templateKey.keys()]: key = datasetName2templateKey[dsName] if key in inpsDict.keys(): files = sorted(glob.glob(str(inpsDict[key]))) if len(files) > 0: dsPathDict[dsName] = files dsNumDict[dsName] = len(files) print('{:<{width}}: {path}'.format(dsName, width=maxDigit, path=inpsDict[key])) # Check 1: required dataset dsName0 = 'unwrapPhase' if dsName0 not in dsPathDict.keys(): print('WARNING: No reqired {} data files found!'.format(dsName0)) return None # Check 2: number of files for all dataset types for key, value in dsNumDict.items(): print('number of {:<{width}}: {num}'.format(key, width=maxDigit, num=value)) dsNumList = list(dsNumDict.values()) if any(i != dsNumList[0] for i in dsNumList): msg = 'WARNING: NOT all types of dataset have the same number of files.' msg += ' -> skip interferograms with missing files and continue.' print(msg) #raise Exception(msg) # Check 3: data dimension for all files # dsPathDict --> pairsDict --> stackObj dsNameList = list(dsPathDict.keys()) pairsDict = {} for dsPath in dsPathDict[dsName0]: dates = ptime.yyyymmdd(readfile.read_attribute(dsPath)['DATE12'].split('-')) ##################################### # A dictionary of data files for a given pair. # One pair may have several types of dataset. # example ifgramPathDict = {'unwrapPhase': /pathToFile/filt.unw, 'iono':/PathToFile/iono.bil} # All path of data file must contain the master and slave date, either in file name or folder name. ifgramPathDict = {} for i in range(len(dsNameList)): dsName = dsNameList[i] dsPath1 = dsPathDict[dsName][0] if all(d[2:8] in dsPath1 for d in dates): ifgramPathDict[dsName] = dsPath1 else: dsPath2 = [i for i in dsPathDict[dsName] if all(d[2:8] in i for d in dates)] if len(dsPath2) > 0: ifgramPathDict[dsName] = dsPath2[0] else: print('WARNING: {} file missing for pair {}'.format(dsName, dates)) ifgramObj = ifgramDict(dates=tuple(dates), datasetDict=ifgramPathDict) pairsDict[tuple(dates)] = ifgramObj if len(pairsDict) > 0: stackObj = ifgramStackDict(pairsDict=pairsDict) else: stackObj = None return stackObj