Merge "homemade" .hdr/.img file with BEAM data using GPT

Deer collegues,

For several reasons, I need to process with my own scripts the .hdr/.img contained in the BEAM-DIMAP format used by SNAP.

Then I would like to reimport the data to the corresponding BEAM-DIMAP. What I do now is :

  • drag’n drop the .dim into SNAP Deskstop
  • drag’n drop the .hdr into SNAP Deskstop
  • use the Band Maths in SNAP Deskstop to create a new band for the BEAM-DIMAP file whose expression is simply the band of the second product (the .hdr one)

That works since the two products are compatible.

However, I would have liked not to do this manually, by using the Graph Procesing Tool (GPT).

First of all, the BandMaths documentation (gpt -h bandMaths) is not very exhaustive. Ok no problem, I can make the process using the graph builder and create a corresponding .xml file that i can call using GPT. However, the expression editors are different. In the graph builder, I cannot choose the other product’s band.

My last chance was using the “Merge” option. Maybe i’m doing wrong but i’m getting the message
"Error: Product [sourceProducts] is not compatible to master product."

using the command

gpt Merge -SmasterProduct="subset_0_of_insar_flt.dim" -SsourceProducts="externalBand.hdr"

Note that the BandMerge gives me the same issue.

I just want to do what I do manually (which works well) using gpt commands. Maybe I just mispelled a command or maybe I miss a subtility.

I would greatly appreciate your help on this “simple” task where i’m stuck. I hope i gave enough information.

Thanks in advance

Do you replace existing bands? If so, you could simply copy the files into .data directory and replace the existing ones if you haven’t changed the data type. If these are newly generated bands you are on the right track.
It is true, the Band Maths within the Graph Builder does not support multiple bands at the moment. This will change in the next releases.
That the Merge does not work is probably due to the reason the one is geocoded and the other not. Set the parameter geographicError to NaN. Then it should work.
For the BandMaths operator I’ve attached an example how you can reference the first and the second product.
BandMaths_twoProducts.xml (623 Bytes)

1 Like

Thanks a lot for your quick response.

The Merge with -PgeographicError=NaN works great. However, it adds the band from the .hdr file as “Band_1”, meaning that if i want to merge several times some new products, the Merge function erases the previous “Band_1”. I can’t find a “rename” module or something to avoid the issue.

From the BandMaths, it works great too but it creates a new BEAM-DIMAP file, instead of adding it to the previous one.

One solution is to convert and rename the hdr to BEAM-DIMAP using the BandMaths module and then use the Merge module. Not elegant but works

You can manually edit the *hdr file.

Add the property

band names = { MyBandName }

This should be considered when you read the files in with SNAP. Maybe you can add this already in your other software. If the name is not given, it is simply named as Band_1. The merge is best used when you write a graph file for it.
then you can use the include section.


There you can specify a new name.
I’ve attached an example: merge_two_nameless_products.xml (971 Bytes)

Actually, the merge should create a new product, too. That’s how the graph processing works in SNAP. One (or more) product in, one product out.

1 Like

The band names = { MyBandName } solution works like a charm.

Actually, I use the Merge with -t option such as it is the same as the -SmasterProduct so I visually don’t create a new file.

Again, thank you for you avaibility and pertinent answers