A Python package for managing Sentinel-2 satellite data cubes π
GitHub: https://github.com/IPL-UV/satcube π
PyPI: https://pypi.org/project/satcube/ π οΈ
satcube is a Python package designed for efficient management, processing, and analysis of Sentinel-2 satellite image cubes. It allows for downloading, cloud masking, gap filling, and super-resolving Sentinel-2 imagery, as well as creating monthly composites and performing interpolation.
- Satellite image download: Retrieve Sentinel-2 images from Earth Engine efficiently. π°οΈ
- Cloud masking: Automatically remove clouds from Sentinel-2 images. βοΈ
- Gap filling: Fill missing data using methods like linear interpolation and histogram matching. π§©
- Super-resolution: Apply super-resolution models to enhance image quality. π
- Monthly composites: Aggregate images into monthly composites with various statistical methods. π
- Temporal smoothing: Smooth reflectance values across time using interpolation techniques. π
Install the latest version from PyPI:
pip install satcube
import ee
import satcube
ee.Authenticate()
ee.Initialize(project="ee-csaybar-real")
outpath = satcube.download_weights(path="weights")
datacube = satcube.SatCube(
coordinates=(-77.68598590138802,-8.888223962022263),
sensor=satcube.Sentinel2(weight_path=outpath, edge_size=384),
output_dir="wendy01",
max_workers=12,
device="cuda",
)
# Query the Sentinel-2 image collection
table_query = datacube.metadata_s2()
# Filter images based on cloud cover and remove duplicates
table_query_subset = table_query[table_query["cs_cdf"] > 0.30]
table_query_subset = table_query_subset.drop_duplicates(subset="img_date")
mgrs_tile_max = table_query_subset["mgrs_title"].value_counts().idxmax()
table_query_subset = table_query_subset[table_query_subset["mgrs_title"] == mgrs_tile_max]
table_download = datacube.download_s2_image(table_query_subset)
# Remove clouds from the images
table_nocloud = datacube.cloudmasking_s2(table_download)
table_nocloud = table_nocloud[table_nocloud["cloud_cover"] < 0.75]
table_nocloud.reset_index(drop=True, inplace=True)
# Fill missing data in the images
table_nogaps = datacube.gapfilling_s2(table_nocloud)
table_nogaps = table_nogaps[table_nogaps["match_error"] < 0.1]
# Generate monthly composites
table_composites = datacube.monthly_composites_s2(
table_nogaps, agg_method="median", date_range=("2016-01-01", "2024-07-31")
)
# Interpolate missing months if necessary
table_interpolate = datacube.interpolate_s2(table=table_composites)
# Smooth reflectance values across time
table_smooth = datacube.smooth_s2(table=table_interpolate)
# Apply super-resolution to the image cube
# table_final = datacube.super_s2(table_smooth)
# Display the images from the data cube
datacube.display_images(table=table_smooth)
# !apt-get install imagemagick
import os
os.system("convert -delay 20 -loop 0 wendy01/z_s2_07_smoothed_png/temp_07*.png animation.gif")
from IPython.display import Image
Image(filename='animation.gif', width=500)
# Smooth reflectance values across time
table_smooth = datacube.smooth_s2(table=table_interpolate)
- Cloud masking: Efficient removal of clouds from satellite images.
- Resampling methods: Various methods for resampling and aligning imagery.
- Super-resolution: ONNX-based models for improving image resolution.