Reading Sentinel 2 pixel data with snappy


#1

Hi! I’m new to python and snappy. I am trying to read all bands (not just B01) of a Sentinel 2 image and create a dictionary containing all the information (to be able to call, for example, B01 and see the array of pixel values). The final goal is to convert the dictionary into a netcdf file format. Any help will be appreciated!

Here is what I got so far:

import sys, os
sys.path.append(‘C:\Users\Me\Anaconda2\pkgs’)
os.chdir=(“D:\Sentinel2\S2A_MSIL1C_20180914T160901_N0206_R140_T16QEJ_20180914T212259\S2A_MSIL1C_20180914T160901_N0206_R140_T16QEJ_20180914T212259.SAFE\GRANULE\L1C_T16QEJ_A016868_20180914T162534\IMG_DATA”)

import snappy
from snappy import ProductIO
p1 = ProductIO.readProduct(“T16QEJ_20180914T160901_B01.jp2”)


#2

First, you should use the full path with the readProduct method.
os.chdir does not work. It only works in the Python environment and with snappy you are using Java.

Also, you should use the MTD_MSIL1C.xml file and not the jp2 file. This way, the product which is returned by readProduct will contain all bands.