This repository provides a list of comprehensive tools and utilities for the usage of the SEN2SR neural network super-resolution model, developed by the ESAOpenSR team. This model specializes in upscaling Sentinel-2's 10m/px images up to a x4 times improvement of 2.5m/px.
This package implements a feature to crop a polygon directly from the SR image, useful for close-up satellite observation of agricultural states.
- Clone the repository
git clone https://github.com/KhaosResearch/sen2sr-tools.git cd sen2sr-tools - Create a virtual environment and install all dependencies
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -e .
The overall workflow can be run directly, since it implements a simple example in it:
cd sen2sr-tools
python -m sen2sr_tools.get_sr_imageThe example can also be run using commands:
python -m sen2sr_tools get-sr-image --latitude 42.465226 --longitude -2.292699 --start-date 2025-11-01 --end-date 2025-11-15 --geojson-path ./example.geojsonOutput will be at sen2sr_out, where the SR and original images can be seen.
All relevant methods are stored in the get_sr_image module.
Using get_sr_image runs the full workflow, from date and location data to super resolved image. Default size is the minimal requested 128px. Default bands are Near-Infrared, Red, Blue, Green and the Scene Classification Layer, that contains cloud density information among others. Cropping a polygon from the image is optional, provided the GeoJSON filepath. The final image outputs are in TIF and PNG formats, for usage and visualization respectively.
from sen2sr_tools.get_sr_image import get_sr_image
lat = 37.265840
lng = -4.593406
start_date = "2025-11-01"
end_date = "2025-11-15"
# bands = ["B08", "B02", "B03", "B04", "SCL"] # Default bands
# size = 128 # Default size
# geometry = None # Default value
sr_filepath = get_sr_image(lat, lng, bands, start_date, end_date)
print(f"SR image successfully downloaded and saved at: {sr_filepath}")Running download_sentinel_cubo serves the requested bands' data directly. It uses the date range to get cloudless (<=1%) images. The crs can be provided (i.e, "EPSG:32630"), but it can also be automatically calculated from the lat and lon arguments. If no requested data is found within the date range, it retries with by expanding it backwards in time. The CUBO data is provided as a Dask.array.
from sen2sr_tools.get_sr_image import download_sentinel_cubo
lat = 37.265840
lng = -4.593406
start_date = "2025-11-01"
end_date = "2025-11-15"
# crs = None # Default CRS
# bands = ["B08", "B02", "B03", "B04", "SCL"] # Default bands
# size = 128 # Default size
# cloud_threshold= 0.01 # Default threshold density
# max_retries = 3 # Default retries
# retry_days_shift = 15 # Default shift
cloudless_cubo_data_array, sample_date = download_sentinel_cubo(lat, lon, start_date, end_date)
print(f"CUBO data summary:\n\n{cloudless_cubo_data_array.coords}")
# If you need the array as NumPy
# cubo_np_array = (cloudless_cubo_data_array.astype("float32") / 10_000).compute()The crop_parcel_from_tif method crops the polygon from the given TIF file and returns the cropped image output and metadata.
import json
import geopandas as gpd
from sen2sr_tools.get_sr_image import crop_parcel_from_tif
gdf = gpd.read_file(geometry)
raster_path = "path/to/file.tif"
geometry = {
"type": "Polygon",
"coordinates": [[
[-2.29544172799985, 42.46242962302221],[-2.292531924994703, 42.46538599420777],
[-2.292180580738519, 42.463584097818824], [-2.286733836169323, 42.464620125420105],
[-2.29544172799985, 42.46242962302221]
]],
"CRS": "epsg:4258"}
out_image, out_meta = crop_parcel_from_tif(raster_path, geojson_path)
print(f"Polygon successfully cropped!")We appreciate the work done by the ESAOpenSR team in upscaling and super-resolving satellite imagery and making SR models accessible through Open Source code. This module is built upon the core model and concepts of the sen2sr Python package.
- Original Repository: https://github.com/ESAOpenSR/SEN2SR.git
The original work is licensed under the CC0 1.0 Universal License.
The model file (model/model.safetensors) is available for download from HugginFace.
- Official SEN2SR HuggingFace model card: https://huggingface.co/tacofoundation/sen2sr.