#! /usr/bin/env python ################################################################# ### This program is part of PyINT v2.1 ### ### Copy Right (c): 2017-2019, Yunmeng Cao ### ### Author: Yunmeng Cao ### ### Contact : ymcmrs@gmail.com ### ################################################################# import numpy as np import os import sys import getopt import time import glob import argparse import subprocess from pyint import _utils as ut def get_s1_date(raw_file): file0 = os.path.basename(raw_file) date = file0[17:25] return date def work(data0): cmd = data0[0] err_txt = data0[1] p = subprocess.run(cmd, shell=False,stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout = p.stdout stderr = p.stderr if type(stderr) == bytes: aa=stderr.decode("utf-8") else: aa = stderr if aa: str0 = cmd[0] + ' ' + cmd[1] + ' ' + cmd[2] + '\n' #print(aa) with open(err_txt, 'a') as f: f.write(str0) f.write(aa) f.write('\n') return ######################################################################### INTRODUCTION = ''' ------------------------------------------------------------------- Generate SLCs from Sentinel-1 raw dataset with orbit correction using GAMMA. ''' EXAMPLE = ''' Usage: down2slc_sen_all.py projectName down2slc_sen_all.py projectName --parallel 4 ------------------------------------------------------------------- ''' def cmdLineParse(): parser = argparse.ArgumentParser(description='Generate SLCs from Sentinel-1 raw dataset with orbit correction using GAMMA.',\ formatter_class=argparse.RawTextHelpFormatter,\ epilog=INTRODUCTION+'\n'+EXAMPLE) parser.add_argument('projectName',help='projectName for processing.') parser.add_argument('--parallel', dest='parallelNumb', type=int, default=1, help='Enable parallel processing and Specify the number of processors.') inps = parser.parse_args() return inps def main(argv): start_time = time.time() inps = cmdLineParse() projectName = inps.projectName scratchDir = os.getenv('SCRATCHDIR') projectDir = scratchDir + '/' + projectName downDir = scratchDir + '/' + projectName + "/DOWNLOAD" raw_file_list = glob.glob(downDir + '/ALPSRP*.zip') slc_dir = scratchDir + '/' + projectName + '/SLC' if not os.path.isdir(slc_dir): os.mkdir(slc_dir) err_txt = scratchDir + '/' + projectName + '/unzip_alos_all.err' if os.path.isfile(err_txt): os.remove(err_txt) ########get the ALOS date name ############### data_para = [] date_list = [] for i in range(len(raw_file_list)): cmd0 = ['unzip',raw_file_list[i],'-d',downDir] call_str='unzip ' + raw_file_list[i] + ' -d ' + downDir os.system(call_str) workflow_file=raw_file_list[i].split(".")[0] + '.' +raw_file_list[i].split(".")[1] os.chdir(workflow_file) tempfile=workflow_file + '/' + 'workreport' tempDict=ut.update_template(tempfile) SeneceData = tempDict['Img_SceneCenterDateTime'].split('"')[1].split(' ')[0] SceneID = tempDict['Scs_SceneID'] os.chdir(downDir) call_str= 'mv ' + workflow_file + ' ' + SeneceData os.system(call_str) data0=[SeneceData, err_txt] data_para.append(data0) date0=SeneceData date_list.append(date0) date_list = set(date_list) date_list = sorted(date_list) print('Date to be processed:') for k0 in date_list: print(k0) err_txt = scratchDir + '/' + projectName + '/down2slc_alos_all.err' if os.path.isfile(err_txt): os.remove(err_txt) data_para = [] for i in range(len(date_list)): cmd0 = ['Down2SLC_ALOS.py',projectName,date_list[i]] data0 = [cmd0,err_txt] data_para.append(data0) ut.parallel_process(data_para, work, n_jobs=inps.parallelNumb, use_kwargs=False) os.chdir(downDir) print("Down to SLC for project %s is done! " % projectName) ut.print_process_time(start_time, time.time()) sys.exit(1) if __name__ == '__main__': main(sys.argv[:])