NDVI batch processing issue

I have some questions related to the NDVI calculation in SNAP for sentinel-2 level2A data

  1. How can I NDVI for multiple scenes simultaneously, ie by batch processing? i tried via GraphBuldier but in the available modules there is no NDVI choice
    (only outside GraphBuilder, in normal SNAP> Optical> Thematic> Vegetation Radiometric Indices menu)

  2. if I make a graph via GraphBuldier, e.g. to count NDWI, or another pointer, and go to Batch Processing and use my graph, then regardless of the number of scenes I get only one output file. How to get the right number of NDWI rasters to the number of input data, keeping e.g. part of the name?

  3. What will be the formula for counting NDVI for many scenes simultaneously in CMD so that the result is 10 resolution and the names are kept with the addition of ‘_NDVI’?

thanks for help,
PD

Outside of SNAP (sorry) you can make a shell script that
iterates over a directory containing the band 4 and band 8 JP2 images
and uses the GDAL executables called gdal_calc.py and gdaldem
to produce coloured versions of the NDVI.
For example the inner loop would do something like this:

gdal_calc.py -A ${NAME}_B04_10m.jp2 \
             -B ${NAME}_B08_10m.jp2 \
                --co="COMPRESS=LZW" \
                --type=Byte  \
                --outfile=tmp.tif \
                --calc="((((A.astype(float)-B)/(A.astype(float)+B))+1)*300-20)"
   
gdaldem color-relief tmp.tif ndvi.txt ${NAME}_NDVI_10m.tif

Where the file ndvi.txt contains:

0 255 255 255
16 196 186 164
25 180 150 108
33 164 130 76
41 148 114 60
51 124 158 44
64 148 182 20
0.30 116 170 4
77 100 162 4
102 84 150 4
115 60 134 4
127 28 114 4
153 4 94 4
179 4 66 4
205 4 58 4
239 4 38 4
255 4 18 4

Hope that helps.

1 Like

I tried, I tried and I think it worked,

I made a script for NDWI in graph builder
(tip: I had to do this for a dedicated file to be able to choose the resolution and output location)
then I edited the script (graph_ndwi_highOK.xml (1.3 KB) ):

1

then I had to edit the processDataset.bat file a bit from https://senbox.atlassian.net/wiki/spaces/SNAP/pages/70503475/Bulk+Processing+with+GPT#Example-Usage because it didn’t work for me
the main changes are “md” to “mkdir”
and in “set procCmd” instead of “-p -t” I gave “-PtargetFile =”! ! “-PsourceFile =”! ! “” and it works (processDataset_deskopOK.bat (1.8 KB) )

but i still have problem with NDVI

any ideas not to use band maths because you can’t add NDVI to grapth in SNAP

the gdal script is beyond my reach :frowning: