Sentinel-2 Atmospheric Correction with ACOLITE

  1. Navigate to https://github.com/acolite/acolite and read.


  1. Open a terminal and run the following lines:

  • conda create -n acolite -c conda-forge python=3

  • conda activate acolite

  • conda install -c conda-forge numpy matplotlib scipy gdal pyproj scikit-image pyhdf pyresample netcdf4 h5py requests pygrib astropy cartopy


  1. Set your NASA EarthData username and password and system variables:

  • export EARTHDATA_u=XXXXXX

  • export EARTHDATA_p=XXXXXX


  1. Navigate to a suitable installation directory and run the following lines:


  1. Run.


  1. Convert netCDF output to ENVI format:

    1. Navigate to output directory.

    2. Run the following lines of code:

      1. If S2A

  • for i in *L2R.nc; do gdal_translate -of ENVI NETCDF:"${i}":rhos_443 ${i%???}_b01; gdal_translate -of ENVI NETCDF:"${i}":rhos_492 ${i%???}_b02; gdal_translate -of ENVI NETCDF:"${i}":rhos_560 ${i%???}_b03; gdal_translate -of ENVI NETCDF:"${i}":rhos_665 ${i%???}_b04; gdal_translate -of ENVI NETCDF:"${i}":rhos_704 ${i%???}_b05; gdal_translate -of ENVI NETCDF:"${i}":rhos_740 ${i%???}_b06; gdal_translate -of ENVI NETCDF:"${i}":rhos_783 ${i%???}_b07; gdal_translate -of ENVI NETCDF:"${i}":rhos_833 ${i%???}_b08; gdal_translate -of ENVI NETCDF:"${i}":rhos_865 ${i%???}_b08a; gdal_translate -of ENVI NETCDF:"${i}":rhos_1614 ${i%???}_b11; gdal_translate -of ENVI NETCDF:"${i}":rhos_2202 ${i%???}_b12; done

  • for i in *b01; do gdal_merge.py -separate -of ENVI -o ${i%????????}_eStack ${i} ${i%?}2 ${i%?}3 ${i%?}4 ${i%?}5 ${i%?}6 ${i%?}7 ${i%?}8 ${i%?}8a ${i%??}11 ${i%??}12; done

  • for i in *_eStack.hdr; do echo 'wavelength units = Micrometers' >> ${i}; done

  • for i in *_eStack.hdr; do echo 'wavelength = {0.443, 0.492, 0.560, 0.665, 0.704, 0.740, 0.783, 0.833, 0.865, 1.614, 2.202}' >> ${i}; done

  • rm -v *_b*


      1. If S2B:

  • for i in *L2R.nc; do gdal_translate -of ENVI NETCDF:"${i}":rhos_442 ${i%???}_b01; gdal_translate -of ENVI NETCDF:"${i}":rhos_492 ${i%???}_b02; gdal_translate -of ENVI NETCDF:"${i}":rhos_559 ${i%???}_b03; gdal_translate -of ENVI NETCDF:"${i}":rhos_665 ${i%???}_b04; gdal_translate -of ENVI NETCDF:"${i}":rhos_704 ${i%???}_b05; gdal_translate -of ENVI NETCDF:"${i}":rhos_739 ${i%???}_b06; gdal_translate -of ENVI NETCDF:"${i}":rhos_780 ${i%???}_b07; gdal_translate -of ENVI NETCDF:"${i}":rhos_833 ${i%???}_b08; gdal_translate -of ENVI NETCDF:"${i}":rhos_864 ${i%???}_b08a; gdal_translate -of ENVI NETCDF:"${i}":rhos_1610 ${i%???}_b11; gdal_translate -of ENVI NETCDF:"${i}":rhos_2186 ${i%???}_b12; done


  • for i in *b01; do gdal_merge.py -separate -of ENVI -o ${i%????????}_eStack ${i} ${i%?}2 ${i%?}3 ${i%?}4 ${i%?}5 ${i%?}6 ${i%?}7 ${i%?}8 ${i%?}8a ${i%??}11 ${i%??}12; done

  • for i in *_eStack.hdr; do echo 'wavelength units = Micrometers' >> ${i}; done

  • for i in *_eStack.hdr; do echo 'wavelength = {0.443, 0.490, 0.560, 0.665, 0.705, 0.740, 0.783, 0.842, 0.865, 1.610, 2.190}' >> ${i}; done

  • rm -v *_b*