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

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">
    <version>1.0</version>
    <node id="someNodeId">
      <operator>NdviOp</operator>
      <sources>
        <source>${source}</source>
      </sources>
      <parameters>
        <redFactor>float</redFactor>
        <nirFactor>float</nirFactor>
        <redSourceBand>string</redSourceBand>
        <nirSourceBand>string</nirSourceBand>
      </parameters>
    </node>
  </graph>

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.
https://www.computerhope.com/issues/chusedos.htm.

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?

Returns:

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

Ciao
Marco

Doesnā€™t work either.