def main(iargs=None):
    '''
    The main driver.
    '''

    inps = cmdLineParse(iargs)
    # parsing required inputs
    inputDir = os.path.abspath(inps.input)
    # parsing optional inputs
    if inps.output:
        outputDir = os.path.abspath(inps.output)               
    else:                
        outputDir = None
    rmfile = inps.rmfile
                
    # filename of the runfile
    run_unPack = 'run_unPackRSAT2'


    # loop over the different folder, RSAT2 zip/tar files and unzip them, make the names consistent
    RSAT2_extensions = (os.path.join(inputDir, 'RS2*SLC*.zip'),os.path.join(inputDir, 'RS2*SLC*.tar'),os.path.join(inputDir, 'RS2*SLC*.gz'))
    for RSAT2_extension in RSAT2_extensions:
        RSAT2_filesfolders = glob.glob(RSAT2_extension)
        for RSAT2_infilefolder in RSAT2_filesfolders:
            ## the path to the folder/zip
            workdir = os.path.dirname(RSAT2_infilefolder)
            
            ## get the output name folder without any extensions
            temp = os.path.basename(RSAT2_infilefolder)
            # trim the extensions and keep only very first part
            parts = temp.split(".")
            parts = parts[0].split('-')
            RSAT2_outfolder = parts[0]
            # add the path back in
            RSAT2_outfolder = os.path.join(workdir,RSAT2_outfolder)
            
            # loop over two cases (either file or folder): 
            ### this is a file, try to unzip/untar it
            if os.path.isfile(RSAT2_infilefolder):
                # unzip the file in the outfolder
                successflag_unzip = uncompressfile(RSAT2_infilefolder,RSAT2_outfolder)

                # put failed files in a seperate directory
                if not successflag_unzip:
                    if not os.path.isdir(os.path.join(workdir,'FAILED_FILES')):
                        os.makedirs(os.path.join(workdir,'FAILED_FILES'))
                    os.rename(RSAT2_infilefolder,os.path.join(workdir,'FAILED_FILES','.'))
                else:
                    # check if file needs to be removed or put in archive folder
                    if rmfile:                                                                                                                                   
                        os.remove(RSAT2_infilefolder)
                        print('Deleting: ' + RSAT2_infilefolder)
                    else:
                        if not os.path.isdir(os.path.join(workdir,'ARCHIVED_FILES')):
                            os.makedirs(os.path.join(workdir,'ARCHIVED_FILES'))
                        cmd  = 'mv ' + RSAT2_infilefolder + ' ' + os.path.join(workdir,'ARCHIVED_FILES','.')
                        os.system(cmd)

        # loop over the different RSAT2 folders and make sure the folder names are consistent.
        # this step is not needed unless the user has manually unzipped data before.
        RSAT2_folders = glob.glob(os.path.join(inputDir, 'RS2*SLC*'))
        for RSAT2_folder in RSAT2_folders:
            # in case the user has already unzipped some files, make sure they are unzipped similar like the uncompressfile code
            temp = os.path.basename(RSAT2_folder)
            parts = temp.split(".")
            parts = parts[0].split('-')
            RSAT2_outfolder_temp = parts[0]
            RSAT2_outfolder_temp = os.path.join(os.path.dirname(RSAT2_folder),RSAT2_outfolder_temp)
            # check if the folder (RSAT2_folder) has a different filename as generated from the uncompressFile code (RSAT2_outfolder_temp)
            if not (RSAT2_outfolder_temp == RSAT2_folder):
                # it is different, check if the RSAT2_outfolder_temp already exists, if yes, delete the current folder
                if os.path.isdir(RSAT2_outfolder_temp):
                    print('Remove ' + RSAT2_folder + ' as ' + RSAT2_outfolder_temp + ' exists...')
                    # check if this folder already exist, if so overwrite it
                    shutil.rmtree(RSAT2_folder)

    # loop over the different RSAT2 folders and organize in date folders
    RSAT2_folders = glob.glob(os.path.join(inputDir, 'RS2*SLC*'))     
    for RSAT2_folder in RSAT2_folders:
        # get the date
        successflag, imgDate = get_Date(RSAT2_folder)       
            
        workdir = os.path.dirname(RSAT2_folder)
        if successflag:
            # move the file into the date folder
            SLC_dir = os.path.join(workdir,imgDate,'')
            if os.path.isdir(SLC_dir):
                shutil.rmtree(SLC_dir)

            cmd = 'mv ' + RSAT2_folder + ' ' + SLC_dir 
            os.system(cmd)

            print ('Succes: ' + imgDate)
        else:
            print('Failed: ' + RSAT2_folder)
        

    # now generate the unpacking script for all the date dirs
    dateDirs = glob.glob(os.path.join(inputDir,'2*'))
    if outputDir is not None:
        f = open(run_unPack,'w')
        for dataDir in dateDirs:
            RSAT2Files = glob.glob(os.path.join(dataDir, 'imagery_HH.tif'))
            if len(RSAT2Files)>0:
                acquisitionDate = os.path.basename(dataDir)
                slcDir = os.path.join(outputDir, acquisitionDate)
                if not os.path.exists(slcDir):
                    os.makedirs(slcDir)     
                cmd = 'unpackFrame_RSAT2.py -i ' + os.path.abspath(dataDir) + ' -o ' + slcDir      
                print (cmd)
                f.write(inps.text_cmd + cmd+'\n')
        f.close()
