Batch processing for VIs calculation

I am trying to calculate around 20 vegetation indices for multiple images(L2A) and trying to automate this process using graph builder. Can someone please help me with this problem?

Thank you.

Hi Rajeev,
You can write one VI processor in the graph builder at one time. Then use the band processing for applying them to all your images. The second step would be copy the bands generated by each VI into one single product using band maths in the graph builder and later process all your images with the batch processing tool again.

Thank you very much. It worked. Can you now tell me how can I stack the bands in SNAP?

Radar > Coregistration > Stack Tools > Create Stack

also works for optical data

Why is is saying that I need to select at least two source product? I just wanted to create a stacked layer from a Band Merged output…

delete the Band Merge step and connect all products of the band maths directly to the stack operator.

Thank you. I did that but what I really wanted to do is to apply a final mask to the stacked bunch, so I am adding band math 4 . In bandmath 4 no any single stack is showed so I am finding difficulty with masking at once.
If you could help me with this, a big part of my work would be solved.
Thank you .

Why exactly do you need the BandMerge operator then?
Are all the bands shown in the “create stack” operator?

yes all the bands are shown but how can I apply a single mask in one operation. I removed band merge operation after using create stack operation.

where is your mask defined?
If you create it after the stacking (Band Maths 4 in your screenshot) it will be applied to all bands.

Sorry, it’s hard to understand without knowing what is done in all the Band Maths and what is the aim of the final mask.

Let me tell you the whole process:
Subset( I subset-ed only 9 bands and a quality classification image to make a mask by assigning 1 to vegetation and 0 to all others by band math operation.)
Bandmath : the bandmath in second column bandmath 1 is used to create mask from quality classified image while bandmath 2 and 3 are used to calculate 2 separate vegetation indices.
Band Merge: removed that step
Create stack: I wanna stack all the images obtained before into a single file
Band math 4: I want to apply mask to the bunch of the images stacked.
Thank you .

if you want to mask out all areas in the final product, you can either multiply the mask by your bands to make them 0 where the mask is 0, or you use the mask you created in the valid pixel expression (mask = 1) to exclude all pixels where the mask is 0.

Can I apply a mask to all the images at once or do I need to do that masking once for one image and repeat it several times for several images???

I’m not sure to be honest.
@marpet: Is there a solution to apply a mask to all bands in a stack in one step?

If all the images are in a single product, you could use the Land/Sea Mask processor.

I think the Land/Sea mask processor is not working here, as it can only mask land and sea or vector data within the product.

With the GraphBuilder you need to add several BandMaths operations and you need to merge them afterwards. Maybe the create stack works, too, but I have never used it. So I can’t tell.
That’s a sample graph for the builder: MathAndMerge_GraphBuilder.xml (4.9 KB)

On the command line, with gpt, you can use one BandMaths operation and configure multiple expressions.
S2_math_gpt.xml (2.1 KB)
It contains at the beginning an example, how it can be called from the command line.

In both graph files you need to replace the expressions with yours and add more bands. But it shows how it should work in general. IN

1 Like

Thank you Marco. Its gonna work but the graph will be very busy for 20 VIs I think. Wont it?

I tried using stack but couldn’t get through. Can you please have a look on this process? It would be very beneficial if we could come out with a way to mask everything together.
Thank you.

Yes, it will be busy. Sure. It needs to comput things.
Unfortunately I can’t send more time on this. I showed two ways how you can proceed and mask the data.
I can’t do more.

Its not a problem. Thank you . Its solved now.