Git Product home page Git Product logo

atmospheric_correction's Introduction

A sensor invariant Atmospheric Correction (SIAC)

Feng Yin

Department of Geography, UCL

PyPI version conda py version Docker Image Size (latest by date) Documentation Status Lisence DOI

This atmospheric correction method uses MODIS MCD43 BRDF product to get a coarse resolution simulation of earth surface. A model based on MODIS PSF is built to deal with the scale differences between MODIS and Sentinel 2 / Landsat 8. We uses the ECMWF CAMS prediction as a prior for the atmospheric states, coupling with 6S model to solve for the atmospheric parameters. We do not have topography correction and homogeneous surface is used without considering the BRDF effects.

🐳 Docker:

Please refer to the SIAC Docker usage instruction inside Docker folder.

Citation:

Yin, F., Lewis, P. E., and Gómez-Dans, J. L.: Bayesian atmospheric correction over land: Sentinel-2/MSI and Landsat 8/OLI, Geosci. Model Dev., 15, 7933–7976, https://doi.org/10.5194/gmd-15-7933-2022, 2022.

Auxiliary data needed (Automatically downloaded by SIAC):

  • MCD43 :
    • 16 days before and 16 days after the Sentinel 2 / Landsat 8 sensing date.
    • This has been updated to automatically download data from Google Earth Engine (GEE), which is much faster than the previous way. This means you will need to register to get access to GEE at here.
    • Or you can still use the previous way to download the data by adding the Gee = False in the SIAC_S2 or SIAC_L8 class, i.e. SIAC_S2(**kwargs, gee=False) or SIAC_L8(**kwargs, gee=False).
  • ECMWF CAMS Near Real Time prediction:
  • Global DEM:
  • Emulators:
    • Emulators for atmospheric path reflectance, total transmittance and single scattering Albedo, and the emulators for Sentinel 2 and Landsat 8 trained with 6S.V2 are packed in the current repository.

Installation:

You will need to have gdal and Lightgbm installed, and it is suggested to install them with:

  • conda:
    conda install -c conda-forge gdal lightgbm
  • mamba:
    mamba install -c conda-forge gdal lightgbm

Then you can install SIAC:

  • Directly from GitHub

    pip install https://github.com/MarcYin/SIAC/archive/master.zip

GEE authenticate:

If you have not used GEE python API before, you will need to authenticate to GEE first after you installed SIAC:

  • In terminal:

    earthengine authenticate --auth_mode=notebook
  • Or in python:

    import ee
    ee.Authenticate()

Usage:

The typical usage of SIAC for and Landsat 8&9:

  • Sentinel 2

    from SIAC import SIAC_S2
    global_dem = '/vsicurl/https://gws-access.jasmin.ac.uk/public/nceo_ard/DEM_V3/global_dem.vrt'
    cams_dir = '/vsicurl/https://gws-access.jasmin.ac.uk/public/nceo_ard/cams/'
    SIAC_S2('/directory/where/you/store/S2/data/', global_dem = global_dem, cams_dir=cams_dir)
  • Landsat 8

    from SIAC import SIAC_L8
    global_dem = '/vsicurl/https://gws-access.jasmin.ac.uk/public/nceo_ard/DEM_V3/global_dem.vrt'
    cams_dir = '/vsicurl/https://gws-access.jasmin.ac.uk/public/nceo_ard/cams/'
    SIAC_L8('/directory/where/you/store/L8/data/', global_dem = global_dem, cams_dir=cams_dir) 
  • Landsat 9

    from SIAC import SIAC_L8
    global_dem = '/vsicurl/https://gws-access.jasmin.ac.uk/public/nceo_ard/DEM_V3/global_dem.vrt'
    cams_dir = '/vsicurl/https://gws-access.jasmin.ac.uk/public/nceo_ard/cams/'
    SIAC_L8('/directory/where/you/store/L9/data/', global_dem = global_dem, cams_dir=cams_dir)

Outputs from SIAC_S2

All the outputs from SIAC are specified in the siac_output.json within the original S2 L1C folder:

An example of the siac_output.json

The following table specifies a list of the outputs from SIAC and their corresponding meanings:

Abbreviation Description Scale Comments
siacLog Siac log file N/A
toaOvrs Toa reflectance RGB overviews N/A
boaOvrs Surface reflectance RGB overviews N/A
toaOvrFull Toa reflectance RGB overview full resolution N/A
boaOvrFull Surface reflectance RGB overviews N/A
viewAngles View angles for each band 0.01 2 bands GeoTiff: B1 view azimuth, B2 view zenith
sunAngles Sun angles for each band 0.01 2 bands GeoTiff: B1 sun azimuth, B2 sun zenith
SurfaceReflectance Surface reflectance for each band 0.0001
SurfaceReflectanceUncertainty Surface reflectance uncertainty for each band 0.0001
atmoParas Atmospheric parameters N/A aerosol optical depth[-], total column of water vapour [ $g/cm^2$ ] and total column of ozone [ $cm-atm$ ]
atmoParasUncs Atmospheric parameter uncertainties N/A
Cloud probability Cloud 0.01
Version Version of the SIAC software N/A
CleanPixelPercentage Clean pixel percentage N/A
ValidPixelPercentage Valid pixel percentage N/A