Exemple #2
0
def main(iargs=None):
    '''
    The main driver.
    '''

    inps = cmdLineParse(iargs)
    # parsing required inputs
    inputDir = os.path.abspath(inps.input)
    # parsing optional inputs
    if inps.output:
        outputDir = os.path.abspath(inps.output)
    else:
        outputDir = None
    rmfile = inps.rmfile

    # filename of the runfile
    run_unPack = 'run_unPackCSK'

    # loop over the different folder, CSK zip/tar files and unzip them, make the names consistent
    CSK_extensions = (os.path.join(inputDir, 'EL*.zip'),
                      os.path.join(inputDir, 'EL*.tar'),
                      os.path.join(inputDir, 'CSKS*.gz'))
    for CSK_extension in CSK_extensions:
        CSK_filesfolders = glob.glob(CSK_extension)
        for CSK_infilefolder in CSK_filesfolders:
            ## the path to the folder/zip
            workdir = os.path.dirname(CSK_infilefolder)

            ## get the output name folder without any extensions
            temp = os.path.basename(CSK_infilefolder)
            # trim the extensions and keep only very first part
            parts = temp.split(".")
            parts = parts[0].split('-')
            CSK_outfolder = parts[0]
            # add the path back in
            CSK_outfolder = os.path.join(workdir, CSK_outfolder)

            # loop over two cases (either file or folder):
            ### this is a file, try to unzip/untar it
            if os.path.isfile(CSK_infilefolder):
                # unzip the file in the outfolder
                successflag_unzip = uncompressfile(CSK_infilefolder,
                                                   CSK_outfolder)

                # put failed files in a seperate directory
                if not successflag_unzip:
                    if not os.path.isdir(os.path.join(workdir,
                                                      'FAILED_FILES')):
                        os.makedirs(os.path.join(workdir, 'FAILED_FILES'))
                    os.rename(CSK_infilefolder,
                              os.path.join(workdir, 'FAILED_FILES', '.'))
                else:
                    # check if file needs to be removed or put in archive folder
                    if rmfile:
                        os.remove(CSK_infilefolder)
                        print('Deleting: ' + CSL_infilefolder)
                    else:
                        if not os.path.isdir(
                                os.path.join(workdir, 'ARCHIVED_FILES')):
                            os.makedirs(os.path.join(workdir,
                                                     'ARCHIVED_FILES'))
                        cmd = 'mv ' + CSK_infilefolder + ' ' + os.path.join(
                            workdir, 'ARCHIVED_FILES', '.')
                        os.system(cmd)

        # loop over the different CSK folders and make sure the folder names are consistent.
        # this step is not needed unless the user has manually unzipped data before.
        CSK_folders = glob.glob(os.path.join(inputDir, 'CSKS*'))
        for CSK_folder in CSK_folders:
            # in case the user has already unzipped some files, make sure they are unzipped similar like the uncompressfile code
            temp = os.path.basename(CSK_folder)
            parts = temp.split(".")
            parts = parts[0].split('-')
            CSK_outfolder_temp = parts[0]
            CSK_outfolder_temp = os.path.join(os.path.dirname(CSK_folder),
                                              CSK_outfolder_temp)
            # check if the folder (CSK_folder) has a different filename as generated from the uncompressFile code (CSK_outfolder_temp)
            if not (CSK_outfolder_temp == CSK_folder):
                # it is different, check if the CSK_outfolder_temp already exists, if yes, delete the current folder
                if os.path.isdir(CSK_outfolder_temp):
                    print('Remove ' + CSK_folder + ' as ' +
                          CSK_outfolder_temp + ' exists...')
                    # check if this folder already exist, if so overwrite it
                    shutil.rmtree(CSK_folder)

    # loop over the different CSK folders and organize in date folders
    CSK_folders = glob.glob(os.path.join(inputDir, 'CSKS*'))
    for CSK_folder in CSK_folders:
        # get the date
        successflag, imgDate = get_Date(CSK_folder)

        workdir = os.path.dirname(CSK_folder)
        if successflag:
            # move the file into the date folder
            SLC_dir = os.path.join(workdir, imgDate, '')
            if not os.path.isdir(SLC_dir):
                os.makedirs(SLC_dir)

            # check if the folder already exist in that case overwrite it
            CSK_folder_out = os.path.join(SLC_dir,
                                          os.path.basename(CSK_folder))
            if os.path.isdir(CSK_folder_out):
                shutil.rmtree(CSK_folder_out)

            ### FOR NOW TO MAKE MERGING WORK OF MULTIPLE SCENES
            ### In future would be better to have a -m option for CSK unpack like ALOS unpack?
            cmd = 'mv ' + CSK_folder + '/* ' + SLC_dir + '.'
            os.system(cmd)
            cmd = 'rmdir ' + CSK_folder
            os.system(cmd)
            ###
            ###

            # # move the CSK acqusition folder in the date folder
            # cmd  = 'mv ' + CSK_folder + ' ' + SLC_dir + '.'
            # os.system(cmd)

            print('Succes: ' + imgDate)
        else:
            print('Failed: ' + CSK_folder)

    # now generate the unpacking script for all the date dirs
    dateDirs = glob.glob(os.path.join(inputDir, '2*'))
    if outputDir is not None:
        f = open(run_unPack, 'w')
        for dataDir in dateDirs:
            CSKFiles = glob.glob(os.path.join(dataDir, 'CSK*.h5'))
            if len(CSKFiles) > 0:
                acquisitionDate = os.path.basename(dataDir)
                slcDir = os.path.join(outputDir, acquisitionDate)
                if not os.path.exists(slcDir):
                    os.makedirs(slcDir)
                cmd = 'unpackFrame_CSK_raw.py -i ' + os.path.abspath(
                    dataDir) + ' -o ' + slcDir
                print(cmd)
                f.write(inps.text_cmd + cmd + '\n')
            """ 
            ##### FOR now lets ptu all scences in single folder
            CSKFiles = glob.glob(os.path.join(dataDir, 'EL*'))
            if len(CSKFiles)>0:
               acquisitionDate = os.path.basename(dataDir)
               slcDir = os.path.join(outputDir, acquisitionDate)
               if not os.path.exists(slcDir):
                  os.makedirs(slcDir)     
               cmd = 'unpackFrame_CSK_raw.py -i ' + os.path.abspath(dataDir) + ' -o ' + slcDir      

               if len(CSKFiles) > 1:
                  cmd = cmd + ' -m' 
               print (cmd)
               f.write(inps.text_cmd + cmd+'\n')
            """
        f.close()
