Commit b2c048f0 authored by Adan Salazar Garibay's avatar Adan Salazar Garibay

adding function selec_products and cleaning code

parent b3180834
...@@ -28,7 +28,8 @@ Functions: ...@@ -28,7 +28,8 @@ Functions:
* "find_files" - Discover Sentinel files in directory * "find_files" - Discover Sentinel files in directory
* "download_sentinel_mages" - Calibrate chessboard images discovered in a folder * "download_sentinel_mages" - Calibrate chessboard images discovered in a folder
* "check_existing_directory" - * "check_existing_directory" - Check out if the folder exist. Create folder if it does not exist
* "select_products" - # Select products that their intersection area is less than a certain percentage threshold
""" """
...@@ -99,6 +100,33 @@ def check_existing_directory(folder) : ...@@ -99,6 +100,33 @@ def check_existing_directory(folder) :
else: else:
print folder + " exists " print folder + " exists "
def select_products( products_list , products_df, user_footprint, threshold ) :
products_down = OrderedDict()
products_down = products_list.copy()
polyfootprint = ogr.CreateGeometryFromWkt(user_footprint)
areafootprint = polyfootprint.GetArea()
for i in range(len(products_df)):
inputpoly = ogr.CreateGeometryFromWkt(products_df.footprint[i])
intersectionpoly = polyfootprint.Intersection(inputpoly)
intersectionpoly_area = intersectionpoly.GetArea()
por_intersection = (intersectionpoly_area*100)/areafootprint
if(por_intersection <= threshold):
# Deleting element
del products_down[products_df.uuid[i]]
return products_down
def download_sentinel_mages(args): def download_sentinel_mages(args):
...@@ -116,7 +144,7 @@ def download_sentinel_mages(args): ...@@ -116,7 +144,7 @@ def download_sentinel_mages(args):
products.product_type = args.product_type products.product_type = args.product_type
products.platform_name = args.platform products.platform_name = args.plattform
products.intersection_th = args.overlap products.intersection_th = args.overlap
...@@ -126,42 +154,13 @@ def download_sentinel_mages(args): ...@@ -126,42 +154,13 @@ def download_sentinel_mages(args):
producttype = products.product_type, producttype = products.product_type,
platformname = products.platform_name) platformname = products.platform_name)
polyfootprint = ogr.CreateGeometryFromWkt(products.interest_footprint)
areafootprint = polyfootprint.GetArea()
# filtering products that their intersection is less than --intersection_th
products_down = OrderedDict()
products_down = products_list.copy()
# convert to pandas
products_df = api.to_dataframe(products_list) products_df = api.to_dataframe(products_list)
counter = 0
for i in range(len(products_list)):
inputpoly = ogr.CreateGeometryFromWkt(products_df.footprint[i])
intersectionpoly = polyfootprint.Intersection(inputpoly) products_to_downloading = select_products(products_list, products_df, products.interest_footprint, products.intersection_th )
intersectionpoly_area = intersectionpoly.GetArea()
por_intersection = (intersectionpoly_area*100)/areafootprint
print "area from elemet % :" , intersectionpoly_area
print "Intersection zone % :" , por_intersection
if(por_intersection <= products.intersection_th):
# Deleting element
del products_down[products_df.uuid[i]]
counter = counter + 1
#print ("%d found elements that are not going to be downloaded" % counter)
#print ("Downloading %d elements ..." % len(products_down) )
os.chdir(args.output_folder) os.chdir(args.output_folder)
api.download_all(products_down) api.download_all(products_to_downloading)
......
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