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 the local-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'])
Make this Notebook Trusted to load map: File -> Trust Notebook

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

viewer.png

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()
../../_images/d29468c5d5deff64baf30627810d491c6f6696905a166cafdf744509f6d23beb.png ../../_images/33dd709ff32a68a761f1797a8d34521d2eb6bd5a5373936b0ee8e9305eca3533.png ../../_images/ddd4fb6ee7c23ca6392b4b1dee04e2e891de2cefe3988045f9e6cf908a1487f1.png ../../_images/d26f81652ba3a79a3874771f18f77cc7ff55ee1c4cd3aefe3def79d92f39b40e.png ../../_images/ad278a040730e5fdb93499f9fd3b6b0670a0bd09085fd79cf7c97f00da9e1345.png ../../_images/b74c0e19765cca0a14b4f8d7a946daaa1bd3c6685a75533ef4e1351b003fe584.png ../../_images/b2461da713bb4f2798e7abbc7241604a34b04a6efb76ac302501cab73395d1cb.png ../../_images/48bb511bd880a60a6ff6224799135c970cd96a22aa764d4e9367a40784845771.png ../../_images/c6f84377e581913ea2dc5053da6aa46e38fb57b02224af22617ac8d031f4a335.png ../../_images/c9d3325f287c99b81594b5f07352970d5cd956b705983cdedc64096d4abb5341.png ../../_images/185d0d39de5326c11cc4d4db718fd1b6a1e6035872709ccdb76db33d87e0fd00.png ../../_images/b1671562387c2f2426dab15e694f6f483f8b1fb0949ea58467d8c98ee475d83a.png ../../_images/43fa0e0b0ee8169ab7c02f937db8b464375e2c831bfc5ac25d130a5b8db48706.png ../../_images/df473b4a857a47f76278629d5cfe51201080de7d31569d63c312da6afd209c7d.png ../../_images/bb33024b2f6c9a01cafb190d3f48679011a2c68e4e375b9a25b3a893f14c519b.png ../../_images/d93363fe458e3572178f3986c9d946571c08f750d18c8b7a8e28aa591a70b9b3.png ../../_images/cb114fd78ba3b7d11517343aafea6ea1bbdef635a4ab87ef1037054d54d8cf18.png ../../_images/c8fb9f7c31f05445e2a5426ddad27bf3762a41b21c249089166409a865689a5b.png ../../_images/bb142528ac8b9fe00070fa350a3b48a3224f327afed66166cda4ac8cb70846a9.png ../../_images/398c17377c49e102e94726ecfc4eefc57968b5eb8bb3e2e88847d56d97507911.png ../../_images/15fdc74c5543a3f54bd32200886abe4b0f979887f93d1c6f481cff167e171a21.png ../../_images/48ee9237239e9e22225755d0b807e3842900f0dd5a8ef26011c306adc4804ec5.png ../../_images/66fae0416499d241e11bfdfb7c4655cd8fb2139663814172b0c897d13493875b.png ../../_images/925ecf1b44d70b9bc68d989b059fa60bd63e1b6d7a3cc9e01d82acaf9e4179b5.png ../../_images/74a4216c51ce3aa117d8427dfa69923edf72fc03138bc2cbe2fba19752411fe0.png ../../_images/5b1dc0444165213cb16e34af7d1b17501b1e74be07d426d9a342b0e918a7b3b5.png ../../_images/70b72ea1aff711120285d8ddb049da396dad4a3027d0986d7f83bd2831c0d553.png ../../_images/a790ff16552520ba6f704096e35cae98be646e1ee0ffe1bfe602169ffc308a52.png ../../_images/2fbc6aa25939a47ee84624c6d340d26068fb2f7d2dcce51a17d36b8ea7849a93.png ../../_images/c4a25451ec6af1355ee3fd3ba056814bdba549689b86d3ab513320b66048a692.png ../../_images/c5c6690a991e511893ff92e79396359cc8e4af683a0ded4bddb47ac012133ebf.png ../../_images/bcd6fe3835a68f1720ed6393bc3e7d832a3fb936bc91dc9d219130c6e973d531.png ../../_images/eeb1d5038a5027c224e62118da0b7291047ff21682944df280dada0882b63c06.png ../../_images/d9890150455296cfa4d176788984515c1aad5d38d61ccb1b1eaf32a185c60e25.png

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},
}