Commit 8e77c533 authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

mario image merge

parent de258520
......@@ -5,25 +5,50 @@ import osgeo.osr as osr
import numpy as np
import gdal
import sys, os
import json
########### lee archivo de configuración ################
dirname = os.path.dirname(__file__)
configfile = os.path.join(dirname, '../config/config.json')
with open(configfile, 'r') as f:
config = json.load(f)
#print(config['PATHS']['PATH_GEOSENTINEL'])
SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL']
###########################################################
sys.path.append(SENTINEL_PATH)
from geosentinel import rasterWkt
#-------------------------------------------------------------------------------
def imageMissingData(filename):
def imageMissingData(filename, wkt):
inputImage = gdal.Open(filename)
rows, cols, geotransform = inputImage.RasterYSize, inputImage.RasterXSize, inputImage.GetGeoTransform()
data = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows)
rasterwkt = rasterWkt.getPolygonArray(inputImage, wkt)
data = np.bitwise_and(data, rasterwkt)
inputImage = None
return (data>0).sum()/float((rows*cols))
return (data>0).sum()/(rasterwkt>0).sum()
#-------------------------------------------------------------------------------
def main(argv):
if len(sys.argv) != 3:
print("Usage: " + argv[0] + " <File> <%>")
if len(sys.argv) != 4:
print("Usage: " + argv[0] + " <File> <JSON> <%>")
else:
dataArea = imageMissingData(argv[1])
if dataArea<float(argv[2])/100.0 :
print ("Deleting " + argv[1] + " " + str(dataArea))
jsonFile=open(argv[2]).read()
cfg = json.loads(jsonFile)
dataArea = imageMissingData(argv[1], cfg["wkt"])
th = float(argv[3])/100.0
if dataArea<th :
print ("Deleting " + argv[1] + " " + str(dataArea)+" < " + str(th))
#os.system("rm " + argv[1])
else:
print ("Keeping " + argv[1] + " " + str(dataArea))
......
......@@ -129,7 +129,7 @@ if [ $BYTILE -ne "0" ]; then
fi
cp *SCL_60m.tif SCL
cd SCL
ls *.tif | parallel --jobs 4 imageMissingData.py {} 50
ls *.tif | parallel --jobs 4 imageMissingData.py {} $USERDIR"findproducts.json" 70
if [ ! -d "../TCI" ]; then
mkdir ../TCI
fi
......@@ -149,7 +149,7 @@ else
fi
cp *SCL_60m.tif SCL
cd SCL
ls *.tif | parallel --jobs 4 imageMissingData.py {} 50
ls *.tif | parallel --jobs 4 imageMissingData.py {} $USERDIR"findproducts.json" 70
if [ ! -d "../TCI" ]; then
mkdir ../TCI
......
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