How to apply the Band math to multiple images

Hello everyone!
I am a beginner in Python programming and I need to collocate four daily ocean color images and calculate the band math for eight bands, and I need to do it for 10 years of daily images! I was wondering if there was a code on automatic collocation and also the band math calculations.
Thank you a bunch!
Reza

Hi, sorry but this is not a Python froum. We mainly answer questions about SNAP. There are some things you can do with SNAP if your images have the right format and they can be read. You have not specied which sensor you use or what is the final target of your time series analysis.

1 Like

Thank you Ana for your reply. Actually, I’m using MODIS-MERIS merged images to extract chlorophyll concentration from band ratios. However, I have daily images for ten years. That’s why I was trying ti find a way to facilitate the work.

@Ocean_9 look at Graph Builder.

It’s possible to do this in Python, but setting up the environment is a royal pain. Once you have the Graph built in GraphBuilder, you can run it in batch mode.

Collocate is under Geometric

2 Likes

I would also say, that if you are new to python, snappy is probably not for you.
But you might want to use SNAPISTA (snap-contrib.github.io)
And as @cndnflyr suggested. You can set up the processing chain in the graph builder modify it and use it from the command line.
How to use gpt from the command line is explained here:
Bulk Processing with GPT - SNAP - Confluence (atlassian.net)

1 Like

@cndnflyr & @marpet I sincerely appreciate your help. I’m going to go through your advices rightaway.

I have tried to modify the script file to apply band math for multiple products to create new bands from the coherence maps displaying only the pixels with coherence values higher than 0.97 and here’s what I have done.

This is the graph file and the graph itself
Filter_high_coh_pixels.xml (1.7 KB)

This is the modified bash file
processDataset_modified.bash (1.8 KB)

and this is the original unix script provided by https://senbox.atlassian.net/wiki/spaces/SNAP/pages/70503475/Bulk+Processing+with+GPT#Description-of-the-Scripts
processDataset.bash (1.5 KB)

I still don’t know what the path to parameter.properties file. Therefore I still won’t be able to run the following command

What can I do to modify/run the scrip?

Maybe @gnwiii you could help if you wouldn’t mind?

In general, gpt needs the full path starting from the “root” (“/”) directory. Using linux shell script, you use environment variables to make it easier to enter a bunch of long paths. For example, if you have all
your files under a project director such as /home/user/Projects/2023/SNAP_projects and parameters.properties in a Parameters subdirectory, you can use:

$ export project_path="/home/user/Projects/2023/SNAP_projects/current_project/Parameters"
$ ./processDataDataset_modified.bash "<graph_xml_filepath>" "$project_path"/Parameters/parameters.properties" ...

A couple useful tricks:

  • You can put echo in front of /home/shadi/esa_snap/bin/gpt to have the script print the full command line so you can check for typos. When you get file not found errors you can copy and paste the file path after ls in the terminal to look for the error.

  • The -e option for gpt will display more detailed error messages.

2 Likes

I appreciate your response
The problem I am facing is, what to write inside the properties file, nor how do I create a file with such an extension. The latter is solvable, I shall take an example .properties file and edit its contents. The process I would like to perform is a simple band math on multiple coherence maps. So, what are the required parameters other than having a graph.xml file with the conditions to the bandmath process already saved in it.

Do I use this file to start adding parameters for my band-math process?
snappy_bmaths.py (2.1 KB)