1

first of all, I have to mention that I'm almost new working with Grass and I'm using Grass 6.4.3 on Linuxmint 16. I need to process a large number (~300) of Landsat images. I have downloaded the images from the USGS, I have all of them unzipped, and one folder for each scene containing one file for each band and the metadata file. I need to read/import all the bands of each scene, apply them the radiometric conversion and the atmospheric correction (i.landsat.toar), then do some calculations (r.mapcalc) and finally write a new raster file with the results of these calculations (r.out.gdal?). I can do it manually, importing all bands for each image and doing all the process one by one. That could take me a long time. Much better would be to run a batch job. Could you help me to do it? I've been searching and reading a lot on the web, but I didn't find a solution. So, my problem is: how can I do to read one file, process it, save it, and then read the following file, etc. I have a background programming (R and other languages, not in Python) but I couldn't understand how to perform a batch job inside Grass. Is there a step-by-step tutorial explaining how to do it? Is it possible to read external files and folders in Grass? or I have to import all the raster files to the mapset first and then run the batch job?

Thanks a lot!

EDIT: I think I have reached to something useful, now I have this code:

#!/bin/bash
# Directory where the images are stored
ImgDir="/home/lbianchi/Images/"

for Dir in $(find $ImgDir* -maxdepth 0 -type d ); do
cd $Dir

# Import all files(bands) in de directory     
for files in $(find . -iname '*.tif'); do 
  thefile=$(basename $files)
  importedname=${thefile:0:24}
  fullpath=$PWD"/"$(basename $files)      
  r.in.gdal input=$fullpath output=$importedname
done

# once the bands are imported, apply i.landsat.toar
inputname=${thefile:0:23}
correctedname=${thefile:0:22}"toar_DOS4_"
metadata=${fullpath:0:97}"MTL.txt"
i.landsat.toar input_prefix=$inputname output_prefix=$correctedname metfile=$metadata sensor=tm5 method=dos4
echo $inputname"--"$correctedname
cd ..
done

echo "the end"
exit 0

It does almost what I need, can you help me to improve it? And more important, is there a way to do the same process but without importing ALL files to the Mapset. Otherwise I'm thinking in deleting the imported files once the process is finished. Thanks again.

2

Your Answer

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

Browse other questions tagged or ask your own question.