Casting Error when opening the B1 and B9 of a Sentinel 2 products on SNAP-Desktop

Description

A Java Casting error is produced when trying to display the band B1 or B9 of a Sentinel2 L2A product. The following stack trace is generated:

java.lang.ClassCastException: [B cannot be cast to [S at org.esa.snap.core.datamodel.ProductData.createInstance(ProductData.java:283) at org.esa.snap.core.image.VirtualBandOpImage.addDataToReferredRasterDataSymbols(VirtualBandOpImage.java:317) [catch] at org.esa.snap.core.image.VirtualBandOpImage.computeTile(VirtualBandOpImage.java:235) at com.sun.media.jai.util.SunTileScheduler.scheduleTile(Unknown Source) at javax.media.jai.PlanarImage.cobbleByte(Unknown Source) at javax.media.jai.PlanarImage.getData(Unknown Source) at org.esa.snap.core.datamodel.StxFactory.accumulateTile(StxFactory.java:343) at org.esa.snap.core.datamodel.StxFactory.accumulate(StxFactory.java:323) ...

The main similarity of the 2 bands B1 and B9 is the resolution 1830x1830.

Here you can see the behavior:

 

Environment

Ubuntu 64bit + Zulu JDK

GitHub Work

None

Attachments

1
  • 21 Apr 2020, 12:44 pm

Activity

Show:

Oana Hogoiu29 April 2020 at 13:06
Edited

Some jp2 files within S2 L2A have byte data type (Java AWT) , and by default all bands created in SNAP for S2 products have the short data type (Java AWT):
S2Config.SAMPLE_PRODUCT_DATA_TYPE = ProductData.TYPE_UINT16 = 21 (SNAP data type) corresponding to short data type in Java AWT.
For solving this, when creating a S2 band the data type should be retrived from TileLayout object, created when reading the jp2 file header (instead of using the default SNAP data type).

Source of the problem:
For each resolution, the header of the first valid file within that category is read, and this header is used for all the bands having that resolution.
When reading from a zip archive, the list of JP2 files searched to read a header is different from the actual list that we see on the file system.
At some products, there are JP2 files with a different data type, but those files are not product bands that will be displayed in SNAP.
For example, when reading a compressed product, the first JP2 file having 20m resolution is 'T33TVF_20200427T095029_TCI_20m.jp2', whose data type is byte.
A solution would be to read the header of each band.

Oana Hogoiu29 April 2020 at 10:11
Edited

We are able to reproduce it with newly products downloaded from SciHub, from April 2020.

E.g.

S2B_MSIL2A_20200410T100029_N0214_R122_T33TUF_20200410T134801
S2A_MSIL2A_20200405T100021_N0214_R122_T33TUF_20200405T115512

Martino Ferrari29 April 2020 at 09:07

Update from :

All bands opened except for B5, B6, B7, B8A, B11, and B12 when compressed. When decompressed everything worked.

Martino Ferrari29 April 2020 at 07:30

Done

Details

Assignee

Reporter

Sprint

Fix versions

Time tracking

2d logged

Priority

Created 21 April 2020 at 08:38
Updated 10 February 2023 at 14:26
Resolved 10 February 2023 at 14:22

Flag notifications