import sys
import numpy as np
from snappy import ProductIO
from snappy import GPF


dir = '/DATA/Satellite/SENTINEL2/venice/L1C/'
file=dir+'S2A_OPER_PRD_MSIL1C_PDMC_20160718T175711_R022_V20160718T101028_20160718T101028.SAFE/'

# native product
product = ProductIO.readProduct(file)

sza=product.getBand('sun_zenith')

width=sza.getRasterWidth()
szas2 = np.zeros(width, dtype=np.float32)
sza.readPixels(0, 0, width, 1, szas2)
print szas2

# resampled product
GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()

HashMap = jpy.get_type('java.util.HashMap')
BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')

parameters = HashMap()
parameters.put('targetResolution',60)
parameters.put('upsampling','Bicubic')
parameters.put('downsampling','Mean')
parameters.put('flagDownsampling','FlagMedianAnd')
parameters.put('resampleOnPyramidLevels',True)

product=GPF.createProduct('Resample', parameters, product)

sza=product.getBand('sun_zenith')

width=sza.getRasterWidth()
szas2 = np.zeros(width, dtype=np.float32)
sza.readPixels(0, 0, width, 1, szas2)
print szas2
