107 copernicus

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.
| # %pip install -U leafmap localtileserver jupyter-server-proxy xarray
|
| import os
import rasterio
import 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.
| 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.
| s3cmd -c .s3cfg ls s3://eodata/
|
Let's try out the sample dataset of global water bodies.
| 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"
|
| with rasterio.open(url) as src:
print(src.profile)
|
Visualize the water bodies interactively with Leafmap.
| m = leafmap.Map()
m.add_raster(url, vmin=1, vmax=100, colormap="Blues", layer_name="Water Bodies")
m
|