Outputs from SIAC_L8

All the outputs from SIAC are within the original L8/L9 L1C folder.

  • An example of correction for Landsat 5 for a more detailed demonstration of the usage is shown here

Examples and Map:

A page shows some correction samples.

A map for comparison between TOA and BOA.

LICENSE

GNU GENERAL PUBLIC LICENSE V3

atmospheric_correction's People

Contributors

jgomezdans avatar marcyin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

atmospheric_correction's Issues

JP2 not recognized as a supported file format

Using SIAC-V2.3.5 and GDAL 2.3.3 on a recent Sentinel 2 observation returns the following error: ... .jp2' not recognized as a supported file format.

This is returned after the following output: Doing per pixel angle resampling.

Do you have any suggestions on how to address this?

P.S. Thank you for contributing to open source EO tools. This has the potential to be quite useful for batch processing.

Allow passing in single files

The atmospheric correction expects some of its auxiliary data (as the MODIS MCD43 files) to be placed in a single folder that is to be browsed. It would be good if it were possible to hand in the files directly, especially when these might be located in different folders.

S2 atmospheric correction

Hi @TonioF @gritk ,

This atmospheric correction method needs:

Sentinel 2 data downloaded from AWS on a tile basis, which is much more convenient and reasonable compared to how ESA save the Sentinel 2 data);
CAMS near real time prediction for each day at a time step of 3 hours with the start time of 00:00:00, and should contains aod550, tcwv and gtco3 parameters;
a global DEM VRT file;
MCD43 collection 6 data from 3 days before to 3 days after the sentinel 2 observations;
you will also need the emulators for Sentinel 2 bands, which can be found at http://www2.geog.ucl.ac.uk/~ucfafyi/
The executable file is called Sentinel_atmo_cor.py which can be used as: python Sentinel_atmo_cor.py /directory/where/you/store/s2/data/29/S/QB/2017/9/4/0/ . No other options are needed for this version yet. It will correct for all bands and save them into the same directory of TOA reflectance with the name as B0?_sur.tif and a TOA_RGB.tif and BOA_RGB.tif is also composed for vision checking.

Further details are referred to GitHub at https://github.com/multiply-org/atmospheric_correction

Thanks a lot,

Feng.

ValueError: operands could not be broadcast together with shapes (7931,3910) (7931,7821)

I used to work on atmospheric correction of Landsat 8 via this package. But I struggle in the problem like following.

from SIAC import SIAC_L8
import os

BASE_DIR = r"E:\Remote Sensing"

kwargs = dict(
    l8_dir=os.path.join(BASE_DIR, "Landsat", "LC08_L1TP_147031_20170515_20170525_01_T1", ""),
    mcd43=os.path.join(BASE_DIR, "MCD43", ""),
    vrt_dir=os.path.join(BASE_DIR, "MCD43", ""),
    global_dem=os.path.join(BASE_DIR, "eles", "global_dem.vrt"),
    cams_dir=os.path.join(BASE_DIR, "cams", "")
)

if __name__ == "__main__":
    SIAC_L8(**kwargs)
2020-02-12 08:17:27,591 - SIAC-2.3.0 - INFO - Starting atmospheric corretion for E:\Remote Sensing\Landsat\LC08_L1TP_147031_20170515_20170525_01_T1
...
...
...
2020-02-12 09:47:18,612 - SIAC-2.3.0 - INFO - Doing corrections.
Traceback (most recent call last):
  File "C:\Users\tcztzy\Documents\GitHub\multiply-org\atmospheric_correction\main.py", line 15, in 
    SIAC_L8(**kwargs)
  File "C:\Users\tcztzy\Documents\GitHub\multiply-org\atmospheric_correction\SIAC\SIAC_L8.py", line 44, in SIAC_L8
    aero_atmo = do_correction(*ret)
  File "C:\Users\tcztzy\Documents\GitHub\multiply-org\atmospheric_correction\SIAC\SIAC_L8.py", line 122, in do_correction
    atmo._doing_correction()
  File "C:\Users\tcztzy\Documents\GitHub\multiply-org\atmospheric_correction\SIAC\the_correction.py", line 590, in _doing_correction
    ret = self._get_boa()
  File "C:\Users\tcztzy\Documents\GitHub\multiply-org\atmospheric_correction\SIAC\the_correction.py", line 431, in _get_boa
    re = list(map(self._do_chunk, bands_to_do))
  File "C:\Users\tcztzy\Documents\GitHub\multiply-org\atmospheric_correction\SIAC\the_correction.py", line 464, in _do_chunk
    toa = toa * self.ref_scale + self.ref_off
