Commit de258520 authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

mario image merge

parent 6d996f1f
...@@ -94,6 +94,7 @@ class APISentinel(object): ...@@ -94,6 +94,7 @@ class APISentinel(object):
os.chdir(dir) os.chdir(dir)
# self.api.download_all(products) # self.api.download_all(products)
for p in products: for p in products:
print(products[p]['filename'])
self.api.download(p) self.api.download(p)
def filterProducts(self, productList): def filterProducts(self, productList):
......
...@@ -59,10 +59,9 @@ def main(argv): ...@@ -59,10 +59,9 @@ def main(argv):
while text != "yes" and text != "no": while text != "yes" and text != "no":
text = raw_input("Do you want to download this products to "+rawDir+ " ? (yes, no)") text = raw_input("Do you want to download this products to "+rawDir+ " ? (yes, no)")
if text=="yes": if text=="yes":
sentinel.downloadProducts(productList,rawDir) # sentinel.downloadProducts(productList,rawDir)
print("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1") print("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
os.system("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1") # os.system("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
text ="" text =""
while text != "yes" and text != "no": while text != "yes" and text != "no":
text = raw_input("Do you want to link this products to "+outdir+ " ? (yes, no)") text = raw_input("Do you want to link this products to "+outdir+ " ? (yes, no)")
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
PRODCUTSDIR=$1 #Products Intput directory PRODCUTSDIR=$1 #Products Intput directory
JP2DIR=$2 #JP2 Output Directory JP2DIR=$2 #JP2 Output Directory
JOBS=${3:-1} JOBS=${3:-1}
BYTILE=${4:-0}
cd $PRODCUTSDIR cd $PRODCUTSDIR
ls *.zip | parallel --jobs $JOBS ExtractData.sh {} $JP2DIR 1 ls *.zip | parallel --jobs $JOBS ExtractData.sh {} $JP2DIR $BYTILE
......
...@@ -8,7 +8,7 @@ BYTILE=${2:-0} ...@@ -8,7 +8,7 @@ BYTILE=${2:-0}
# exit # exit
#fi #fi
echo "Iniciando proceso..." echo "Starting Process..."
echo $USERDIR"findProducts.json" echo $USERDIR"findProducts.json"
wkt=$(getJSONparameter.py $USERDIR"findProducts.json" wkt) wkt=$(getJSONparameter.py $USERDIR"findProducts.json" wkt)
RED='\033[0;31m' RED='\033[0;31m'
...@@ -19,6 +19,12 @@ echo $wkt ...@@ -19,6 +19,12 @@ echo $wkt
echo $USERDIR echo $USERDIR
cd $USERDIR cd $USERDIR
#0.- Create Shape File From WKT
echo "${RED}Creating Shape file...${NC}"
rm -r myshape
wktToShape.py "$wkt" "myshape"
#1.- Link L2A products #1.- Link L2A products
echo "Linking Products..." echo "Linking Products..."
if [ ! -d "L2A" ]; then if [ ! -d "L2A" ]; then
...@@ -27,7 +33,7 @@ fi ...@@ -27,7 +33,7 @@ fi
cd L2A cd L2A
rm * rm *
cd .. cd ..
echo yes | findProducts.py $USERDIR"findProducts.json" yes yes | findProducts.py $USERDIR"findProducts.json"
#2.- Extract Images #2.- Extract Images
...@@ -35,11 +41,18 @@ echo "Extracting JP2 Images..." ...@@ -35,11 +41,18 @@ echo "Extracting JP2 Images..."
if [ ! -d "jp2" ]; then if [ ! -d "jp2" ]; then
mkdir jp2 mkdir jp2
fi fi
L2AProductListExtractData.sh $USERDIR"L2A/" $USERDIR"jp2/" 4 if [ $BYTILE -ne "0" ]; then
echo "BY TILE"
L2AProductListExtractData.sh $USERDIR"L2A/" $USERDIR"jp2/" 4 1
else
echo "BY DATE"
L2AProductListExtractData.sh $USERDIR"L2A/" $USERDIR"jp2/" 4 0
fi
#3.- Merge Images #3.- Merge Images
echo "************************************************* Merging Images..." echo "\nMerging Images..."
if [ $BYTILE -ne "0" ]; then if [ $BYTILE -ne "0" ]; then
echo "BY TILE" echo "BY TILE"
cd $USERDIR"jp2/" cd $USERDIR"jp2/"
...@@ -51,22 +64,65 @@ if [ $BYTILE -ne "0" ]; then ...@@ -51,22 +64,65 @@ if [ $BYTILE -ne "0" ]; then
if [ ! -d "../out/"$i ]; then if [ ! -d "../out/"$i ]; then
mkdir "../out/"$i mkdir "../out/"$i
fi fi
"mergeImagesByDirectory.sh" $USERDIR"jp2/"$i ../../../out/$i "$wkt" mergeImagesByDirectory.sh $USERDIR"jp2/"$i ../../../out/$i "$wkt"
done done
else else
echo "BY DATE" echo "BY DATE"
# mergeImagesByDirectory.sh $USERDIR"jp2/" "$wtk" 4 cd $USERDIR"jp2/"
if [ ! -d "../out" ]; then
mkdir "../out"
fi
mergeImagesByDirectory.sh $USERDIR"jp2/" $USERDIR/out/ "$wkt" 4
fi fi
#4.- Mask raster with shape file
echo "\nApplying Mask..."
#4.- Delete images with few data
echo "****************************************************** Deleting Images..."
if [ $BYTILE -ne "0" ]; then if [ $BYTILE -ne "0" ]; then
echo "BY TILE" echo "BY TILE"
cd $USERDIR"jp2/" cd $USERDIR"out/"
for d in $(ls -d */) ; do
cd $d
if [ ! -d "mask" ]; then
mkdir mask
fi
for i in $(ls *.tif) ; do
if [ ! -e mask/$i ]; then
gdalwarp -cutline $USERDIR"myshape/wkt.shp" -crop_to_cutline -dstalpha $i mask/$i
else
echo "Passing " $i
fi
done
cd ..
done
else
echo "BY DATE"
cd $USERDIR"out/"
if [ ! -d "mask" ]; then
mkdir mask
fi
for i in $(ls *.tif) ; do
if [ ! -e mask/$i ]; then
gdalwarp -cutline ../myshape/wkt.shp -crop_to_cutline -dstalpha $i mask/$i
else
echo "Passing " $i
fi
done
fi
#5.- Delete images with few data
echo "\nDeleting Images..."
if [ $BYTILE -ne "0" ]; then
echo "BY TILE"
cd $USERDIR"out/"
for i in $(ls -d */) ; do for i in $(ls -d */) ; do
cd ../out/$i cd $i"mask"
echo $i echo $i
if [ ! -d "SCL" ]; then if [ ! -d "SCL" ]; then
mkdir SCL mkdir SCL
...@@ -82,17 +138,12 @@ if [ $BYTILE -ne "0" ]; then ...@@ -82,17 +138,12 @@ if [ $BYTILE -ne "0" ]; then
fileprefix=$(echo $scl | (cut -d"_" -f1)) fileprefix=$(echo $scl | (cut -d"_" -f1))
cp ../$fileprefix"_TCI_60m.tif" ../TCI/$fileprefix"_TCI_60m.tif" cp ../$fileprefix"_TCI_60m.tif" ../TCI/$fileprefix"_TCI_60m.tif"
done done
cd ../TCI cd $USERDIR"out/"
mogrify -format jpg -quality 100 *.tif
mkdir thumbnails
mogrify -path ./thumbnails -resize 10% *.jpg
cd $USERDIR"jp2/"
done done
else else
echo "BY DATE" echo "BY DATE"
cd jp2/merge_out/ cd $USERDIR"out/mask/"
if [ ! -d "SCL" ]; then if [ ! -d "SCL" ]; then
mkdir SCL mkdir SCL
fi fi
...@@ -106,51 +157,145 @@ else ...@@ -106,51 +157,145 @@ else
for scl in $(ls *.tif) for scl in $(ls *.tif)
do do
fileprefix=$(echo $scl | (cut -d"_" -f1)) fileprefix=$(echo $scl | (cut -d"_" -f1))
cp ../$fileprefix"_TCI_10m.tif" ../TCI/$fileprefix"_TCI_10m.tif" cp ../$fileprefix"_TCI_60m.tif" ../TCI/$fileprefix"_TCI_60m.tif"
done
cd ../TCI cd ../TCI
echo "mogrify -format jpg -quality 100 *.tif" done
fi
#6.-Creating Thumbnails
echo "Creating Thumbnails"
if [ $BYTILE -ne "0" ]; then
echo "BY TILE"
cd $USERDIR"out/"
for i in $(ls -d */) ; do
cd $i"mask"
if [ ! -d "SCL/thumbnails" ]; then
mkdir SCL/thumbnails
fi
if [ ! -d "TCI/thumbnails" ]; then
mkdir TCI/thumbnails
fi
cd TCI
mogrify -format jpg -quality 100 *.tif mogrify -format jpg -quality 100 *.tif
mkdir thumbnails
mogrify -path ./thumbnails -resize 10% *.jpg mogrify -path ./thumbnails -resize 10% *.jpg
cd $USERDIR"out/"
done
else
echo "BY DATE"
cd $USERDIR"out/mask/"
if [ ! -d "SCL/thumbnails" ]; then
mkdir SCL/thumbnails
fi
if [ ! -d "TCI/thumbnails" ]; then
mkdir TCI/thumbnails
fi
cd TCI
mogrify -format jpg -quality 100 *.tif
mogrify -path ./thumbnails -resize 10% *.jpg
fi fi
#5.-Extract SCL information
echo "**************************************************** Extracting SCL information..." #7.-Extract SCL information
cd $USERDIR"jp2/" echo ${RED}"Extracting SCL information..."${NC}
if [ $BYTILE -ne "0" ]; then if [ $BYTILE -ne "0" ]; then
echo "BY TILE" echo "BY TILE"
cd $USERDIR"out/"
for i in $(ls -d */) ; do for i in $(ls -d */) ; do
cd ../out/$i"SCL" cd ../out/$i"mask/SCL"
if [ ! -d "json" ]; then if [ ! -d "json" ]; then
mkdir json mkdir json
fi fi
SCLimageListToJSON.sh $USERDIR"out/"$i"SCL/" $USERDIR"findProducts.json" 6 SCLimageListToJSON.sh $USERDIR"out/"$i"mask/SCL/" $USERDIR"findProducts.json" 6
mv *.json json mv *.json json
cd json cd json
tile=$(echo $i | cut -d "/" -f1) tile=$(echo $i | cut -d "/" -f1)
mergeL2ASCL_JSON.py $USERDIR"out/"$i"SCL/json/" > $USERDIR$tile"_sclData.json" mergeL2ASCL_JSON.py $USERDIR"out/"$i"mask/SCL/json/" > $USERDIR$tile"_sclData.json"
echo $tile echo $tile
echo "_sclData.json" echo "_sclData.json"
cd $USERDIR"jp2/" cd $USERDIR"out/"
done done
else else
echo "BY DATE" echo "BY DATE"
cd $USERDIR/jp2/merge_out/SCL cd $USERDIR"out/mask/SCL/"
if [ ! -d "json" ]; then if [ ! -d "json" ]; then
mkdir json mkdir json
fi fi
SCLimageListToJSON.sh $USERDIR"jp2/merge_out/SCL/" $USERDIR"findProducts.json" 6 SCLimageListToJSON.sh $USERDIR"out/mask/SCL/" $USERDIR"findProducts.json" 6
mv *.json json mv *.json json
cd json cd json
mergeL2ASCL_JSON.py $USERDIR"jp2/merge_out/SCL/json/" > $USERDIR"scl_data.json" mergeL2ASCL_JSON.py $USERDIR"out/mask/SCL/json/" > $USERDIR"scl_data.json"
fi fi
echo "Archivo"
echo $USERDIR #8.-Create Tiles
echo "Genenado zip..." echo ${RED}"Creating Tiles..."${NC}
if [ $BYTILE -ne "0" ]; then
echo "BY TILE"
cd $USERDIR"out/"
for d in $(ls -d */) ; do
cd $d"mask/TCI/"
if [ ! -d "tiles" ]; then
mkdir tiles
fi
for i in $(ls *.tif) ;
do
cd tiles
gdal2tiles.py ../$i
cd ..
done
cd $USERDIR"out/"
cd $d"mask/SCL/"
if [ ! -d "tiles" ]; then
mkdir tiles
fi
for i in $(ls *.tif) ;
do
cd tiles
gdal2tiles.py ../$i
cd ..
done
cd $USERDIR"out/"
done
else
echo "BY DATE"
cd $USERDIR"out/mask/TCI/"
if [ ! -d "tiles" ]; then
mkdir tiles
fi
for i in $(ls *.tif) ;
do
cd tiles
gdal2tiles.py ../$i
cd ..
done
cd $USERDIR"out/mask/SCL/"
if [ ! -d "tiles" ]; then
mkdir tiles
fi
for i in $(ls *.tif) ;
do
cd tiles
gdal2tiles.py ../$i
cd ..
done
fi
exit
#9.-Create ZIP file
echo "Compresing Files in " $USERDIR "..."
cd $USERDIR cd $USERDIR
zip -r myzip . --exclude *.json --exclude *.zip --exclude *thumbnails* --exclude *.tif -x ./jp2\* ./L2A\* \*\*/\*/SCL/\*^C zip -r myzip . --exclude *.json --exclude *.zip --exclude *thumbnails* --exclude *.tif -x ./jp2\* ./L2A\* \*\*/\*/SCL/\*^C
echo "FIN" echo "END"
#mv *SCL_60m.tif json #mv *SCL_60m.tif json
#cd json #cd json
#!/bin/sh #!/bin/sh
INDIR=$1 #Output filename INDIR=$1 #Directory with images to merge
OUTDIR=$2 #Output filename OUTDIR=$2 #Output directory
POLYGON=$3 #Crop Window POLYGON=$3 #Crop Window (minX, maxX, minY, maxY)
DIRNAME=$(echo $INDIR | cut -d"/" -f1) DIRNAME=$(echo $INDIR | cut -d"/" -f1)
echo "INDIR:" $INDIR echo "INDIR:" $INDIR
echo "OUTDIR:" $OUTDIR echo "OUTDIR:" $OUTDIR
......
...@@ -7,6 +7,8 @@ DIRNAME=$(echo $JP2DIR | cut -d"/" -f1) ...@@ -7,6 +7,8 @@ DIRNAME=$(echo $JP2DIR | cut -d"/" -f1)
#echo "POLYGON" #echo "POLYGON"
#echo $POLYGON #echo $POLYGON
BOX=$(polygonToBox.py "$POLYGON") BOX=$(polygonToBox.py "$POLYGON")
echo "Polygon BOX"
echo $BOX
if [ "$#" -le 1 ]; then if [ "$#" -le 1 ]; then
echo "Usage " $0 " <Parent Directory with subdirectories> <POLYGON> [jobs]" echo "Usage " $0 " <Parent Directory with subdirectories> <POLYGON> [jobs]"
exit exit
......
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