NDVI Processing from command line


Is there way to generate NDVI images via command line with 3 bands (for ex: B4, B5 and B8) using sen2cor or some other software?


the graph processing tool of SNAP does that. You don’t need sen2cor.

gpt NDVIop


Thanks! but there is little documentation online about this command.

Can you give an example of usage, using the command or the xml graph file or both??

Thanks again

  1. Navigate in the folder where your product is
  2. Enter the command

e.g. for Sentinel-2:
gpt NDVIop -Ssource=MTD_MSIL1C.xml -t NDVI.tif


It works fine with L1C products!
But when converted to L2A products (to 20m resolution for example), it does not work when running the command:

$ gpt NDVIop -Ssource=MTD_MSIL2A.xml -t NDVI.tif

Any advice on this matter?

thanks in advance


I guess you get an error message like no appropriate band was found, right?
Does your 20m L2A product contain the bands B4 and B8?
These are the bands which are chosen by default by the NDVI and they are 10m bands.


Thx for rp!

The error is listed and right bellow it lies the ‘.SAFE’ folder structure with all bands as you can see in the image!

Note: I’ve noticed that the L2A folder structure generated by ’ L2A_process’ command is a little different than the L1C folder structure… it has this ‘R20m’ subfolder among other things… but I assume that the command and the xml is prepared to handle this


You probably need to update.
See here:


I’ve seen this post, but I considered it unlikely because I downloaded Snap 6.0 directly from Esa website
(http://step.esa.int/main/download/ ).

Still, just to be sure after your reply, I’ve performed a command-line update following Snap’s docs:

“Update all modules
To update all modules which can be updated you need to call”
$ snap --nosplash --nogui --modules --update-all

Strangely, it updated some of the modules, and others where downgraded, like the Snap’s GUI (maybe a cause of the --nogui param, dont know). So, I had to reinstall Snap 6.0 in another folder to have both sets of modules.

Anyway, the gtp NDVIop command works on L2A Product folders now.
But after analisys i’ve notice that the L2A 20m resolution images are mutch worse than the L1C 60m images.

Image: Brazil / Paraguay border. L1C, L2A (20m), and L2A (10m) products, respectively

How come is that?

  1. Is ther a way to choose the resolution in witch you want to perform the NDVIop on any of L1C or L2A products?

  2. When you perform a L2A_process with a 10m resolution parameter, the process creates both 20m and 10m resolution images on all bands. When I perform gtp NDVIop in this case, how would I know what resolution the commando is choosgin?

  3. Can some one give a clear example on how to use the so called NDVIop’s graph xml:

 <graph id="someGraphId">
    <node id="someNodeId">

NOTE: Iam performing all processes and convertions via command line. The goal is to automate.


Where to write this command? Which software?


your windows command line.


As @ABraun said. You nee to use the command line.
You should have an entry in your start menu which is named “SNAP Command-Line”.
You can simply search for it in the start menu.