1

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.

3
  • 1
    Silly question, has the computational region been set to the input map(s)? g.region raster=$nir_fn [-p]. Just to be sure...
    – markusN
    Commented May 18, 2022 at 20:29
  • actually no.. I was doing it AFTER I created the NDVI image. i'll move it before and try again! Thanks for something to try!
    – Nick Brady
    Commented May 18, 2022 at 21:10
  • it worked! Seems obvious in hindsight. Thank you so much @markusN !! If you'd like, please paste your comment as an answer so I can accept the answer. Thanks again, cheers :)
    – Nick Brady
    Commented May 19, 2022 at 12:52

1 Answer 1

1

Please be sure if the computational region been set to the input map(s) prior to the i.vi command. In your case, just use the variable to pass on the raster map name:

g.region raster=$nir_fn [-p]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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