Skip to content

Copernicus

image image image

Visualizing Copernicus data interactively with Leafmap

To learn more about Copernicus data, please visit https://dataspace.copernicus.eu.

Uncomment the following line to install leafmap if needed.

1
# %pip install -U leafmap localtileserver jupyter-server-proxy xarray
1
2
3
import os
import rasterio
import leafmap.maplibregl as leafmap

To use Copernicus data, you need to get your own credentials. Follow the instructions here to get the credentials. Then, replace the os.environ["AWS_ACCESS_KEY_ID"] and os.environ["AWS_SECRET_ACCESS_KEY"] with your own credentials.

1
2
3
4
5
6
7
os.environ["AWS_ACCESS_KEY_ID"] = "YOUR_ACCESS_KEY_ID"
os.environ["AWS_SECRET_ACCESS_KEY"] = "YOUR_SECRET_ACCESS_KEY"
os.environ["AWS_S3_ENDPOINT"] = "eodata.dataspace.copernicus.eu"
os.environ["AWS_VIRTUAL_HOSTING"] = "FALSE"
os.environ["GDAL_HTTP_UNSAFESSL"] = "YES"
os.environ["AWS_HTTPS"] = "YES"
os.environ["GDAL_HTTP_TCP_KEEPALIVE"] = "YES"

You can create a ~/.s3cfg file to store the credentials. Then use the following command to list the data.

1
s3cmd -c .s3cfg ls s3://eodata/

Let's try out the sample dataset of global water bodies.

1
url = "/vsis3/eodata/CLMS/bio-geophysical/water_bodies/wb_global_1km_10daily_v2/2018/01/01/c_gls_WB_201801010000_GLOBE_PROBAV_V2.1.1_cog/c_gls_WB-WB_201801010000_GLOBE_PROBAV_V2.1.1.tiff"
1
2
with rasterio.open(url) as src:
    print(src.profile)

Visualize the water bodies interactively with Leafmap.

1
2
3
4
m = leafmap.Map(projection="globe")
m.add_basemap("Esri.WorldImagery", visible=False)
m.add_raster(url, vmin=1, vmax=100, colormap="Blues", layer_name="Water Bodies")
m