NDVI Processing from command line

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

1 Like

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.

1 Like

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.

1 Like

I tried to use this command gpt NDVIop -Ssource=MTD_MSIL1C.xml -t NDVI.tif in macOs Terminal but all I get is that error message: “gpt: unknown command: NDVIop”.

Can anybody help me?

Could be case sensitive. Try
gpt NdviOp

Doesn’t work either.
Returns the same error message.

When you run gpt -h, can you then find the NDVI operator in the list of operators?


gpt: illegal option – h
usage: gpt [-frv] [-p nparts] command [options] device …

Sure that gpt is the correct command in macOS? I know this command only for disk partitioning purpose.

If I go to the snap directory there is a gpt file. But why I’m not able to call it from terminal? I’m able to execute the gpt file which tells me every possible gpt command. But I can’t call any gpt command from terminal.

Probably you have GParted installed and that’s called instead of SNAP gpt.
Put ‘./’ in front of the call, e.g.
./gpt -h

The ‘./’ uses the local file in the current directory


Doesn’t work either.

what happens if you call the full path of the GPT?

e.g./usr/local/snap/bin/gpt -NdviOp -h

INFO: org.esa.snap.python.gpf.PyOperatorSpi: Python operator ‘py_sambuca_snap_op’ registered (Python module: ‘sambuca_snap_op’, class: ‘sambuca_snap_op’, root: ‘/Users/MYNAME/.snap/system/modules/org-esa-sen2coral-sen2coral-inversion.jar’)
INFO: org.esa.snap.python.gpf.PyOperatorSpi: Python operator ‘S2RutOp’ registered (Python module: ‘s2_rut’, class: ‘S2RutOp’, root: ‘/Applications/snap/s2tbx/modules/org-esa-snap-snap-rut.jar’)
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.s2tbx.dataio.gdal.activator.GDALDistributionInstaller: No distribution folder found on Macintosh.