Exploring WorldFloods#
Last Modified: 9-1-2024
Authors: Gonzalo Mateo-García, Enrique Portalés-Julià
This notebook shows the locations and some of the products of the WorldFloodsv2 dataset published in:
E. Portalés-Julià, G. Mateo-García, C. Purcell, and L. Gómez-Chova Global flood extent segmentation in optical satellite images. Scientific Reports 13, 20316 (2023). DOI: 10.1038/s41598-023-47595-7.
Download dataset#
Download the WorldFloodsv2 dataset from HuggingFace 🤗:
huggingface-cli download --cache-dir /path/to/cachedir --local-dir /path/to/localdir/WorldFloodsv2 --repo-type dataset isp-uv-es/WorldFloodsv2
Note 1: the dataset requires approximately 76Gb of disk storage!
Note 2: the
local_dir
variable in this notebook should point to thelocal-dir
argument in the previous line.
Explore the locations of the products#
import pandas as pd
import geopandas as gpd
from georeader import window_utils
from shapely.geometry import box
import os
local_dir = "/path/to/localdir/WorldFloodsv2"
metadata_file = os.path.join(local_dir,"dataset_metadata.csv")
metadata = pd.read_csv(metadata_file)
metadata["geometry"] = metadata.apply(lambda row: window_utils.polygon_to_crs(box(*eval(row.bounds)),row.crs,"EPSG:4326"),
axis=1)
metadata = gpd.GeoDataFrame(metadata,crs="EPSG:4326")
metadata = metadata.sort_values(["split","event id"])
metadata[["event id", "split", "s2_date","geometry"]].explore(column='split', cmap=['red','blue' ,'green'])
Show the dataset with the interactive viewer and edit the labels#
The ml4floods viewer and label editor is a Flask web application to view and manually edit the floodmaps of the WorldFloods dataset. This application is in the ml4floods GitHub package in the viewer
folder.
For launching the viewer, run in a terminal:
pip install flask ml4floods
git clone git@github.com:spaceml-org/ml4floods.git
cd ml4floods/viewer
python serve.py --root_location /path/to/localdir/WorldFloodsv2 --gt_version v2 --no_save_floodmap_bucket
Plot all test and validation images#
from ml4floods.visualization import plot_utils
import matplotlib.pyplot as plt
from georeader import plot
from georeader.rasterio_reader import RasterioReader
from ml4floods.data.worldfloods.configs import BANDS_S2, COLORS_WORLDFLOODS
s2_bands_read = ["B2","B3", "B4", "B8", "B11", "B12"]
s2_band_indexes = [BANDS_S2.index(b)+1 for b in s2_bands_read]
for record in metadata[metadata.split.isin(["test","val"])].to_dict(orient="records"):
s2_file = os.path.join(local_dir,record["split"],"S2",record["event id"]+".tif")
if not os.path.exists(s2_file):
print(f"ERROR: Record: {record['event id']} from {record['split']} split is not downloaded")
continue
rst = RasterioReader(s2_file,indexes=s2_band_indexes).load()
fig, ax = plt.subplots(1,3,figsize=(22,8))
plot.show((rst.isel({"band": [2,1,0]})/3_500).clip(0,1),ax=ax[0],add_scalebar=True,
title="RGB")
plot.show((rst.isel({"band": [4,3,2]})/3_500).clip(0,1),ax=ax[1], title="SWIR/NIR/RED")
gt_file = os.path.join(local_dir,record["split"],"gt",record["event id"]+".tif")
rst_gt = RasterioReader(gt_file).load()
v1gt = rst_gt.isel({"band": 1})
v1gt.values[rst_gt.values[0] == 2] = 3
plot.plot_segmentation_mask(v1gt, color_array=COLORS_WORLDFLOODS,
interpretation_array=plot_utils.INTERPRETATION_WORLDFLOODS,
ax=ax[2])
ax[2].set_title("GT")
s2split = s2_file.split("/")
title = f"{record['split']}/{record['event id']}"
plt.suptitle(title)
plt.show()
Licence#
The ML4Floods package is published under a GNU Lesser GPL v3 licence
The WorldFloods database and all pre-trained models are released under a Creative Commons non-commercial licence. For using the models in comercial pipelines written consent by the authors must be provided.
The Ml4Floods notebooks and docs are released under a Creative Commons non-commercial licence.
If you find this work useful please cite:
@article{portales-julia_global_2023,
title = {Global flood extent segmentation in optical satellite images},
volume = {13},
issn = {2045-2322},
doi = {10.1038/s41598-023-47595-7},
number = {1},
urldate = {2023-11-30},
journal = {Scientific Reports},
author = {Portalés-Julià, Enrique and Mateo-García, Gonzalo and Purcell, Cormac and Gómez-Chova, Luis},
month = nov,
year = {2023},
pages = {20316},
}