"Empty region! " occurs at batch-processing using python+snappy

"Empty region! " occurs at batch-processing using python+snappy

Hi,

Can anyone help me? I have sufferd from the problem below for a long time.

I tried to use python3.6+snappy(from SNAP 8.0) to batch calibrate my Sentinel-1 data. My computer has 32g memory and all the data are downloaded completely. But when it comes to the 5th ‘.zip’ data, the memory used will rearch above 20g, and the errors will occur as follows:

Errors is as follows:

INFO: org.esa.snap.core.gpf.common.WriteOp: Start writing product S1A_IW_GRDH_1SDV_20190828T095450_20190828T095515_028768_034210_A6E9_Cal to E:\Code\Python\data_RreprocessingResult\Step1_Calibration\S1A_IW_GRDH_1SDV_20190828T095450_20190828T095515_028768_034210_A6E9_Cal.dim
java.lang.NullPointerException
	at com.sun.media.jai.util.SunCachedTile.<init>(Unknown Source)
	at com.sun.media.jai.util.SunTileCache.add(Unknown Source)
	at javax.media.jai.OpImage.addTileToCache(Unknown Source)
	at javax.media.jai.OpImage.getTile(Unknown Source)
	at javax.media.jai.PlanarImage.getData(Unknown Source)
	at com.bc.ceres.glevel.MultiLevelImage.getData(MultiLevelImage.java:64)
	at org.esa.snap.core.gpf.internal.OperatorContext.getSourceTile(OperatorContext.java:449)
	at org.esa.snap.core.gpf.internal.OperatorContext.getSourceTile(OperatorContext.java:435)
	at org.esa.snap.core.gpf.Operator.getSourceTile(Operator.java:459)
	at org.esa.s1tbx.calibration.gpf.calibrators.Sentinel1Calibrator.computeTile(Sentinel1Calibrator.java:554)
	at org.esa.s1tbx.calibration.gpf.CalibrationOp.computeTile(CalibrationOp.java:190)
	at org.esa.snap.core.gpf.internal.OperatorImage.computeRect(OperatorImage.java:82)
	at javax.media.jai.SourcelessOpImage.computeTile(Unknown Source)
	at com.sun.media.jai.util.SunTileScheduler.scheduleTile(Unknown Source)
	at javax.media.jai.OpImage.getTile(Unknown Source)
	at javax.media.jai.PlanarImage.getData(Unknown Source)
	at com.bc.ceres.glevel.MultiLevelImage.getData(MultiLevelImage.java:64)
	at org.esa.snap.core.gpf.internal.OperatorContext.getSourceTile(OperatorContext.java:449)
	at org.esa.snap.core.gpf.internal.OperatorContext.getSourceTile(OperatorContext.java:435)
	at org.esa.snap.core.gpf.internal.OperatorImage.computeRect(OperatorImage.java:75)
	at javax.media.jai.SourcelessOpImage.computeTile(Unknown Source)
	at com.sun.media.jai.util.SunTileScheduler.scheduleTile(Unknown Source)
	at javax.media.jai.OpImage.getTile(Unknown Source)
	at org.esa.snap.core.gpf.internal.OperatorExecutor$OperatorTileComputationListenerStack.tileComputed(OperatorExecutor.java:315)
	at com.sun.media.jai.util.RequestJob.compute(Unknown Source)
	at com.sun.media.jai.util.WorkerThread.run(Unknown Source)
Traceback (most recent call last):
  File "E:/Code/Python/Step1_Calibration.py", line 31, in <module>
    snappy.GPF.writeProduct(targetProduct, snappy.File(outpath_name), 'BEAM-DIMAP', incremental, snappy.ProgressMonitor.NULL)
RuntimeError: org.esa.snap.core.gpf.OperatorException: Empty region!

The data I used is as follows:
S1A_IW_GRDH_1SDV_20190617T095445_20190617T095510_027718_0320F1_218D.zip
S1A_IW_GRDH_1SDV_20190617T095510_20190617T095535_027718_0320F1_7F33.zip
S1A_IW_GRDH_1SDV_20190711T095447_20190711T095512_028068_032B79_5D63.zip
S1A_IW_GRDH_1SDV_20190711T095512_20190711T095537_028068_032B79_10ED.zip
S1A_IW_GRDH_1SDV_20190828T095450_20190828T095515_028768_034210_A6E9.zip
S1A_IW_GRDH_1SDV_20190828T095515_20190828T095540_028768_034210_860C.zip

My code is as follows:
#The error occurs at the line of “snappy.GPF.writeProduct()”

1. import os                     
2. from glob import iglob        
3. import snappy                 
4. import time

5. #the orignal image in ‘.zip’ format is stored in 'inFld_product'
6. inFld_product = r"E:\Code\Python\data"
7. inPath_S1_files = sorted(list(iglob(os.path.join(inFld_product,  '*S1*.zip'), recursive=False)))
8. outFld_resultData = r'E:\Code\Python\Step1_Calibration'
9. if not os.path.exists(outFld_resultData):
10.     os.makedirs(outFld_resultData)

11. #batch Calibration
12. for i in range(len(inPath_S1_files)):

13.     tic = time.time()
14.     # Read with snappy
15.     s1_read = snappy.ProductIO.readProduct(inPath_S1_files[i])

16.     parameters = snappy.HashMap()
17.     parameters.put('outputSigmaBand', True)
18.     parameters.put('sourceBands', 'Intensity_VH,Intensity_VV')
19.     parameters.put('selectedPolarisations', 'VH,VV')
20.     parameters.put('outputImageScaleInDb', False)
21.     targetProduct = snappy.GPF.createProduct("Calibration", parameters, s1_read)

22.     print('band_names:', list(targetProduct.getBandNames()))

23.     outpath_name = outFld_resultData + '/' + targetProduct.getName() + '.dim'
24.     incremental = False
25.     snappy.GPF.writeProduct(targetProduct, snappy.File(outpath_name), 'BEAM-DIMAP', incremental, snappy.ProgressMonitor.NULL)
26.     toc = time.time()
27.     timeElapse = toc - tic
28.     print('productName=%s, timeElapse=%.1fs'%(targetProduct.getName(),timeElapse))

If you search the forums you will find that using ESA SNAP snappy in a Python loop quicly runs into memory problems. This is because snappy is designed to work with memory objects managed by Java. Snappy is usful when you need to supplement GPF processing with some python code (less and less necessary as more operators are added to gpt, but if you are simply using a python loop to process a list of files you are better off using the loop to construct and execute gpt command-lines, see: Python shell commands (for Windows and linux).