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 ...@@ -5,25 +5,50 @@ import osgeo.osr as osr
import numpy as np import numpy as np
import gdal import gdal
import sys, os 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) inputImage = gdal.Open(filename)
rows, cols, geotransform = inputImage.RasterYSize, inputImage.RasterXSize, inputImage.GetGeoTransform() rows, cols, geotransform = inputImage.RasterYSize, inputImage.RasterXSize, inputImage.GetGeoTransform()
data = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows) data = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows)
rasterwkt = rasterWkt.getPolygonArray(inputImage, wkt)
data = np.bitwise_and(data, rasterwkt)
inputImage = None inputImage = None
return (data>0).sum()/float((rows*cols)) return (data>0).sum()/(rasterwkt>0).sum()
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def main(argv): def main(argv):
if len(sys.argv) != 3: if len(sys.argv) != 4:
print("Usage: " + argv[0] + " <File> <%>") print("Usage: " + argv[0] + " <File> <JSON> <%>")
else: else:
dataArea = imageMissingData(argv[1]) jsonFile=open(argv[2]).read()
if dataArea<float(argv[2])/100.0 : cfg = json.loads(jsonFile)
print ("Deleting " + argv[1] + " " + str(dataArea))
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]) #os.system("rm " + argv[1])
else: else:
print ("Keeping " + argv[1] + " " + str(dataArea)) print ("Keeping " + argv[1] + " " + str(dataArea))
......
...@@ -129,7 +129,7 @@ if [ $BYTILE -ne "0" ]; then ...@@ -129,7 +129,7 @@ if [ $BYTILE -ne "0" ]; then
fi fi
cp *SCL_60m.tif SCL cp *SCL_60m.tif SCL
cd 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 if [ ! -d "../TCI" ]; then
mkdir ../TCI mkdir ../TCI
fi fi
...@@ -149,7 +149,7 @@ else ...@@ -149,7 +149,7 @@ else
fi fi
cp *SCL_60m.tif SCL cp *SCL_60m.tif SCL
cd 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 if [ ! -d "../TCI" ]; then
mkdir ../TCI 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