Sentinel-2 preprocessing

remote_sensing_processor.sentinel2(inputs, output_path=None, sen2cor=False, upscale='superres', resample='bilinear', crs=None, cloud_mask=True, clip=None, normalize=False, write_stac=True)[source]

Preprocess Sentinel-2 imagery.

Parameters:
  • inputs (string or list of strings or STAC Item or list of STAC Items) – Path to archive / directory or list of paths to archives / directories or a STAC Item or list of STAC Items (e.g., from Planetary Computer).

  • output_path (string (optional)) – Path to output directory. If not set, then will write to the same directory as archive. Must be set if the inputs are remote STAC Items.

  • sen2cor (bool (default = False)) – Is atmospheric correction using Sen2Cor needed. Set it to False if you have troubles with Sen2Cor. It will have no effect if Sentinel 2 product is already processed to L2A level. It cannot be applied to a remote STAC dataset. As Sen2Cor is an external product, we cannot guarantee that everything will work as expected. As L2A level products are available for most of the Sentinel-2 scenes, we strongly recommend using them instead of L1C level products to skip Sen2Cor stage and make processing faster and more stable.

  • upscale (string or None (default = 'superres')) – Method for upscaling 20- and 60-m bands to 10 m resolution. Can be ‘superres’ - uses neural network for superresolution, ‘resample’ - uses resampling, or None - keeps original band resolution. Set it to ‘resample’ or None if you do not have GPU that supports CUDA.

  • resample (resampling method from rasterio as a string (default = 'bilinear')) – Resampling method that will be used to upscale 20 and 60 m bands if upscale == ‘resample’. You can read more about resampling methods here.

  • crs (any (optional)) – CRS in which output data should be or same to get CRS from the first archive.

  • cloud_mask (bool (default = True)) – Is cloud masking needed.

  • clip (string (optional)) – Path to a vector file to be used to crop the image.

  • normalize (bool (default = False)) – Is min-max normalization to 0-1 range needed.

  • write_stac (bool (default = True)) – If True, then output metadata is saved to a STAC file.

Returns:

List of paths where preprocessed Sentinel-2 products are saved.

Return type:

list of pathlib.Paths

Examples

>>> import remote_sensing_processor as rsp
>>> from glob import glob
>>> sentinel2_imgs = glob("/home/rsp_test/sentinels/*.zip")
>>> print(sentinel2_imgs)
['/home/rsp_test/sentinels/L1C_T42VWR_A032192_20210821T064626.zip',
 '/home/rsp_test/sentinels/L1C_T42WXS_A032192_20210821T064626.zip',
 '/home/rsp_test/sentinels/L1C_T43VCL_A032192_20210821T064626.zip',
 '/home/rsp_test/sentinels/L1C_T43VDK_A031391_20210626T063027.zip',
 '/home/rsp_test/sentinels/L1C_T43VDL_A023312_20210823T063624.zip',
 '/home/rsp_test/sentinels/L1C_T43VDL_A031577_20210709T064041.zip']
>>> output_sentinels = rsp.sentinel2(sentinel2_imgs)
Preprocessing of /home/rsp_test/sentinels/L1C_T42VWR_A032192_20210821T064626.zip completed
Preprocessing of /home/rsp_test/sentinels/L1C_T42WXS_A032192_20210821T064626.zip completed
Preprocessing of /home/rsp_test/sentinels/L1C_T43VCL_A032192_20210821T064626.zip completed
Preprocessing of /home/rsp_test/sentinels/L1C_T43VDK_A031391_20210626T063027.zip completed
Preprocessing of /home/rsp_test/sentinels/L1C_T43VDL_A023312_20210823T063624.zip completed
Preprocessing of /home/rsp_test/sentinels/L1C_T43VDL_A031577_20210709T064041.zip completed
>>> print(output_sentinels)
['/home/rsp_test/sentinels/S2A_MSIL2A_20210821T064626_N0209_R063_T42VWR_20210821T064626/S2A_MSIL2A_20210821T064626_N0209_R063_T42VWR_20210821T064626.json',
 '/home/rsp_test/sentinels/S2A_MSIL2A_20210821T064626_N0209_R063_T42WXS_20210821T064626/S2A_MSIL2A_20210821T064626_N0209_R063_T42WXS_20210821T064626.json',
 '/home/rsp_test/sentinels/S2B_MSIL2A_20210821T064626_N0209_R020_T43VCL_20210821T064626/S2B_MSIL2A_20210821T064626_N0209_R020_T43VCL_20210821T064626.json',
 '/home/rsp_test/sentinels/S2A_MSIL2A_20210626T063027_N0209_R120_T43VDK_20210626T063027/S2A_MSIL2A_20210626T063027_N0209_R120_T43VDK_20210626T063027.json',
 '/home/rsp_test/sentinels/S2A_MSIL2A_20210823T063624_N0209_R120_T43VDL_20210823T063624/S2A_MSIL2A_20210823T063624_N0209_R120_T43VDL_20210823T063624.json',
 '/home/rsp_test/sentinels/S2B_MSIL2A_20210709T064041_N0209_R020_T43VDL_20210709T064041/S2B_MSIL2A_20210709T064041_N0209_R020_T43VDL_20210709T064041.json']