Image subsetting with condition


I’m trying to subset my S3 image based on the result of a band math expression in GPT.
I filtered the image based on Viewing Zenith Angle and I want to subset from 4865*4091 to 472*4091. This would exclude all the unnecessary NaN values resulted from band math and save disk space.

My ideas so far:

  • I would need to automatically detect the x,y locations of the valid pixels, which have the min and max x, y values (the four corners of the valid area). Then I could use these locations as Scene Start and Scene End in the Subset operator. Is there a way to do this?

  • Or, it would be so simple using numpy.
    Is there a way in XML to NOT write to file but write to a numpy array, and use numpy operations?

Thak you for your help!

The first idea is the way you should do it.
First determine the coordinates and the create a subset. This can be done in Python.

When you invoke gpt with an xml file from python the result is always stored on disk.
But you can also call GPF.createProduct(…) and then you will get an in-memory representation of the result. And you can work with the data. Have a look at several threads in the Python section.
And also these links

Thank you!

I will try that.