Exemple #3
0
def main(iargs=None):
    '''
    The main driver.
    '''

    inps = cmdLineParse(iargs)

    # filename of the runfile
    run_unPack = 'run_unPackALOS'   

    # loop over the different folder, ALOS zip/tar files and unzip them, make the names consistent
    ALOS_extensions = (os.path.join(inps.inputDir, '*.zip'),
                       os.path.join(inps.inputDir, '*.tar'),
                       os.path.join(inps.inputDir, '*.gz'))
    for ALOS_extension in ALOS_extensions:
        # loop over zip/tar files
        ALOS_filesfolders = sorted(glob.glob(ALOS_extension))
        for ALOS_infilefolder in ALOS_filesfolders:
            ## the path to the folder/zip
            workdir = os.path.dirname(ALOS_infilefolder)

            ## get the output name folder without any extensions
            ALOS_outfolder = get_ALOS_ALP_name(ALOS_infilefolder)
            # add the path back in
            ALOS_outfolder = os.path.join(workdir, ALOS_outfolder)

            # loop over two cases (either file or folder): 
            ### this is a file, try to unzip/untar it
            if os.path.isfile(ALOS_infilefolder):
                # unzip the file in the outfolder
                successflag_unzip = uncompressfile(ALOS_infilefolder, ALOS_outfolder)

                # put failed files in a seperate directory
                if not successflag_unzip:
                    os.makedirs(os.path.join(workdir,'FAILED_FILES'), exist_ok=True)
                    os.rename(ALOS_infilefolder,os.path.join(workdir,'FAILED_FILES','.'))
                else:
                    # check if file needs to be removed or put in archive folder
                    if inps.rmfile:
                        os.remove(ALOS_infilefolder)
                        print('Deleting: ' + ALOS_infilefolder)
                    else:
                        os.makedirs(os.path.join(workdir,'ARCHIVED_FILES'), exist_ok=True)
                        cmd  = 'mv ' + ALOS_infilefolder + ' ' + os.path.join(workdir,'ARCHIVED_FILES','.')
                        os.system(cmd)


        # loop over the different ALOS folders and make sure the folder names are consistent.
        # this step is not needed unless the user has manually unzipped data before.
        ALOS_folders = glob.glob(os.path.join(inps.inputDir, 'ALP*'))
        for ALOS_folder in ALOS_folders:
            # in case the user has already unzipped some files
            # make sure they are unzipped similar like the uncompressfile code
            temp = os.path.basename(ALOS_folder)
            parts = temp.split(".")
            parts = parts[0].split('-')
            ALOS_outfolder_temp = parts[0]
            ALOS_outfolder_temp = os.path.join(os.path.dirname(ALOS_folder),ALOS_outfolder_temp)
            # check if the folder (ALOS_folder) has a different filename as generated from uncompressFile (ALOS_outfolder_temp)
            if not (ALOS_outfolder_temp == ALOS_folder):
                # it is different, check if the ALOS_outfolder_temp already exists, if yes, delete the current folder
                if os.path.isdir(ALOS_outfolder_temp):
                    print('Remove ' + ALOS_folder + ' as ' + ALOS_outfolder_temp + ' exists...')
                    # check if this folder already exist, if so overwrite it
                    shutil.rmtree(ALOS_folder)


    # loop over the different ALOS folders and organize in date folders
    ALOS_folders = glob.glob(os.path.join(inps.inputDir, 'ALP*'))                        
    for ALOS_folder in ALOS_folders:
        # get the date
        successflag, imgDate = get_Date(ALOS_folder)       
        
        workdir = os.path.dirname(ALOS_folder)
        if successflag:
            # move the file into the date folder
            SLC_dir = os.path.join(workdir,imgDate,'')
            os.makedirs(SLC_dir, exist_ok=True)

            # check if the folder already exist in that case overwrite it
            ALOS_folder_out = os.path.join(SLC_dir,os.path.basename(ALOS_folder))
            if os.path.isdir(ALOS_folder_out):
                shutil.rmtree(ALOS_folder_out)
            # move the ALOS acqusition folder in the date folder
            cmd  = 'mv ' + ALOS_folder + ' ' + SLC_dir + '.' 
            os.system(cmd)

            print ('Succes: ' + imgDate)
        else:
            print('Failed: ' + ALOS_folder)
        

    # now generate the unpacking script for all the date dirs
    dateDirs = sorted(glob.glob(os.path.join(inps.inputDir,'2*')))
    if inps.outputDir is not None:
        f = open(run_unPack,'w')
        for dateDir in dateDirs:
            AlosFiles = glob.glob(os.path.join(dateDir, 'ALP*'))
            if len(AlosFiles)>0:
                acquisitionDate = os.path.basename(dateDir)
                slcDir = os.path.join(inps.outputDir, acquisitionDate)
                os.makedirs(slcDir, exist_ok=True)
                cmd = 'unpackFrame_ALOS_raw.py -i ' + os.path.abspath(dateDir) + ' -o ' + slcDir      
                IMG_files = glob.glob(os.path.join(AlosFiles[0],'IMG*'))
                if inps.fbd2fbs:
                    #recommended for regular interferometry to use all FBS bandwidth
                    if len(IMG_files) == 2:
                        cmd += ' -f fbd2fbs '
                else:
                    #used for ionosphere workflow for simplicity
                    if len(IMG_files) == 1:
                        cmd = cmd + ' -f  fbs2fbd ' 
                if len(AlosFiles) > 1:
                    cmd = cmd + ' -m' 
                print (cmd)
                f.write(inps.text_cmd + cmd+'\n')
        f.close()
    return
