I have the following lines of code in a bash script I wrote using osgeo's GRASS command line tools:
i.vi viname=ndvi output=$ndvi_fn nir=$nir_fn red=$red_fn --overwrite
while r.info $ndvi_fn -r | grep NULL;do
echo "Failed to write NDVI file, trying again"
sleep 2
i.vi viname=ndvi output=$ndvi_fn nir=$nir_fn red=$red_fn --overwrite
done
This will loop indefinitely. If I stop my script, and rerun it, usually the NDVI band is actually written to the file. Sometimes the third try or more (not always on the second attempt). I can not understand for the life of me why restarting the script makes a difference from sleeping and running it again.
The script will only work if I comment out the while loop, and I rerun the script. I have also tried using g.remove type=raster name=$ndvi_fn -f
in the while loop to remove and recreate the file every iteration. no luck.
Has anyone else seen erratic behavior with i.vi
? I checked the docs.. but it seems like I'm using it correctly.
g.region raster=$nir_fn [-p]
. Just to be sure...