def check_inputs(inps): parser = create_parser() # output directories/files atr = dict() mintpy_dir = None if inps.timeseries_file: atr = readfile.read_attribute(inps.timeseries_file) mintpy_dir = os.path.dirname(inps.timeseries_file) if not inps.outfile: fbase = os.path.splitext(inps.timeseries_file)[0] inps.outfile = '{}_{}.h5'.format(fbase, inps.trop_model) elif inps.geom_file: atr = readfile.read_attribute(inps.geom_file) mintpy_dir = os.path.join(os.path.dirname(inps.geom_file), '..') else: mintpy_dir = os.path.abspath(os.getcwd()) # trop_file inps.trop_file = os.path.join(mintpy_dir, 'inputs/{}.h5'.format(inps.trop_model)) print('output tropospheric delay file: {}'.format(inps.trop_file)) # hour if not inps.hour: if 'CENTER_LINE_UTC' in atr.keys(): inps.hour = ptime.closest_weather_product_time(atr['CENTER_LINE_UTC'], inps.trop_model) else: parser.print_usage() raise Exception('no input for hour') print('time of cloest available product: {}:00 UTC'.format(inps.hour)) # date list if inps.timeseries_file: print('read date list from timeseries file: {}'.format(inps.timeseries_file)) ts_obj = timeseries(inps.timeseries_file) ts_obj.open(print_msg=False) inps.date_list = ts_obj.dateList elif len(inps.date_list) == 1: if os.path.isfile(inps.date_list[0]): print('read date list from text file: {}'.format(inps.date_list[0])) inps.date_list = ptime.yyyymmdd(np.loadtxt(inps.date_list[0], dtype=bytes, usecols=(0,)).astype(str).tolist()) else: parser.print_usage() raise Exception('ERROR: input date list < 2') # Grib data directory inps.grib_dir = os.path.join(inps.weather_dir, inps.trop_model) if not os.path.isdir(inps.grib_dir): os.makedirs(inps.grib_dir) print('making directory: '+inps.grib_dir) # Date list to grib file list inps.grib_file_list = date_list2grib_file(inps.date_list, inps.hour, inps.trop_model, inps.grib_dir) if 'REF_Y' in atr.keys(): inps.ref_yx = [int(atr['REF_Y']), int(atr['REF_X'])] print('reference pixel: {}'.format(inps.ref_yx)) # Coordinate system: geocoded or not inps.geocoded = False if 'Y_FIRST' in atr.keys(): inps.geocoded = True print('geocoded: {}'.format(inps.geocoded)) # Prepare DEM, inc_angle, lat/lon file for PyAPS to read if inps.geom_file: geom_atr = readfile.read_attribute(inps.geom_file) print('converting DEM/incAngle for PyAPS to read') # DEM data = readfile.read(inps.geom_file, datasetName='height', print_msg=False)[0] inps.dem_file = 'pyapsDem.hgt' writefile.write(data, inps.dem_file, metadata=geom_atr) # inc_angle inps.inc_angle = readfile.read(inps.geom_file, datasetName='incidenceAngle', print_msg=False)[0] inps.inc_angle_file = 'pyapsIncAngle.flt' writefile.write(inps.inc_angle, inps.inc_angle_file, metadata=geom_atr) # latitude try: data = readfile.read(inps.geom_file, datasetName='latitude', print_msg=False)[0] print('converting lat for PyAPS to read') inps.lat_file = 'pyapsLat.flt' writefile.write(data, inps.lat_file, metadata=geom_atr) except: inps.lat_file = None # longitude try: data = readfile.read(inps.geom_file, datasetName='longitude', print_msg=False)[0] print('converting lon for PyAPS to read') inps.lon_file = 'pyapsLon.flt' writefile.write(data, inps.lon_file, metadata=geom_atr) except: inps.lon_file = None return inps, atr
def check_inputs(inps): parser = create_parser() # output directories/files atr = dict() mintpy_dir = None if inps.timeseries_file: atr = readfile.read_attribute(inps.timeseries_file) mintpy_dir = os.path.dirname(inps.timeseries_file) if not inps.outfile: fbase = os.path.splitext(inps.timeseries_file)[0] inps.outfile = '{}_{}.h5'.format(fbase, inps.trop_model) elif inps.geom_file: atr = readfile.read_attribute(inps.geom_file) mintpy_dir = os.path.join(os.path.dirname(inps.geom_file), '..') else: mintpy_dir = os.path.abspath(os.getcwd()) # trop_file inps.trop_file = os.path.join(mintpy_dir, 'inputs/{}.h5'.format(inps.trop_model)) print('output tropospheric delay file: {}'.format(inps.trop_file)) # hour if not inps.hour: if 'CENTER_LINE_UTC' in atr.keys(): inps.hour = ptime.closest_weather_product_time(atr['CENTER_LINE_UTC'], inps.trop_model) else: parser.print_usage() raise Exception('no input for hour') print('time of cloest available product: {}:00 UTC'.format(inps.hour)) # date list if inps.timeseries_file: print('read date list from timeseries file: {}'.format(inps.timeseries_file)) ts_obj = timeseries(inps.timeseries_file) ts_obj.open(print_msg=False) inps.date_list = ts_obj.dateList elif len(inps.date_list) == 1: if os.path.isfile(inps.date_list[0]): print('read date list from text file: {}'.format(inps.date_list[0])) inps.date_list = ptime.yyyymmdd(np.loadtxt(inps.date_list[0], dtype=bytes, usecols=(0,)).astype(str).tolist()) else: parser.print_usage() raise Exception('ERROR: input date list < 2') # Grib data directory inps.grib_dir = os.path.join(inps.weather_dir, inps.trop_model) if not os.path.isdir(inps.grib_dir): os.makedirs(inps.grib_dir) print('making directory: '+inps.grib_dir) # Date list to grib file list inps.grib_file_list = date_list2grib_file(inps.date_list, inps.hour, inps.trop_model, inps.grib_dir) if 'REF_Y' in atr.keys(): inps.ref_yx = [int(atr['REF_Y']), int(atr['REF_X'])] print('reference pixel: {}'.format(inps.ref_yx)) # Coordinate system: geocoded or not inps.geocoded = False if 'Y_FIRST' in atr.keys(): inps.geocoded = True print('geocoded: {}'.format(inps.geocoded)) # Prepare DEM, inc_angle, lat/lon file for PyAPS to read if inps.geom_file: geom_obj = geometry(inps.geom_file) geom_obj.open() print('converting DEM/incAngle for PyAPS to read') # DEM dem = readfile.read(inps.geom_file, datasetName='height', print_msg=False)[0] inps.dem_file = 'pyapsDem.hgt' writefile.write(dem, inps.dem_file, metadata=atr) # inc_angle if 'incidenceAngle' in geom_obj.datasetNames: inps.inc_angle = readfile.read(inps.geom_file, datasetName='incidenceAngle', print_msg=False)[0] else: atr = readfile.read_attribute(inps.timeseries_file) inps.inc_angle = ut.incidence_angle(atr, dem=dem, dimension=0) inps.inc_angle = np.ones(dem.shape, dtype=np.float32) * inps.inc_angle inps.inc_angle_file = 'pyapsIncAngle.flt' writefile.write(inps.inc_angle, inps.inc_angle_file, metadata=atr) # latitude if 'latitude' in geom_obj.datasetNames: data = readfile.read(inps.geom_file, datasetName='latitude', print_msg=False)[0] print('converting lat for PyAPS to read') inps.lat_file = 'pyapsLat.flt' writefile.write(data, inps.lat_file, metadata=atr) else: inps.lat_file = None # longitude if 'longitude' in geom_obj.datasetNames: data = readfile.read(inps.geom_file, datasetName='longitude', print_msg=False)[0] print('converting lon for PyAPS to read') inps.lon_file = 'pyapsLon.flt' writefile.write(data, inps.lon_file, metadata=atr) else: inps.lon_file = None return inps, atr