Skip to main content

Super-resolution for Sentinel 2 files.

This library presents a special approach to sharpening imagery, where areas are only sharpened if the model is confident in doing so.

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. Please look at the example colab or investigate the results in their full resolution.

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)

Example colab notebook Open All Collab

Super-sampled band 12. TOPLEFT: RGB, TOPRIGHT: CONFIDENCE, BOTLEFT: UNSHARP, BOTRIGHT:SHARP
Sentinel 2 Band 12 (SWIR2) Sharpnened.
Clockwise from topleft: RGB, Confidence, B12-unsharp, B12-sharpened (Beirut - Lebanon, 2022)
Super-sampled band 12 Zoomed 1. TOPLEFT: RGB, TOPRIGHT: CONFIDENCE, BOTLEFT: UNSHARP, BOTRIGHT:SHARP
Sentinel 2 Band 8A (Narrow-NIR) Sharpnened. Zoomed in.
Clockwise from topleft: RGB, Confidence, B8A-unsharp, B8A-sharpened (Aley - Lebanon, 2022)
Super-sampled band 12 Zoomed 2. TOPLEFT: RGB, TOPRIGHT: CONFIDENCE, BOTLEFT: UNSHARP, BOTRIGHT:SHARP
Sentinel 2 Band 5 (Red Edge 1) Sharpnened. Zoomed in.
Clockwise from topleft: RGB, Confidence, B5-unsharp, B5-sharpened (Rafic Hariri Airport - Lebanon, 2022)

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

Metadata

Release files for s2super 1.2.30

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for s2super 1.2.30
File Size Uploaded
s2super-1.2.30.tar.gz 30.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for s2super 1.2.30
File Interpreter ABI Platform
s2super-1.2.30-py3-none-any.whl Python 3 none any Details

Total release size: 61.1 MB

Release files / s2super-1.2.30.tar.gz

Download URL s2super-1.2.30.tar.gz
Size 30.5 MB
Tags Source
SHA-256 checksum
How to use checksums
a35bf98e3a35ba726e6ed5118a5c2179b6d7669053550866b6bb93f575c6b661
BLAKE2b-256 checksum
How to use checksums
ad505dd0af4be650eb16f1914954a068462da0408ba499c45f946dba8d8c8c98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release files / s2super-1.2.30-py3-none-any.whl

Download URL s2super-1.2.30-py3-none-any.whl
Size 30.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
8245ac8dd2073d16e1e9d39adf6e39e823ac3ed5c474659c325505ea75095f4e
BLAKE2b-256 checksum
How to use checksums
09c28bd3ca7663d24b34585581c363b8d2c5d440874347748980604275d5e8ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.2.30 This release

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page