ValueError: operands could not be broadcast together with shapes (7931,3910) (7931,7821)

Conda install failed due to MD5 mismatch

conda create -n siac
conda install -n siac -c conda-forge -c f0xy siac
...
Downloading and Extracting Packages
siac-2.3.1           | 10.2 MB   | ########################################################################### | 100%  
ChecksumMismatchError: Conda detected a mismatch between the expected content and downloaded content
for url 'https://conda.anaconda.org/f0xy/noarch/siac-2.3.1-0.tar.bz2'.
  download saved to: C:\Users\tcztzy\scoop\apps\miniconda3\current\pkgs\siac-2.3.1-0.tar.bz2
  expected md5: 64188e31f1537075cf02e64e269023c6
  actual md5: 84c7875dcd76c36a9cead4ba7e267db0

And I use my web browser download url 'https://conda.anaconda.org/f0xy/noarch/siac-2.3.1-0.tar.bz2'

$ md5sum /mnt/c/Users/tcztzy/Downloads/siac-2.3.1-0.tar.bz2
84c7875dcd76c36a9cead4ba7e267db0  /mnt/c/Users/tcztzy/Downloads/siac-2.3.1-0.tar.bz2

documentation name

@MarcYin
For consistency please change the documentation name for the repository to
MULTIPLY - Sensor Invariant Atmospheric Correction (SIAC)

Pickle file should be binary

As the title said. When you clone the source code on Windows, the pickle file's end line will replace by '\r\n' by default, which will cause the error while loading. Adding a file named .gitattributes with content like following will solve this problem.

*.pkl binary

Numpy dependency problem

Numpy 1.18 introduce this PR. And this PR will cause the problem as I reported.

to_inv = np.nansum([sparse.diags((self.obs_unc[0]).ravel()), sparse.diags((self.prior_uncs[0]**-2).ravel()), self.gamma**2 * dtd], axis = 0)

to_inv = np.nansum([sparse.diags((self.obs_unc[1]).ravel()), sparse.diags((self.prior_uncs[1]**-2).ravel()), self.gamma**2 * dtd], axis = 0)

AttributeError: Can't pickle local object

I used to suffer the exceptions as the title said. I personally think if a nested function doesn't relay on the local variable of the parent's scoop, put this function on the top scoop is the better way.
Python: AttributeError: Can't pickle local object 'writeBuf..write'
Can't pickle function

def smooth(da_w):
da, w = da_w
mid = int(da.shape[0]/2)
if (da.shape[-1]==0) | (w.shape[-1]==0):
return da[mid], w[mid]
data = np.array(smoothn(da, s=10., smoothOrder=1., axis=0, TolZ=0.001, verbose=False, isrobust=True, W = w))[[0, 3],]
return data[0][mid], data[1][mid]

def convolve(img, gaus_2d, hx, hy):
x_size, y_size = img.shape
if x_size % 2 != 0:
img = np.insert(img, -1, img[-1, :], axis=0)
if y_size % 2 != 0:
img = np.insert(img, -1, img[:, -1], axis=1)
dat = idct(idct(dct(dct(img, axis=0, norm = 'ortho'), axis=1, \
norm='ortho') * gaus_2d, axis=1, norm='ortho'), axis=0, norm='ortho')[hx, hy]
return dat

def fill_nan(array):
x_shp, y_shp = array.shape
mask = ~np.isnan(array)
valid = np.array(np.where(mask)).T
value = array[mask]
mesh = np.repeat(range(x_shp), y_shp).reshape(x_shp, y_shp), \
np.tile (range(y_shp), x_shp).reshape(x_shp, y_shp)
array = griddata(valid, value, mesh, method='nearest')
return array

def fill_nan(array):
x_shp, y_shp = array.shape
mask = ~np.isnan(array)
valid = np.array(np.where(mask)).T
value = array[mask]
mesh = np.repeat(range(x_shp), y_shp).reshape(x_shp, y_shp), \
np.tile (range(y_shp), x_shp).reshape(x_shp, y_shp)
array = griddata(valid, value, mesh, method='nearest')
return array

def euclid_distance(arr):
n = arr.shape[0]
ans = 0.0
for i in range(n-1):
for j in range(i+1,n):
d = np.sqrt(np.sum([(arr[i,k]-arr[j,k])**2 for k in range(arr.shape[1])]))
ans += 1.0/d**2
return ans
def fill_space(data):
best = 1e8
for it in range(iterations):
d = euclid_distance(data)
if d<best:
d_opt = d
data_opt = data.copy()
data = _mix(data)

SIAC may not work with GDAL>=3.0

I used to install SIAC with pip, things worked fine before the process handling MCD43_VRT, I got the error message as "None object has no attributes named FlushCache", the detailed log message shows that it failed getting VRT files from HDR. The latest release of gdal in pypi is version 3.0.3, I downgrade gdal to 2.4.4, such problems solved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.