netCDF CF single flag value error

I’m trying to read a CF-compliant netCDF into SNAP Desktop.
When it contains a single flag_value, this however generates the following error:

Failed to open image view
java.lang.IllegalArgumentException: [NumColors] is less than or equal to [1]

The use case is a simple binary mask, where
1 = tropical_forest
0 = all other land pixels
(_FillValue is used to fill the sea pixels)

Coded into netCDF attributes as
flag_values = 1
flag_meanings = tropical_forest

The same Exception was thrown when reading in other datasets with 1 flag_value too.

Thanks for the report. Can you provide such a product for testing?
I’ll send you a link in a PM where you can upload the data.


This is indeed a limitation in SNAP. The colour handling requires at least two samples. Actually, this is not necessary for index-coding/flag-coding case. I’ve noted this in our issue tracker (SNAP-944).

However, in your case, you have two values [0,1] and I think it would make sense to encode both in the NetCDF file. The second could be named “not_tropical_forest_land”.

Another little hint. You said your file should be CF-compliant. But currently, it is not.
The ubyte is not supported by CF-convention. See:

Also, the string is not well accepted. I think it should be an int.

You can use the CF-Compliance checker:
I did this with your file. It causes an exception at the moment. I’ve reported this already. They told me it is because of the ubyte type. They want to update the checker in order to handle this case better.