Reading Products in Java

Hi there,

I’m currently converting my Python pipeline into Java/Scala. I’ve done a call to ProductIO.readProduct(<My file>) but I just receive a null product back. This is the exact same call as I’ve been using with Python and the file is definitely there as I then create a File object with the same path.

Any help is appreciated :slight_smile:

Ciaran

For reference I’m using S1A Data and the file is: S1A_IW_GRDH_1SDV_20170226T173256_20170226T173321_015458_019612_2E3B.zip

Looking into it I don’t seem to get a ProductReader returned. Confusing as it’s the same call that I make in Python, am I missing a dependency or something?

Figured it out, had to add the Sentinel1ProductReaderPlugin to ProductIOPluginManager.

Ironically using Java in Java is more long winded than using Java in Python haha!

Actually the plugin should be found automatically if it is on the class path.
Manually adding plugins to the PluginManager should not be necessary.
Maybe something wrong with your run configuration?

Interesting, what should be on my classpath?

@marpet feeling like I’ve not set up my environment in the correct way. Using IntelliJ and now trying to call GPF functions it cannot find the operators.

Do I need to set some other settings somewhere?

Do you use maven for your project? Then you should add as dependency
        <dependency>
            <groupId>org.esa.s1tbx</groupId>
            <artifactId>s1tbx-io</artifactId>
            <version>5.0.4</version>
        </dependency>

Is 5.0.4 the right version to use? I’ve seen 6.0.0-SNAPSHOT around.

I already had this dependency but with the 6.0.0-SNAPSHOT version

For the operators you need to add also other modules to your project.
I’m also not so familiar with using SNAP this way. So I can’t give you good advices., unfortunately.
Also we have only documented how to use SNAP via snappy but how it is used directly with Java we haven’t explained.
What you should do at the beginning of your Programm is to call
SystemUtils.init3rdPartyLibs(GPT.class);

If you want to use the development version, including all the risks, then you can use 6.0.0-SNAPSHOT, otherwise it is better to stay with the released version.

I see, kind of a pain that it’s difficult writing stuff using the Engine in its native language haha!

Just a observation that the Snappy documentation is few and far between but even documentation for development Java-wise is pretty sparse, are there plans to boost documentation for both Python and Java?

Sorry for being a pain!

@marpet here’s my pom.xml as it stands:

<?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>maven-test</groupId>
    <artifactId>maven-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <snap.version>5.0.3</snap.version>
    </properties>

    <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>

    <dependencies>
        <dependency>
            <groupId>org.esa.snap</groupId>
            <artifactId>snap-core</artifactId>
            <version>${snap.version}</version>
        </dependency>
        <dependency>
            <groupId>org.esa.snap</groupId>
            <artifactId>snap-engine</artifactId>
            <version>${snap.version}</version>
        </dependency>
        <dependency>
            <groupId>org.esa.s1tbx</groupId>
            <artifactId>s1tbx-io</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>

</project> 

Running return GPF.createProduct("Calibration", parameters, product);

Gives me: Exception in thread “main” org.esa.snap.core.gpf.OperatorException: Unknown operator ‘Calibration’. Note that operator aliases are case sensitive.

Yes, there a plans, but since years. :flushed:
Always there is something more important to implement. It’s a pity. :worried:
I started last year a task to improve the documentation, but I didn’t get very far.
It’s good if you bother us with questions like this. Maybe the documentation get’s a higher priority then.

The Calibration is included in the s1tbx-op-calibration module.
So you need to add it to the pom. Probably you will need to add all non -ui ending modules to your pom.
You can find the list here:


The s1tbx-rcp and the s1tbx modules are probably not needed.

I wonder if including snap-engine as dependency works. It seems so. You can access GPF.
The you can probably remove snap-core and maybe, but only maybe, you can use the dependency:

<groupId>org.esa.s1tbx</groupId>
<artifactId>s1tbx</artifactId>
<version>5.0.3</version>

And then you have all necessary dependencies. It is worth a try.

I am still using SNAP v4, but to implement a Sentinel-1 pre-processing chain (several operators like subset, terrain correction, precise orbit, calibration, etc) I have the following dependencies:

<dependencies>
    <dependency>
        <groupId>org.esa.snap</groupId>
        <artifactId>snap-engine-utilities</artifactId>
        <version>${snap.version}</version>
    </dependency>
    <dependency>
        <groupId>org.esa.s1tbx</groupId>
        <artifactId>s1tbx-io</artifactId>
        <version>${s1tbx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.esa.s1tbx</groupId>
        <artifactId>s1tbx-op-sar-processing</artifactId>
        <version>${s1tbx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.esa.s1tbx</groupId>
        <artifactId>s1tbx-op-insar</artifactId>
        <version>${s1tbx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.esa.s1tbx</groupId>
        <artifactId>s1tbx-op-calibration</artifactId>
        <version>${s1tbx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.esa.s1tbx</groupId>
        <artifactId>s1tbx-op-sentinel1</artifactId>
        <version>${s1tbx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.esa.s1tbx</groupId>
        <artifactId>s1tbx-op-utilities</artifactId>
        <version>${s1tbx.version}</version>
    </dependency>
</dependencies>