RuntimeError: java.lang.NullPointerException in snappy

Hi i’m working with snappy and my scripts works so well until when i arrive at 2010 file. After that moment in my terminal apears the error:

Traceback (most recent call last):
File “./complete_output_file.py”, line 67, in
ProductIO.writeProduct(result,outDir,outForm)
RuntimeError: java.lang.NullPointerException

My script is:

#!/usr/bin/python

import sys
import glob
#import netCDF4
from netCDF4 import Dataset as ncDataSet

import snappy
from snappy import ProductIO
from snappy import GPF
import numpy as np
import os
# region

if len(sys.argv) >= 1:
    region = sys.argv[1]
else:
    sys.exit("Incorrect number of arguments for " + sys.argv[0])

# TOA path files
path=region + '/data/*'

list=sorted(glob.glob(path), key=os.path.getmtime)
#list=glob.glob(path)

for e in range(len(list)):

    # open netcdf file to know TOA file

    ncFile=ncDataSet(list[e],'a',format='NETCDF4')
    TOA=ncFile.__dict__['l1_file']

    # Just execute if file is not processed

    if 'sst_nadir' in ncFile.__dict__ :


        nom=TOA[17:76]


        # SNAP - Optical - Thematic water Processing - (A)ATSR SST Processor


        source=ProductIO.readProduct(TOA)
op_spi=GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi('Aatsr.SST')

param_Desc=op_spi.getOperatorDescriptor().getParameterDescriptors()

        #for param in param_Desc:

        HashMap=snappy.jpy.get_type('java.util.HashMap')

        parameters=HashMap()


        parameters.put("dual","false")
        parameters.put("nadir","true")
parameters.put("nadirCoefficientsFile","AVERAGE_POLAR_SINGLE_VIEW")
parameters.put("nadirMaskExpression","!cloud_flags_nadir.LAND")
        parameters.put("invalidSstValue","-999.0")
result=snappy.GPF.createProduct('Aatsr.SST',parameters,source)

        #outDir='/mnt/lustre/scratch/'+nom+'.nc'
        outDir='/home/masdeu/'+nom+'.nc'
        outForm='NETCDF4-CF'
        ProductIO.writeProduct(result,outDir,outForm)

        start=ncFile.__dict__[u'start_line']
        end=ncFile.__dict__[u'end_line']

        ncFile2=ncDataSet(outDir,'r',format='NETCDF4')
        sstCor=ncFile2.variables['nadir_sst']
        lati=ncFile2.variables['latitude'][:]
        loni=ncFile2.variables['longitude'][:]

        A=sstCor[start:end+1,:]
        B=lati[start:end+1,:]
        C=loni[start:end+1,:]

# TOA processed result has a mirror effect, for that reason we use a fliplr command before save the result in the final file

        E=np.fliplr(A.data)
        lat_TOA=np.fliplr(B)
        lon_TOA=np.fliplr(C)

        #sst_cell=ncFile.variables['sst'][:]
        lat_cell=ncFile.variables['lat'][:]
        lon_cell=ncFile.variables['lon'][:]

        #rmse between ghrsst and toa
        rmse_lat=np.sqrt(((lat_TOA-lat_cell)**2).mean())
        rmse_lon=np.sqrt(((lon_TOA-lon_cell)**2).mean())

        if rmse_lat>=0.005 or rmse_lon>=0.005:
            print('ATENTION! LAT-LON DISTANCE>=500m')
            ncFile.rmse_lat = rmse_lat
            ncFile.rmse_lon = rmse_lon
        else:
            ncFile.rmse_lat = rmse_lat
            ncFile.rmse_lon = rmse_lon
        # Write sst values from Corrected TOA to original netCDF
        ncFile.variables['sst'][:]=E

        del ncFile.sst_nadir

        write=list[e] + ' Complete'
        print(write)
        ncFile.close()
        ncFile2.close()

        os.remove(outDir)
        print("File Removed!")
    else:
        write=list[e] + ' SST added'
        print(write)

you have some idea?

thank you!

What if you from again with the first product which failed? Do you get the same error?
If not it could be that you are running out of memory. How many products do you process before it fails?

Hi,

I have the same issue. I created a script for coherence estimation, the script suceed to write images in VV or VH decibels in Tiff. But when i want to write the coherence estimation image in Tiff I have this error message : image
And this is the function for saving an image : image

I don’t know how to solve this issue because it’s working for all other images, no matter the size … but the coherence one wont save…
If anyone has an idea, I hope revive this topic will help.

Thanks in advance.

I have the same problem for creating product file within phase unrwrapping step.
How did you fix this issue?

Hum concerning the saving part I didn’t change anything. It been a while I didn’t work on coherence but I think the issue was earlier and it wasn’t able to save it because there was no data on the product. If I remember well the issue was located in the geocoding process while combining the two dates images… At this time I played with the parameters to fix the issue.

What is exactly your issue ? Is it the same RuntimeError msg ?

I have a similar doubt, I’m trying to import the unwrapped image, but the following error appears…

java.lang.NullPointerException: Failed opening a dataset from the file ‘…’ to load the product

Your error occurs when opening an input dataset, but you have posted in a thread that deals with problems saving a product with ProductIO.writeProduct(). Please read the FAQ and then start a new topic. You should include enough details to allow others to reproduce your problem.

This is the message that appears.

The images you provide hide some of the important details. The name of your source product is truncated. The path shown for the file where a dataset failed to open has a data file in a “bin” directory normally reserved for programs.

Snaphu Export and file paths notes that you can encounter problems when snaphu.conf doesn’t have the full path of the files.

I am having the same problem with the Maximun Likehood Classifier, in supervised. I set multiple classes however as soon as I press run I get this error. I am using a geo tiff image file.

The unsupervised method worked fine.

What do you mean by same problem? There are many many causes of a Java “NullPointerException”, so more detail is needed. You should always provide enough detail to allow other to reproduce the problem, including your OS version, SNAP version update status.

Note that some tools do not handle paths that contain spaces. You appear to have many spaces (e.g., 8<space>red, RGB<space>-<space>Ramp, OneDrive<space>-<space>Fir and New<space>Folder). This problem often occurs in 3rd party code used by SNAP. Since many users have learned from experience to avoid spaces, the issue may be missed by other users.

1 Like

Thanks for the contributions.