Exemple #4
0
def main(iargs=None):
    '''
    The main driver.
    '''

    inps = cmdLineParse(iargs)

    # filename of the runfile
    run_unPack = 'run_unPackALOS2'

    # loop over the different folder of ALOS2 zip/tar files and unzip them, make the names consistent
    file_exts = (os.path.join(inps.inputDir,
                              '*.zip'), os.path.join(inps.inputDir, '*.tar'),
                 os.path.join(inps.inputDir, '*.gz'))
    for file_ext in file_exts:
        # loop over zip/tar files
        for fname in sorted(glob.glob(file_ext)):
            ## the path to the folder/zip
            workdir = os.path.dirname(fname)

            ## get the output name folder without any extensions
            dir_unzip = get_ALOS2_name(fname)
            dir_unzip = os.path.join(workdir, dir_unzip)

            # loop over two cases (either file or folder):
            # if this is a file, try to unzip/untar it
            if os.path.isfile(fname):
                # unzip the file in the outfolder
                successflag_unzip = uncompressfile(fname, dir_unzip)

                # put failed files in a seperate directory
                if not successflag_unzip:
                    dir_failed = os.path.join(workdir, 'FAILED_FILES')
                    if not os.path.isdir(dir_failed):
                        os.makedirs(dir_failed)
                    cmd = 'mv {} {}'.format(fname, dir_failed)
                    os.system(cmd)
                else:
                    # check if file needs to be removed or put in archive folder
                    if inps.rmfile:
                        os.remove(fname)
                        print('Deleting: ' + fname)
                    else:
                        dir_archive = os.path.join(workdir, 'ARCHIVED_FILES')
                        if not os.path.isdir(dir_archive):
                            os.makedirs(dir_archive)
                        cmd = 'mv {} {}'.format(fname, dir_archive)
                        os.system(cmd)

        # loop over the different ALOS folders and make sure the folder names are consistent.
        # this step is not needed unless the user has manually unzipped data before.
        ALOS_folders = glob.glob(os.path.join(inps.inputDir, 'ALOS2*'))
        for ALOS_folder in ALOS_folders:
            # in case the user has already unzipped some files
            # make sure they are unzipped similar like the uncompressfile code
            temp = os.path.basename(ALOS_folder)
            parts = temp.split(".")
            parts = parts[0].split('-')
            ALOS_outfolder_temp = parts[0]
            ALOS_outfolder_temp = os.path.join(os.path.dirname(ALOS_folder),
                                               ALOS_outfolder_temp)
            # check if the folder (ALOS_folder) has a different filename as generated from uncompressFile (ALOS_outfolder_temp)
            if not (ALOS_outfolder_temp == ALOS_folder):
                # it is different, check if the ALOS_outfolder_temp already exists, if yes, delete the current folder
                if os.path.isdir(ALOS_outfolder_temp):
                    print('Remove ' + ALOS_folder + ' as ' +
                          ALOS_outfolder_temp + ' exists...')
                    # check if this folder already exist, if so overwrite it
                    shutil.rmtree(ALOS_folder)

    # loop over the different ALOS folders and organize in date folders
    ALOS_folders = glob.glob(os.path.join(inps.inputDir, 'ALOS2*'))
    for ALOS_folder in ALOS_folders:
        # get the date
        successflag, imgDate = get_Date(ALOS_folder)

        workdir = os.path.dirname(ALOS_folder)
        if successflag:
            # move the file into the date folder
            SLC_dir = os.path.join(workdir, imgDate, '')
            if not os.path.isdir(SLC_dir):
                os.makedirs(SLC_dir)

            # check if the folder already exist in that case overwrite it
            ALOS_folder_out = os.path.join(SLC_dir,
                                           os.path.basename(ALOS_folder))
            if os.path.isdir(ALOS_folder_out):
                shutil.rmtree(ALOS_folder_out)
            # move the ALOS acqusition folder in the date folder
            cmd = 'mv ' + ALOS_folder + ' ' + SLC_dir + '.'
            os.system(cmd)

            print('Succes: ' + imgDate)
        else:
            print('Failed: ' + ALOS_folder)

    # now generate the unpacking script for all the date dirs
    dateDirs = sorted(glob.glob(os.path.join(inps.inputDir, '2*')))
    if inps.outputDir is not None:
        f = open(run_unPack, 'w')
        for dateDir in dateDirs:
            AlosFiles = glob.glob(os.path.join(dateDir, 'ALOS2*'))
            # if there is at least one frame
            if len(AlosFiles) > 0:
                acquisitionDate = os.path.basename(dateDir)
                slcDir = os.path.join(inps.outputDir, acquisitionDate)
                if not os.path.exists(slcDir):
                    os.makedirs(slcDir)
                cmd = 'unpackFrame_ALOS2.py -i ' + os.path.abspath(
                    dateDir) + ' -o ' + slcDir
                print(cmd)
                f.write(inps.text_cmd + cmd + '\n')
        f.close()
    return