Process

Process#

class grs.grs_process.Process[source]#

Bases: object

Main GRS class.

execute(l1c_prod, ofile='', cams_file=None, surfwater_file=None, dem_file=None, resolution=20, scale_aot=1, opac_model=None, allpixels=False, snap_compliant=False)[source]#

Main program calling all GRS steps

Parameters:
  • l1c_prod – xarray L1C object or L1C input file (path) to be processed

  • ofile – Absolute path of the output file

  • cams_file – Absolute path for root directory of CAMS data

  • surfwater_file – Absolute path the surfwater file (.tif)

  • dem_file – Absolute path of the DEM geotiff file

  • resolution – pixel resolution in meter

  • scale_aot – scaling factor applied to CAMS aod550 raster

  • opac_model – If set force OPAC aerosol model for LUT interpolation (taken from CAMS data otherwise)

  • allpixels – if True process all pixels (no water pixel masking)

  • snap_compliant – Output format compliant with SNAP software for practical analysis

Returns:

Examples#

>>> import grs
>>> file ='$YOUR_PATH_TO_IMG/S2A_MSIL1C_20181019T102031_N0500_R065_T30PYT_20230815T043850.SAFE'
>>> tile = file.split('_')[-2][1:]
>>> dem_file = '$YOUR_PATH_TO_DEM/COP-DEM_GLO-30-DGED_'+tile+'.tif'
>>> cams_file = '$YOUR_PATH_TO_CAMS/cams_forecast_2018-10.nc'
>>> process_ = grs.Process()

In this example, you force the aerosol model to be ‘DESE_rh70’ for desert dust

>>> process_.execute(file_nc,
...                 cams_file=cams_file,
...                 surfwater_file=None,
...                 dem_file=dem_file,
...                 scale_aot=1,
...                 opac_model='DESE_rh70')
INFO:root:pass netcdf image as grs product object
INFO:root:get CAMS auxilliary data
INFO:root:flagging from l1c data
INFO:root:cloud masking with s2cloudless
INFO:root:land masking
INFO:root:cirrus masking
INFO:root:high swir masking
INFO:root:loading look-up tables
INFO:root:compute gaseous transmittance from cams data
INFO:root:correct for gaseous absorption
INFO:root:compute spectral index (e.g., NDWI)
INFO:root:apply water masking
INFO:root:lut interpolation
INFO:root:selected aerosol model: DESE_rh70
INFO:root:scaling aot by: 1
INFO:root:set final parameters
INFO:root:compute surface pressure from dem
INFO:root:run grs process
INFO:root:success
INFO:root:construct final product
INFO:root:construct l2a
>>> process_.l2a.l2_prod
<xarray.Dataset>
Dimensions:      (wl: 11, y: 1818, x: 2523)
Coordinates:
  * wl           (wl) int64 443 490 560 665 705 740 783 842 865 1610 2190
    time         datetime64[ns] 2018-10-19T10:20:31.024000
  * x            (x) float64 7.299e+05 7.299e+05 7.3e+05 ... 7.803e+05 7.804e+05
  * y            (y) float64 1.3e+06 1.3e+06 1.3e+06 ... 1.264e+06 1.264e+06
    band         int64 1
    spatial_ref  int64 0
Data variables:
    Rrs          (wl, y, x) float32 nan nan nan nan nan ... nan nan nan nan nan
    BRDFg        (y, x) float32 nan nan nan nan nan nan ... nan nan nan nan nan
    aot550       (y, x) float32 0.187 0.187 0.187 0.187 ... 0.1929 0.1929 0.1929
    vza          (y, x) float32 6.489 6.489 6.483 6.483 ... 2.13 2.125 2.125
    sza          (y, x) float32 nan nan nan nan nan nan ... nan nan nan nan nan
    raa          (y, x) float32 332.5 332.5 332.5 332.5 ... 290.0 289.9 289.9
    flags    (y, x) int64 184 56 184 184 184 184 ... 160 160 160 160 160 160
    dem          (y, x) float32 282.9 282.7 282.5 282.3 ... 237.3 237.3 237.4
    surfwater    (y, x) int8 1 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 1
Attributes: (12/71)
    long_name:                           CA BLUE GREEN RED VRE_1 VRE_2 VRE_3 ...
    constellation:                       Sentinel-2
    constellation_id:                    S2
    product_path:                        /data/satellite/Sentinel-2/L1C/30PYT...
    product_name:                        S2A_MSIL1C_20181019T102031_N0500_R06...
    product_filename:                    S2A_MSIL1C_20181019T102031_N0500_R06...
    ...                                  ...
    ndwi_threshold:                      0.0
    vis_swir_index_threshold:            0.0
    hcld_threshold:                      0.003
    dirdata:                             /data/grs/grsdata
    abs_gas_file:                        /home/harmel/Dropbox/Dropbox/work/gi...
    water_vapor_transmittance_file:      /home/harmel/Dropbox/Dropbox/work/gi...

You can either further play with the l2a xarray or save it into netcdf:

>>> process_.ofile='./name_of_your_output_l2a_netcdf'
>>> process_.write_output()
INFO:root:export final product into netcdf
INFO:root:export into encoded netcdf