def mosaic_timescan(burst_inventory, processing_dir, temp_dir, proc_file, cut_to_aoi=False, exec_file=None): # load ard parameters with open(proc_file, 'r') as ard_file: ard_params = json.load(ard_file)['processing parameters'] metrics = ard_params['time-scan ARD']['metrics'] if 'harmonics' in metrics: metrics.remove('harmonics') metrics.extend(['amplitude', 'phase', 'residuals']) if 'percentiles' in metrics: metrics.remove('percentiles') metrics.extend(['p95', 'p5']) # a products list product_list = ['bs.HH', 'bs.VV', 'bs.HV', 'bs.VH', 'coh.VV', 'coh.VH', 'coh.HH', 'coh.HV', 'pol.Entropy', 'pol.Anisotropy', 'pol.Alpha'] tscan_dir = opj(processing_dir, 'Mosaic', 'Timescan') os.makedirs(tscan_dir, exist_ok=True) outfiles = [] for product, metric in itertools.product(product_list, metrics): # **** filelist = glob.glob( opj(processing_dir, '*', 'Timescan', '*{}.{}.tif'.format(product, metric)) ) if not len(filelist) >= 2: continue filelist = ' '.join(filelist) outfile = opj(tscan_dir, '{}.{}.tif'.format(product, metric)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4]) ) if os.path.isfile(check_file): print(' INFO: Mosaic layer {} already ' ' processed.'.format(os.path.basename(outfile))) continue print(' INFO: Mosaicking layer {}.'.format(os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, temp_dir, cut_to_aoi) outfiles.append(outfile) if exec_file: print(' gdalbuildvrt ....command, outfiles') else: # create vrt ras.create_tscan_vrt(tscan_dir, proc_file)
def mosaic_timescan(inventory_df, processing_dir, temp_dir, proc_file, cut_to_aoi=False, exec_file=None): # load ard parameters with open(proc_file, 'r') as ard_file: ard_params = json.load(ard_file)['processing parameters'] metrics = ard_params['time-scan ARD']['metrics'] if 'harmonics' in metrics: metrics.remove('harmonics') metrics.extend(['amplitude', 'phase', 'residuals']) if 'percentiles' in metrics: metrics.remove('percentiles') metrics.extend(['p95', 'p5']) # create out directory of not existent tscan_dir = opj(processing_dir, 'Mosaic', 'Timescan') os.makedirs(tscan_dir, exist_ok=True) outfiles = [] # loop through all pontial proucts for polar, metric in itertools.product(['VV', 'HH', 'VH', 'HV'], metrics): # create a list of files based on polarisation and metric filelist = glob.glob( opj(processing_dir, '*', 'Timescan', '*bs.{}.{}.tif'.format(polar, metric))) # break loop if there are no files if not len(filelist) >= 2: continue # get number filelist = ' '.join(filelist) outfile = opj(tscan_dir, 'bs.{}.{}.tif'.format(polar, metric)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4])) if os.path.isfile(check_file): print(' INFO: Mosaic layer {} already ' ' processed.'.format(os.path.basename(outfile))) continue print(' INFO: Mosaicking layer {}.'.format(os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, temp_dir, cut_to_aoi) outfiles.append(outfile) if exec_file: print(' gdalbuildvrt ....command, outfiles') else: ras.create_tscan_vrt(tscan_dir, proc_file)
def mosaic_timescan( processing_dir, ard_params, cut_to_aoi=False, ): metrics = ard_params['metrics'] if 'harmonics' in metrics: metrics.remove('harmonics') metrics.extend(['amplitude', 'phase', 'residuals']) if 'percentiles' in metrics: metrics.remove('percentiles') metrics.extend(['p95', 'p5']) # create out directory of not existent tscan_dir = opj(processing_dir, 'Mosaic', 'Timescan') os.makedirs(tscan_dir, exist_ok=True) outfiles = [] # loop through all pontial proucts for polar, metric in itertools.product(['VV', 'HH', 'VH', 'HV'], metrics): # create a list of files based on polarisation and metric filelist = glob.glob( opj(processing_dir, '*', 'Timescan', '*TC.{}.{}.tif'.format(polar, metric))) # break loop if there are no files if not len(filelist) >= 2: continue # get number filelist = ' '.join(filelist) outfile = opj(tscan_dir, 'BS.{}.{}.tif'.format(polar, metric)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4])) if os.path.isfile(check_file): logger.debug('INFO: Mosaic layer {} already ' ' processed.'.format(os.path.basename(outfile))) continue logger.debug('INFO: Mosaicking layer {}.'.format( os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, cut_to_aoi) outfiles.append(outfile) create_tscan_vrt(tscan_dir, ard_params)
def mosaic_timeseries(burst_inventory, processing_dir, temp_dir, cut_to_aoi=False, exec_file=None): print(' ------------------------------------') print(' INFO: Mosaicking Time-series layers.') print(' ------------------------------------') # create output folder ts_dir = opj(processing_dir, 'Mosaic', 'Timeseries') os.makedirs(ts_dir, exist_ok=True) # a products list product_list = ['bs.HH', 'bs.VV', 'bs.HV', 'bs.VH', 'coh.VV', 'coh.VH', 'coh.HH', 'coh.HV', 'pol.Entropy', 'pol.Anisotropy', 'pol.Alpha'] # now we loop through each timestep and product for product in product_list: # **** bursts = burst_inventory.bid.unique() nr_of_ts = len(glob.glob(opj( processing_dir, bursts[0], 'Timeseries', '*.{}.tif'.format(product))) ) if not nr_of_ts > 1: continue outfiles = [] for i in range(1, nr_of_ts + 1): filelist = glob.glob(opj( processing_dir, '*', 'Timeseries', '{}.*{}.tif' .format(i, product))) filelist = [file for file in filelist if 'Mosaic' not in file] print(' INFO: Creating timeseries mosaic {} for {}.'.format( i, product)) # create dates for timseries naming datelist = [] for file in filelist: if '.coh.' in file: datelist.append('{}_{}'.format( os.path.basename(file).split('.')[2], os.path.basename(file).split('.')[1])) else: datelist.append(os.path.basename(file).split('.')[1]) start, end = sorted(datelist)[0], sorted(datelist)[-1] filelist = ' '.join(filelist) if start == end: outfile = opj(ts_dir, '{}.{}.{}.tif'.format(i, start, product)) else: outfile = opj(ts_dir, '{}.{}-{}.{}.tif'.format(i, start, end, product)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4]) ) outfiles.append(outfile) if os.path.isfile(check_file): print( 'INFO: Mosaic layer {} already' ' processed.'.format(outfile)) continue # the command print(' INFO: Mosaicking layer {}.'.format(os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, temp_dir, cut_to_aoi) # create vrt if exec_file: continue # create final vrt vrt_options = gdal.BuildVRTOptions(srcNodata=0, separate=True) gdal.BuildVRT(opj(ts_dir, '{}.Timeseries.vrt'.format(product)), outfiles, options=vrt_options)
def mosaic_timeseries(inventory_df, processing_dir, temp_dir, cut_to_aoi=False, exec_file=None): logger.debug(' -----------------------------------') logger.debug('INFO: Mosaicking Time-series layers') logger.debug(' -----------------------------------') # create output folder ts_dir = opj(processing_dir, 'Mosaic', 'Timeseries') os.makedirs(ts_dir, exist_ok=True) # loop through polarisations for p in ['VV', 'VH', 'HH', 'HV']: tracks = inventory_df.relativeorbit.unique() nr_of_ts = len( glob.glob( opj(processing_dir, tracks[0], 'Timeseries', '*.{}.tif'.format(p)))) if not nr_of_ts >= 1: continue outfiles = [] for i in range(1, nr_of_ts + 1): filelist = glob.glob( opj(processing_dir, '*', 'Timeseries', '{}.*.{}.tif'.format(i, p))) filelist = [file for file in filelist if 'Mosaic' not in file] # create datelist = [] for file in filelist: datelist.append(os.path.basename(file).split('.')[1]) filelist = ' '.join(filelist) start, end = sorted(datelist)[0], sorted(datelist)[-1] if start == end: outfile = opj(ts_dir, '{}.{}.BS.{}.tif'.format(i, start, p)) else: outfile = opj(ts_dir, '{}.{}-{}.BS.{}.tif'.format(i, start, end, p)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4])) outfiles.append(outfile) if os.path.isfile(check_file): logger.debug('INFO: Mosaic layer {} already' ' processed.'.format(os.path.basename(outfile))) continue logger.debug('INFO: Mosaicking layer {}.'.format( os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, cut_to_aoi) if exec_file: logger.debug(' gdalbuildvrt ....command, outfiles') continue # create vrt vrt_options = gdal.BuildVRTOptions(srcNodata=0, separate=True) gdal.BuildVRT(opj(ts_dir, 'Timeseries.{}.vrt'.format(p)), outfiles, options=vrt_options)
def mosaic_timescan(burst_inventory, processing_dir, temp_dir, proc_file, cut_to_aoi=False, exec_file=None, ncores=os.cpu_count()): # load ard parameters with open(proc_file, 'r') as ard_file: ard_params = json.load(ard_file)['processing parameters'] metrics = ard_params['time-scan ARD']['metrics'] if 'harmonics' in metrics: metrics.remove('harmonics') metrics.extend(['amplitude', 'phase', 'residuals']) if 'percentiles' in metrics: metrics.remove('percentiles') metrics.extend(['p95', 'p5']) # a products list product_list = ['bs.HH', 'bs.VV', 'bs.HV', 'bs.VH', 'coh.VV', 'coh.VH', 'coh.HH', 'coh.HV', 'pol.Entropy', 'pol.Anisotropy', 'pol.Alpha'] tscan_dir = opj(processing_dir, 'Mosaic', 'Timescan') os.makedirs(tscan_dir, exist_ok=True) outfiles = [] for product, metric in itertools.product(product_list, metrics): # **** filelist = glob.glob( opj(processing_dir, '*', 'Timescan', '*{}.{}.tif'.format(product, metric)) ) if not len(filelist) >= 1: continue filelist = ' '.join(filelist) outfile = opj(tscan_dir, '{}.{}.tif'.format(product, metric)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4]) ) if os.path.isfile(check_file): print(' INFO: Mosaic layer {} already ' ' processed.'.format(os.path.basename(outfile))) continue if exec_file: filelist = filelist.split(" ") if cut_to_aoi==False: cut_to_aoi = 'False' parallel_temp_dir = temp_dir + '/temp_' + product + '_mosaic_tscan' os.makedirs(parallel_temp_dir, exist_ok=True) args = ('{};{};{};{};{}').format( filelist, outfile, parallel_temp_dir, cut_to_aoi, ncores) # get path to graph # rootpath = imp.find_module('ost')[1] # python_exe = opj(rootpath, 'mosaic', 'mosaic.py') exec_mosaic_timescan = exec_file + '_mosaic_tscan.txt' with open(exec_mosaic_timescan, 'a') as exe: exe.write('{}\n'.format(args)) else: print(' INFO: Mosaicking layer {}.'.format(os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, temp_dir, cut_to_aoi) outfiles.append(outfile) if not exec_file: # create vrt ras.create_tscan_vrt(tscan_dir, proc_file) else: #create vrt exec file exec_mosaic_tscan_vrt = exec_file + '_mosaic_tscan_vrt.txt' with open(exec_mosaic_tscan_vrt, 'a') as exe: exe.write('{};{}\n'.format(tscan_dir, proc_file))
def mosaic_timeseries(burst_inventory, processing_dir, temp_dir, cut_to_aoi=False, exec_file=None, ncores=os.cpu_count()): print(' ------------------------------------') print(' INFO: Mosaicking Time-series layers.') print(' ------------------------------------') # create output folder ts_dir = opj(processing_dir, 'Mosaic', 'Timeseries') os.makedirs(ts_dir, exist_ok=True) # a products list product_list = ['bs.HH', 'bs.VV', 'bs.HV', 'bs.VH', 'coh.VV', 'coh.VH', 'coh.HH', 'coh.HV', 'pol.Entropy', 'pol.Anisotropy', 'pol.Alpha'] # now we loop through each timestep and product for product in product_list: # **** bursts = burst_inventory.bid.unique() nr_of_ts = len(glob.glob(opj( processing_dir, bursts[0], 'Timeseries', '*.{}.tif'.format(product))) ) if not nr_of_ts > 1: continue outfiles = [] for i in range(1, nr_of_ts + 1): filelist = glob.glob(opj( processing_dir, '*', 'Timeseries', '{:02d}.*{}.tif' .format(i, product))) filelist = [file for file in filelist if 'Mosaic' not in file] print(' INFO: Creating timeseries mosaic {:02d} for {}.'.format( i, product)) # create dates for timseries naming datelist = [] for file in filelist: if '.coh.' in file: datelist.append('{}_{}'.format( os.path.basename(file).split('.')[2], os.path.basename(file).split('.')[1])) else: datelist.append(os.path.basename(file).split('.')[1]) start, end = sorted(datelist)[0], sorted(datelist)[-1] filelist = ' '.join(filelist) if start == end: outfile = opj(ts_dir, '{:02d}.{}.{}.tif'.format(i, start, product)) else: outfile = opj(ts_dir, '{:02d}.{}-{}.{}.tif'.format(i, start, end, product)) check_file = opj( os.path.dirname(outfile), '.{}.processed'.format(os.path.basename(outfile)[:-4]) ) outfiles.append(outfile) if os.path.isfile(check_file): print( 'INFO: Mosaic layer {} already' ' processed.'.format(outfile)) continue if exec_file: filelist=filelist.split(" ") if cut_to_aoi == False: cut_to_aoi = 'False' parallel_temp_dir = temp_dir + '/temp_' + product + '_' + str(i) + '_mosaic_timeseries' os.makedirs(parallel_temp_dir, exist_ok=True) args = ('{};{};{};{};{}').format( filelist, outfile, parallel_temp_dir, cut_to_aoi, ncores) # get path to graph # rootpath = imp.find_module('ost')[1] # python_exe = opj(rootpath, 'mosaic', 'mosaic.py') exec_mosaic_timeseries = exec_file + '_mosaic_timeseries.txt' with open(exec_mosaic_timeseries, 'a') as exe: exe.write('{}\n'.format(args)) else: # the command print(' INFO: Mosaicking layer {}.'.format(os.path.basename(outfile))) mosaic.mosaic(filelist, outfile, temp_dir, cut_to_aoi) # create vrt if not exec_file: # create final vrt vrt_options = gdal.BuildVRTOptions(srcNodata=0, separate=True) gdal.BuildVRT(opj(ts_dir, '{}.Timeseries.vrt'.format(product)), outfiles, options=vrt_options) else: # create vrt exec file exec_mosaic_ts_vrt = exec_file + '_mosaic_ts_vrt.txt' with open(exec_mosaic_ts_vrt, 'a') as exe: exe.write('{};{};{}\n'.format(ts_dir, product, outfiles))