Commit 2cefd271 authored by Pedro Alfonso Ramirez's avatar Pedro Alfonso Ramirez

Add unzip

parent 9f209e69
...@@ -35,7 +35,7 @@ Functions: ...@@ -35,7 +35,7 @@ Functions:
from argparse import ArgumentParser from argparse import ArgumentParser
import os import os,sys
import zipfile import zipfile
from collections import OrderedDict from collections import OrderedDict
...@@ -84,16 +84,21 @@ SENTINEL_UNZIP_ARGUMENTS.add_argument("product_type", help="sentinel product typ ...@@ -84,16 +84,21 @@ SENTINEL_UNZIP_ARGUMENTS.add_argument("product_type", help="sentinel product typ
def find_files(args): def find_files(args):
check_existing_directory(args.folder, 2)
folder = args.folder folder = args.folder
satelite = args.plattform satelite = args.plattform
files = os.listdir(folder) files = os.listdir(folder)
if(satelite=="Sentinel-1"): if(satelite!="Sentinel-1")or(satelite!="sentinel-1")or(satelite=="Sentinel-2")or(satelite=="sentinel-2"):
namfil1 = 'S1A_'+ args.product_type print satelite + " not exist"
namfil2 = 'S1B_'+ args.product_type sys.exit()
if(satelite=="Sentinel-2"): else:
namfil1 = 'S2A_'+ args.product_type if(satelite=="Sentinel-1")or(satelite=="sentinel-1"):
namfil2 = 'S2B_'+ args.product_type namfil1 = 'S1A_'+ args.product_type
files = [f for f in files if f.startswith(namfil1) or f.startswith(namfil2)] namfil2 = 'S1B_'+ args.product_type
if(satelite=="Sentinel-2")or(satelite=="sentinel-2"):
namfil1 = 'S2A_'+ args.product_type
namfil2 = 'S2B_'+ args.product_type
files = [f for f in files if f.startswith(namfil1) or f.startswith(namfil2)]
if(len(files)==0): if(len(files)==0):
print"Files not found..." print"Files not found..."
return files return files
...@@ -106,13 +111,19 @@ def unzip(list_files,args): ...@@ -106,13 +111,19 @@ def unzip(list_files,args):
zip_ref.extractall(args.folder) # extract file to dir zip_ref.extractall(args.folder) # extract file to dir
zip_ref.close() # close file zip_ref.close() # close file
def check_existing_directory(folder) : def check_existing_directory(folder,flag):
if not os.path.exists(folder): if(flag==1):
os.makedirs(folder) if not os.path.exists(folder):
print folder + " was created" os.makedirs(folder)
else: print folder + " was created"
print folder + " exists " else:
print folder + " exists "
if(flag == 2):
if not os.path.exists(folder):
print folder + " not exist"
sys.exit()
def select_products( products_list , products_df, user_footprint, threshold ) : def select_products( products_list , products_df, user_footprint, threshold ) :
...@@ -144,7 +155,7 @@ def select_products( products_list , products_df, user_footprint, threshold ) : ...@@ -144,7 +155,7 @@ def select_products( products_list , products_df, user_footprint, threshold ) :
def download_sentinel_mages(args): def download_sentinel_mages(args):
check_existing_directory(args.output_folder) check_existing_directory(args.output_folder,1)
products = SentinelData() products = SentinelData()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment