Have a look at this thread:
In addition you are probably interested in the following snippet:
image_info = ProductUtils.createImageInfo(bands, true, ProgressMonitor.NULL);
image_rgb = ImageManager.getInstance().createColoredBandImage(bands, image_info, 0);
I’ve updated the example on github. Now it writes also an rgb image.
If you want to use only a certain region of the product you should use the Subset operator to tailor the scene to the region beforehand. For S2 data you need to resample them too, because of their multi-resolution nature.
Roughly written this resampling and subsetting would look like:
from snappy import (HashMap, Rectangle, ProductIO, GPF)
source = ProductIO.readProduct('G:/path/to/S2/data')
parameters = HashMap()
parameters.put('referenceBand', 'B2')
resampled = GPF.createProduct('Resample', parameters, source)
parameters.clear()
parameters.put('geoRegion', 'POLYGON((15.786082 45.30223, 11.798364 46.118263, 10.878688 43.61961, 14.722727 42.85818, 15.786082 45.30223))')
# or
parameters.put('region', Rectangle(0,0,1000,1000))
result = GPF.createProduct('Subset', parameters, resample)
ProductIO.writeProduct(result, 'target_filepath.dim', 'BEAM-DIMAP')
There might be errors in the script, I just wrote it down with out further testing. But I think you get the idea.
For getting the possible parameter names you can use the command line tool gpt.
For general help
> gpt -h
For a specific operator like subset
> gpt Subset -h