NDVI Processing from command line


#1

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?


#2

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

gpt NDVIop


#3

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


#4
  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


#5

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


#6

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.


#7

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


#8

You probably need to update.
See here:


#9

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.