ndvi_processor.py (3.6 KB)
I’m adding the Python program that does batch NDVI processing of Sentinel-2 products and masking them to an area.
Create a directory and make sure all Sentinel-2 L2A products you want to be processed are in it.
Create a GeoJSON mask enclosing the area of interest. Draw it with http://geojson.io and save it as
field.jsoninside the same directory as the L2A products. What I’d do is copy-paste the JSON code to a text file and change the extension from .txt to .json.
Make sure you have PyCharm CE installed together with Conda. The default package manager (pip) makes things very difficult.
Create a new project and import the attached .py file.
Open the file so that you can see the code. Make sure all frameworks at the top of the .py file are imported (installed).
Scroll all the way to the bottom and you’ll see the line:
ndvi_batch_processor('D:', 'field.json'). Replace
'D:'with the directory where the L2A zips and the
field.jsonfile are located.
Run the entire thing.
What this program does is to search for zip files in the working directory, create a list of products to be processed, and then one-by-one unzip, create NDVI raster, mask to the GeoJSON, delete full-size NDVI raster and temporary folder with the unzipped product. You should be left with several NDVI files one for each of the source products.
Let me know how this works out.
ADDENDUM: As @cristianoLopes pointed out, I should improve my input; his points make good sense, at least to the extent I can understand, and I’ll try to do in due course.
In the meantime, there’s no license to this code, use it as you please.