Band Math error using sun zenith band

I tried using the sun zenith band in a band math expression which led to a java error. I tried the following statement:

B4 / 10000. / cos(sun_zenith * PI/180.)

The reported error was as follows:

java.lang.IllegalArgumentException: level=4
at com.bc.ceres.glevel.support.AbstractMultiLevelSource.checkLevel(AbstractMultiLevelSource.java:116)
at com.bc.ceres.glevel.support.AbstractMultiLevelSource.getImage(AbstractMultiLevelSource.java:62)
at com.bc.ceres.glevel.support.DefaultMultiLevelImage.getImage(DefaultMultiLevelImage.java:66)
at org.esa.snap.core.image.ImageManager.getLevelImage(ImageManager.java:795)
at org.esa.snap.core.image.ImageManager.getGeophysicalImage(ImageManager.java:115)
at org.esa.snap.core.image.VirtualBandOpImage.addDataToReferredRasterDataSymbols(VirtualBandOpImage.java:303)
at org.esa.snap.core.image.VirtualBandOpImage.computeTile(VirtualBandOpImage.java:235)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at org.esa.snap.core.datamodel.StxFactory.accumulateTile(StxFactory.java:339)
at org.esa.snap.core.datamodel.StxFactory.accumulate(StxFactory.java:323)
at org.esa.snap.core.datamodel.StxFactory.accumulate(StxFactory.java:296)
at org.esa.snap.core.datamodel.StxFactory.create(StxFactory.java:200)
at org.esa.snap.core.datamodel.StxFactory.create(StxFactory.java:274)
at org.esa.snap.core.datamodel.RasterDataNode.computeStxImpl(RasterDataNode.java:2427)
at org.esa.snap.core.datamodel.Band.computeStxImpl(Band.java:504)
at org.esa.snap.core.datamodel.RasterDataNode.getStx(RasterDataNode.java:2394)
at org.esa.snap.core.datamodel.RasterDataNode.createDefaultImageInfo(RasterDataNode.java:1802)
at org.esa.snap.core.datamodel.Band.createDefaultImageInfo(Band.java:483)
at org.esa.snap.core.datamodel.RasterDataNode.getImageInfo(RasterDataNode.java:1784)
at org.esa.snap.core.datamodel.RasterDataNode.getImageInfo(RasterDataNode.java:1767)
at org.esa.snap.core.image.ImageManager.prepareImageInfos(ImageManager.java:834)
at org.esa.snap.core.image.ColoredBandImageMultiLevelSource.create(ColoredBandImageMultiLevelSource.java:51)
at org.esa.snap.core.image.ColoredBandImageMultiLevelSource.create(ColoredBandImageMultiLevelSource.java:47)
at org.esa.snap.core.image.ColoredBandImageMultiLevelSource.create(ColoredBandImageMultiLevelSource.java:41)
at org.esa.snap.ui.product.ProductSceneImage.(ProductSceneImage.java:69)
at org.esa.snap.rcp.actions.window.OpenImageViewAction.createProductSceneImage(OpenImageViewAction.java:181)
at org.esa.snap.rcp.actions.window.OpenImageViewAction.access$000(OpenImageViewAction.java:61)
at org.esa.snap.rcp.actions.window.OpenImageViewAction$1.doInBackground(OpenImageViewAction.java:129)
at org.esa.snap.rcp.actions.window.OpenImageViewAction$1.doInBackground(OpenImageViewAction.java:124)
at com.bc.ceres.swing.progress.ProgressMonitorSwingWorker.doInBackground(ProgressMonitorSwingWorker.java:55)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused: java.util.concurrent.ExecutionException
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at javax.swing.SwingWorker.get(Unknown Source)
[catch] at org.esa.snap.rcp.actions.window.OpenImageViewAction$1.done(OpenImageViewAction.java:143)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

When I save the product afterwards as dimap and re-open the file, the calculated band can be opened. The band math expression also works if I first save the product as dimap and then execute the statement.

Any ideas?
Cheers,
Jan

Hi @Jan,

I just tried it in the upcoming new SNAP version (4.0, to be released in a few days), and I cannot reproduce your issue.
For using the BandMath operator, all bands need to be resampled to a common size (using the Resample operator).

Julien

Hi Julien,

I did that too, sorry for not pointing that out. But unfortunately it doesn’t make a difference. After saving the re-sampled product it works, as described before.

Jan

P.S.: I am also using SNAP 4.0

If you are using SNAP-4.0, then is it the latest and greatest ? Do you have the angles grid at 5000m resolution in the originally opened product (before resampling) ?

I resampled a L1C product containing two granules at 10m, then applied the exact same formula as you, and I don’t reproduce this.

Now that’s weird… I had the problem yesterday and today in the morning. I tried to reproduce it again after your last reply and suddenly it works. I can’t explain why, as described above I did the exact same steps 10 times before. If it happens again, I will try to figure out what the exact basic conditions were leading to the problem.