Operator.setSourceProduct() not working as intended

I have a separate project, which I set up to test the inner workings of different operators, but I seem to be having problems trying to set a single source product, like this:

Product product1 = this.reader1.readProductNodes(file1, null);
this.tileHeight = 560;
this.tileWidth = 404;

Operator operator = new CoherenceOp();
operator.setSourceProduct(product1);
//((CoherenceOp) operator).sourceProduct = product1;
operator.initialize();

the commented out part is what I used to forcefully set source products after setting their field public in the operator. The operator works after this, but I suspect that a bug that surfaces later is connected to it.

The code produces the following error:
java.lang.NullPointerException
org.esa.snap.core.gpf.OperatorException: java.lang.NullPointerException
problems reading nodes
at org.esa.snap.engine_utilities.gpf.OperatorUtils.catchOperatorException(OperatorUtils.java:415)
at operators.CoherenceOp.initialize(CoherenceOp.java:227)
at OperatorHandler.coherenceEstimation(OperatorHandler.java:102)
at Main.main(Main.java:9)
Caused by: java.lang.NullPointerException
at org.esa.snap.engine_utilities.datamodel.AbstractMetadata.getAbstractedMetadata(AbstractMetadata.java:633)
at operators.CoherenceOp.initialize(CoherenceOp.java:198)
… 2 more

The error was achieved on intellij. The project is only composed of the operator and the code that starts it up. I have more of such projects, but all of those use setSourceProducts in plural, which works just fine.

Is there anything that I need to do with an operator before setting source product?

using the following pom.xml file:
<?xml version=“1.0” encoding=“UTF-8”?>
<project xmlns=“http://maven.apache.org/POM/4.0.0
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>

<groupId>erik.soekov</groupId>
<artifactId>coherence-play</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<snap.version>7.0.0-SNAPSHOT</snap.version>
<s1tbx.version>7.0.0-SNAPSHOT</s1tbx.version>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.esa.snap</groupId>
<artifactId>snap-core</artifactId>
<version>{snap.version}&lt;/version&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/dependency&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;dependency&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;groupId&gt;org.esa.snap&lt;/groupId&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;artifactId&gt;snap-geotiff&lt;/artifactId&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;version&gt;{snap.version}</version>
</dependency>
<dependency>
<groupId>org.esa.snap</groupId>
<artifactId>snap-gpf</artifactId>
<version>{snap.version}&lt;/version&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/dependency&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;dependency&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;groupId&gt;org.esa.s1tbx&lt;/groupId&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;artifactId&gt;s1tbx-commons&lt;/artifactId&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;version&gt;{s1tbx.version}</version>
</dependency>
<dependency>
<groupId>org.esa.s1tbx</groupId>
<artifactId>s1tbx-op-insar</artifactId>
<version>{s1tbx.version}&lt;/version&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/dependency&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;dependency&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;groupId&gt;org.esa.snap&lt;/groupId&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;artifactId&gt;snap-engine-utilities&lt;/artifactId&gt; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;version&gt;{s1tbx.version}</version>
</dependency>
<dependency>
<groupId>org.jocl</groupId>
<artifactId>jocl</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>snap-repo-public</id>
<name>Public Maven Repository for SNAP</name>
<url>http://nexus.senbox.net/nexus/content/repositories/public/</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<publicPackages>
<publicPackage>org.esa.s1tbx.*</publicPackage>
</publicPackages>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>ee.cgi.malbolge.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

Your XML hasn’t read, or product set reader, this the first thing,

How many products do process at once?

Do you use gpt command call, or bulk bash?

Did you apply the similar in your computer before? Or this the first time? (Might be RAM issue)

The XML is read in fine. I had the product output it’s details before it gets sent to the operator and everything matches. If I forcefully set the product, by making the source product field public then it partly works.

I use 1 product, which is a TOPSAR coregistered stack. Has a total of 6 bands.

I do not understand what you mean with gpt command call or bulk bash. Are they tools of some sort? What I did myself is that I took out the CoherenceOp java class from snap’s code and I’m running this in a different java program to see how it works from the inside.

Why am I doing this is that I’m trying to build a GPU powered operator into SNAP. I already got half of Back-geocoding working and now I’m setting my sights on Coherence operator.

Please take a look at this Creating a GPF Graph

I think @marpet could answer this,

No I do not use this. As said before I do not use tools, but run the java code in a different program. In that program I do not use that either. The program itself simulates a very light snap environment where I can run the operator and monitor its insides.

Then I think the best one to answer this as I mentioned is @marpet

Would you please to share details how to use it.

I uploaded it here: https://github.com/erik132/coherencePlay

The current project will produce the error, when started from Main

Hi erik132,
I think the problem will be solved if you simply remove the following line:

operator.initialize();

This is probably misbehaviour of the framework.
In the case of the CoherenceOp, it uses the field sourceProduct in its initialize method. But it is still not set. This field is only set when the getTargetProduct is called. The getTargetProduct method is the method which should be called by clients, it ensures that the initialisation takes place in the right order. The initialise method should actually not be called. This is documented in the API doc
Your code works actually around the framework (maybe for good reasons), but in this case, it can happen that things don’t work smoothly.

2 Likes

This solved it. I figured that setSourceProduct already makes the appropriate arrangements to initialize everything in the operator correctly, because I did not have a problem with its plural version setSourceProducts, which I used with the same code.

However now that I looked into getTargetProducts() code everything makes sense. Thank you :slight_smile: