biophysicalProcessor - subseting

Hello everybody,

I’m actually computing a large amount of LAI / FAPAR for Sentinel-2 data. Due to the amount of region I have I am using snappy to automatize all my work.

My problem is that the computation of those two vegetation information is really long. For each location I have a shapefile associated and I noticed that I can’t subset my image before processing the LAI : it says "RuntimeError: org.esa.snap.core.gpf.OperatorException: Missing band at 560.0 nm".

I saw that for the creation of the biophysical factors, all the metadata was needed so I added it in my subset function that looks like this :

def subset(product,wkt):
    parameters = HashMap()
    return GPF.createProduct('Subset',parameters,product)

And here my functions for computing the factors :

def biophysicalProcessor(product, LAI = True, FAPAR = False, FCOVER = False, CAB = False, CW = False):
    parameters = HashMap()
    parameters.put('computeLAI', LAI)
    parameters.put('computeFapar', FAPAR)
    parameters.put('computeFcover', FCOVER)
    parameters.put('computeCab', CAB)
    parameters.put('computeCw', CW)
    return GPF.createProduct('BiophysicalOp',parameters,product)    

def resample(product, targetRes):
    parameters = HashMap()
    parameters.put('targetResolution', targetRes)
    return GPF.createProduct('Resample',parameters,product)    

def BIOFactors(file, dst, res=10, wkt = None, LAI = True, FAPAR = False, FCOVER = False, CAB = False, CW = False) :
    X = read(file)
    X = resample(X, res)
    if wkt != None :
        WKT = WKTReader().read(wkt)
        X = subset(X, WKT)
    X = biophysicalProcessor(X, LAI = LAI,
                                FAPAR = FAPAR,
                                FCOVER = FCOVER,
                                CAB = CAB,
                                CW = CW)
    if not os.path.isfile(dst) :
    return dst 

Maybe my subset function is not good to fit with the biophysicalProcessor function …
But I tried on snap and there was no problem in subseting first before computing the LAI.

So if you have any idea to permit to subset before computing it will help me to save a lot of time !

Thanks in advance for your answers.

In your subset function you do also a band subset. Only the first band is included in the result.

Try this snippet:

def subset(product,wkt):
    parameters = HashMap()
    return GPF.createProduct('Subset',parameters,product)

here the first band is used as referenceBand. This is needed because it is a multi-resolution product. All bands are included in the result.

I see, didn’t noticed this line of my function… Thanks for the help it’s now working.

I’m trying to apply the resampling to the subset object using a target resolution but I retrieve this error :

RuntimeError: org.esa.snap.core.gpf.OperatorException: Use of target resolution parameter is not possible for this source product.

Any specific reason for this ?

There are some restrictions for the usage of the targetResolution parameter. E.g the transform of the CRS should be affine.
With a Sentinel-2 product this should work.