Skip to main content

SuperResolution of Sentinel2 imagery.

Project description

Super-resolution for Sentinel 2 files.

Provides a function to "Super-Sample" the 20m bands of the Sentinel 2 imagery to match the 10m bands.

It works by using an inception res-net style Deep Learning model trained on 1000 sites randomly selected around the globe. The sites represent at least 25 samples within each Köppen-Geiger climate zone and at least one image for each city in the world with at least 1 million inhabitants. For each location, three training mosaics were collected spread out across different seasons resulting in a total of 3000 mosaics.

The model itself is trained by using the RGB bands to sharpen the downsampled NIR band. First the resampled NIR band is transposed to the mean values of the RGB bands, secondly the network super-samples the transposed NIR band, and thirdly the network mean-matches the low-resolution image to the generated high-resolution image. To super-sample the other bands, they are substituted with the NIR band. The model has been purposely made small to ensure easy deployment, and the methodology is quite conservative in its estimates to ensure that no wild predictions are made.

The package aims to be a drop-in replacement for arrays sharpened with the bilinear method and should provide a minor improvement in downstream model accuracy.

Dependencies
buteo(https://casperfibaek.github.io/buteo/)
tensorflow (https://www.tensorflow.org/)

Installation
pip install s2super

Quickstart

# Setup
from s2super import super_sample

# Constants
YEAR = 2021
MONTHS = 1
AOI = [0.039611, -51.169216] # Macapá

# Example get Sentinel 2 data function.
data = get_data_from_latlng(AOI, year=YEAR, months=MONTHS)[0] 

# Fast is about 2.5 times faster and almost as good.
super_sampled = super_sample(data, method="fast", fit_data=False)

Super-sampled bands: B05, B06, B07, B8A, B11, B12 Super-sampled bands: B05, B06, B07, B8A, B11, B12 Super-sampled bands: B05, B06, B07, B8A, B11, B12

super_sample

Super-sample a Sentinel 2 image. The source can either be a NumPy array of the bands, or a .safe file.

Args:

data (str/np.ndarray): The image to supersample. Either .safe file or NumPy array.

Kwargs:

indices (dict): If the input is not a .safe file, a dictionary with the band names and the indices in the NumPy array must be proved. It comes in the form of { "B02": 0, "B03": 1, ... } (Default: 10m first, then 20m)
method (str): Either fast or accurate. If fast, uses less overlaps and weighted average merging. If accurate, uses more overlaps and the mad_merge algorithm (Default: "fast")
fit_data (bool): Should the deep learning model be fitted with the data? Improves accuracy, but takes around 1m to fit on colab. (Default: True)
fit_epochs (int): If the model is refitted, for how many epochs should it run? (Default: 5)
verbose (bool): If True, print statements will update on the progress (Default: True)
normalise (bool): If the input data should be normalised. Leave this True, unless it has already been done. The model expects sentinel 2 l2a data normalised by dividing by 10000.0 (Default: True)
preloaded_model (None/tf.model): Allows preloading the model, useful if applying the super_sampling function within a loop. (Default: None)

Returns:

(np.ndarray): A NumPy array with the supersampled data.

Cite

Fibaek, C.S, Super-sample Sentinel 2, (2022), GitHub repository, https://github.com/casperfibaek/super_res_s2

Developed at the European Space Agency's Φ-lab.

Build

python -m build; python -m twine upload dist/*

Cuda-setup

conda install -c nvidia cuda-python conda install -c conda-forge cudnn

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s2super-1.1.4.tar.gz (28.5 MB view details)

Uploaded Source

Built Distribution

s2super-1.1.4-py3-none-any.whl (28.5 MB view details)

Uploaded Python 3

File details

Details for the file s2super-1.1.4.tar.gz.

File metadata

  • Download URL: s2super-1.1.4.tar.gz
  • Upload date:
  • Size: 28.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for s2super-1.1.4.tar.gz
Algorithm Hash digest
SHA256 279031ae15f2d0ef76173cf8f5088633ad012a75c1d6198d64522b986315530e
MD5 c3a8fb986122e26a868b7beb052a31bf
BLAKE2b-256 1c2e6870caa32a4268cc8fa4cc38570e0cfd22ec0dced7313cc11e8682899e08

See more details on using hashes here.

File details

Details for the file s2super-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: s2super-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 28.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for s2super-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b0e3a3ca8eab708a8ba70dd95b1829ad06bfd664cf882f8a8c4717c3e3e964c8
MD5 1aa2c18c7f028dd9b3fa56db4c1b8d22
BLAKE2b-256 4cf58dc56f00c9861dc778a5863f0a8d4f33261fa30abb9190c7f4d672a54b03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page