0

How to mosaic multiple tiles of Modis MOD13Q1 in loop. I have about 395 files of each tile from a total of four tiles. I am using linux operating system and therefore use shell script. I need to mosaic the four tiles for each date. I used the mrt mosaic in MRT which automatically took the four tiles and mosaicked it but is there anyway to automate all the (395 X 4) files in a loop? I carried this out successfully

mrtmosaic -i mosaicfile.txt -s "1 0 0" -o MOSAIC_temp.hdf

what i need is,

mrtmosaic -i tempfile.txt -s "1 0 0" -o MOSAIC_$date.hdf ## tempfile.txt temporary text file containing filenames of four files from the same date but from different tiles that are mosaicked and further removed at the end of the loop

1

The following code worked for me:

# list all the filenames of each tile in a text file and make sure they are identical order (filenames)
#read them as arrays
readarray a < Mod24v05list.txt
readarray b < Mod25v05list.txt
readarray c < Mod24v06list.txt
readarray d < Mod25v06list.txt
for (( i=0; i <= ${#a[@]} ; ++i ))
do 
a1="${a[i]}"
b1="${b[i]}"
c1="${c[i]}"
d1="${d[i]}"
f=$a1$b1$c1$d1
echo $f > mosaicfile.txt
#mosaicked text file contains just the four names that needs to be mosaicked
# date of the file is cut and added to output file name
date=`echo "$a1" | cut -c9-16`
#spectral subset 
mrtmosaic -i mosaicfile.txt -s "1 0 0 0 0 0 0 0 0 0 0 1" -o MOSAIC_$date.hdf
resample -p input2.prm -i MOSAIC_$date.hdf -o MOD13Q1_$date.tif
#removing text file so that a fresh file is created in the loop
# removing mosaicked hdf file too (optional)
rm MOSAIC_$date.hdf
rm mosaicfile.txt
done
exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.