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

mario image merge

parent 6d996f1f
......@@ -94,6 +94,7 @@ class APISentinel(object):
os.chdir(dir)
# self.api.download_all(products)
for p in products:
print(products[p]['filename'])
self.api.download(p)
def filterProducts(self, productList):
......
......@@ -54,15 +54,14 @@ def main(argv):
print ( str(len(matchingProducts))+" of " + str(len(fileNames)) +" products found.")
rawDir = inDir.replace(cfg['productLevel'],productsCodes[cfg['productLevel']])
print(rawDir)
text =""
while text != "yes" and text != "no":
text = raw_input("Do you want to download this products to "+rawDir+ " ? (yes, no)")
if text=="yes":
sentinel.downloadProducts(productList,rawDir)
print("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
os.system("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
if text=="yes":
# sentinel.downloadProducts(productList,rawDir)
print("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
# os.system("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
text =""
while text != "yes" and text != "no":
text = raw_input("Do you want to link this products to "+outdir+ " ? (yes, no)")
......
......@@ -2,10 +2,10 @@
PRODCUTSDIR=$1 #Products Intput directory
JP2DIR=$2 #JP2 Output Directory
JOBS=${3:-1}
BYTILE=${4:-0}
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}
# exit
#fi
echo "Iniciando proceso..."
echo "Starting Process..."
echo $USERDIR"findProducts.json"
wkt=$(getJSONparameter.py $USERDIR"findProducts.json" wkt)
RED='\033[0;31m'
......@@ -19,6 +19,12 @@ echo $wkt
echo $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
echo "Linking Products..."
if [ ! -d "L2A" ]; then
......@@ -27,7 +33,7 @@ fi
cd L2A
rm *
cd ..
echo yes | findProducts.py $USERDIR"findProducts.json"
yes yes | findProducts.py $USERDIR"findProducts.json"
#2.- Extract Images
......@@ -35,11 +41,18 @@ echo "Extracting JP2 Images..."
if [ ! -d "jp2" ]; then
mkdir jp2
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
echo "************************************************* Merging Images..."
echo "\nMerging Images..."
if [ $BYTILE -ne "0" ]; then
echo "BY TILE"
cd $USERDIR"jp2/"
......@@ -51,22 +64,65 @@ if [ $BYTILE -ne "0" ]; then
if [ ! -d "../out/"$i ]; then
mkdir "../out/"$i
fi
"mergeImagesByDirectory.sh" $USERDIR"jp2/"$i ../../../out/$i "$wkt"
mergeImagesByDirectory.sh $USERDIR"jp2/"$i ../../../out/$i "$wkt"
done
else
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
#4.- Mask raster with shape file
echo "\nApplying Mask..."
#4.- Delete images with few data
echo "****************************************************** Deleting Images..."
if [ $BYTILE -ne "0" ]; then
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
cd ../out/$i
cd $i"mask"
echo $i
if [ ! -d "SCL" ]; then
mkdir SCL
......@@ -82,17 +138,12 @@ if [ $BYTILE -ne "0" ]; then
fileprefix=$(echo $scl | (cut -d"_" -f1))
cp ../$fileprefix"_TCI_60m.tif" ../TCI/$fileprefix"_TCI_60m.tif"
done
cd ../TCI
mogrify -format jpg -quality 100 *.tif
mkdir thumbnails
mogrify -path ./thumbnails -resize 10% *.jpg
cd $USERDIR"out/"
cd $USERDIR"jp2/"
done
else
echo "BY DATE"
cd jp2/merge_out/
cd $USERDIR"out/mask/"
if [ ! -d "SCL" ]; then
mkdir SCL
fi
......@@ -106,51 +157,145 @@ else
for scl in $(ls *.tif)
do
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"
cd ../TCI
done
cd ../TCI
echo "mogrify -format jpg -quality 100 *.tif"
mogrify -format jpg -quality 100 *.tif
mkdir thumbnails
mogrify -path ./thumbnails -resize 10% *.jpg
fi
#5.-Extract SCL information
echo "**************************************************** Extracting SCL information..."
cd $USERDIR"jp2/"
#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 -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
#7.-Extract SCL information
echo ${RED}"Extracting SCL information..."${NC}
if [ $BYTILE -ne "0" ]; then
echo "BY TILE"
cd $USERDIR"out/"
for i in $(ls -d */) ; do
cd ../out/$i"SCL"
cd ../out/$i"mask/SCL"
if [ ! -d "json" ]; then
mkdir json
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
cd json
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 "_sclData.json"
cd $USERDIR"jp2/"
cd $USERDIR"out/"
done
else
echo "BY DATE"
cd $USERDIR/jp2/merge_out/SCL
cd $USERDIR"out/mask/SCL/"
if [ ! -d "json" ]; then
mkdir json
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
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
echo "Archivo"
echo $USERDIR
echo "Genenado zip..."
#8.-Create Tiles
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
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
#cd json
#!/bin/sh
INDIR=$1 #Output filename
OUTDIR=$2 #Output filename
POLYGON=$3 #Crop Window
INDIR=$1 #Directory with images to merge
OUTDIR=$2 #Output directory
POLYGON=$3 #Crop Window (minX, maxX, minY, maxY)
DIRNAME=$(echo $INDIR | cut -d"/" -f1)
echo "INDIR:" $INDIR
echo "OUTDIR:" $OUTDIR
......
......@@ -7,6 +7,8 @@ DIRNAME=$(echo $JP2DIR | cut -d"/" -f1)
#echo "POLYGON"
#echo $POLYGON
BOX=$(polygonToBox.py "$POLYGON")
echo "Polygon BOX"
echo $BOX
if [ "$#" -le 1 ]; then
echo "Usage " $0 " <Parent Directory with subdirectories> <POLYGON> [jobs]"
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