HANZE — API reference#
HANZE historical European flood-impacts data source subpackage — earthlens.hanze.
Background and usage are covered under the other pages in this section
(Introduction, Usage); this page is the rendered
API. HANZE needs no credentials — the Zenodo record is public (CC-BY-4.0).
earthlens.hanze
#
HANZE historical-flood-impacts backend.
Fetches the HANZE (Historical Analysis of Natural Hazards in Europe) database of
observed European flood events and their impacts (Paprotny et al.) from its
pinned static Zenodo release, and returns the event / impact records as a
:class:pandas.DataFrame. It is the observed hazard -> loss record: real floods
with fatalities, persons affected, area flooded and economic losses, against
which a modelled event set can be validated. Companion to the global emdat
backend.
This is a tabular backend by default: the result is a table of event / impact
rows, not a gridded array, so the :class:earthlens.earthlens.EarthLens facade
rejects an aggregate= argument. Passing with_geometry=True instead returns a
pyramids :class:~pyramids.feature.collection.FeatureCollection of the affected
NUTS-3 regions (a per-instance vector output).
HANZE needs no credentials — the Zenodo record is public (CC-BY-4.0) — so
there is no auth class and no [hanze] extra: the only dependencies (HttpClient,
pandas, base/archive, pyramids) are all core.
Public surface (re-exported from this package):
- :class:
HANZE— the backend; instantiate with a date range and optionalcountry=/region=/flood_type=filters, then call :meth:HANZE.download. - :class:
Catalog— loader for the bundledhanze_data_catalog.yaml. - :class:
ZenodoRecord/ :class:HanzeFile/ :class:FloodType/ :class:GeometryJoin— the catalog's frozen row models. - :func:
join_events_to_regions/ :func:empty_region_fc— the event -> region-geometry join and its empty-result counterpart. - :data:
CATALOG_PATH— path to the bundled catalog YAML; monkey-patchable in tests.
Examples:
-
List the flood-type vocabulary:
Catalog
#
Bases: AbstractCatalog
Catalog for the HANZE backend.
Reads the bundled hanze_data_catalog.yaml (shipped as package data) and
exposes the pinned Zenodo record, the per-file names, the flood-Type
vocabulary (as :class:FloodType rows keyed by type under the inherited
:attr:datasets field — the cat["River"] / "River" in cat / len(cat)
dict surface), the friendly-name -> CSV-header map, and the region-geometry
join configuration. Instantiate with no arguments (Catalog()).
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, FloodType]
|
Map from a flood- |
record |
ZenodoRecord | None
|
The pinned :class: |
files |
dict[str, HanzeFile]
|
Map from a logical key ( |
geometry |
GeometryJoin | None
|
The :class: |
columns |
dict[str, str]
|
Friendly name -> exact HANZE CSV header. |
Examples:
- List the flood types and resolve one, and read the pinned record:
- An unknown flood type raises with a did-you-mean hint:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
column(friendly)
#
Return the exact HANZE CSV header for a friendly column name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
friendly
|
str
|
A friendly key from the catalog's |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The exact CSV header ( |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
- Map friendly keys to their exact HANZE headers:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
file(key)
#
Return the :class:HanzeFile for a logical key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
HanzeFile |
HanzeFile
|
The matching file descriptor. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
- Resolve the events and region file names:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
flood_types()
#
Return the registered flood-Type strings, sorted.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The flood types
( |
Examples:
- The registered types come back sorted:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
get_catalog()
#
Return the flood-type map (satisfies the abstract contract).
Returns:
| Type | Description |
|---|---|
dict[str, FloodType]
|
dict[str, FloodType]: Same object as :attr: |
Examples:
- The flood-type map is keyed by the
Typestring:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
get_flood_type(flood_type)
#
Return the :class:FloodType for flood_type, with a did-you-mean hint.
Thin alias over :meth:~earthlens.base.AbstractCatalog.get_dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flood_type
|
str
|
A HANZE flood- |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FloodType |
FloodType
|
The matching row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Resolve a type and read its description:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
load(catalog_path=None)
classmethod
#
Read the HANZE catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the module-level
:data: |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Loading the bundled catalog yields the pinned record and types:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
FloodType
#
Bases: BaseModel
One entry of the HANZE flood-Type vocabulary.
The type string ("River", "River/Coastal") is the parent key in
:attr:Catalog.datasets and is not stored on the row.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
Short note on what the flood type covers. |
Examples:
- Build a row directly:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
GeometryJoin
#
Bases: BaseModel
The region-shapefile join configuration for with_geometry.
Attributes:
| Name | Type | Description |
|---|---|---|
member_stem |
str
|
The shapefile member stem inside the region zip
( |
join_field |
str
|
The shapefile attribute holding the NUTS-3 code ( |
name_field |
str
|
The shapefile attribute holding the region name ( |
crs |
str
|
The shapefile's stored CRS ( |
Examples:
- The join field and CRS are what the geometry attach reads:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
HANZE
#
Bases: AbstractDataSource
HANZE historical-flood-impacts backend (per-instance output kind).
Downloads the HANZE events / impacts table from its pinned Zenodo release,
filters it by country / region / flood type / date window, and returns a
:class:pandas.DataFrame. With with_geometry=True it instead returns a
:class:~pyramids.feature.collection.FeatureCollection of the affected
NUTS-3 regions.
The record is public (CC-BY-4.0); no credentials are needed.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Set per instance in :meth: |
REQUIRES_TIME_WINDOW |
|
Examples:
-
Pull DE + NL flood events, or the affected-region geometry, through the facade (both fetch from Zenodo, so this is illustrative, not a doctest):
from earthlens.core import EarthLens events = EarthLens( "hanze", start="1950", end="2020", country=["DE", "NL"] ).download() # a pandas.DataFrame of events + impacts regions = EarthLens( "hanze", start="1990", end="2020", country="DE", with_geometry=True ).download() # a FeatureCollection of the affected NUTS-3 regions
Source code in libs/providers/hazards/src/earthlens/hanze/backend.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
__init__(start=None, end=None, lat_lim=None, lon_lim=None, temporal_resolution='all', path=None, fmt='%Y-%m-%d', country=None, region=None, flood_type=None, with_geometry=False, timeout=120.0)
#
Initialise a HANZE backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str | None
|
Inclusive start of an optional window, parsed with |
None
|
end
|
str | None
|
Inclusive end of the optional window; |
None
|
lat_lim
|
list[float] | None
|
|
None
|
lon_lim
|
list[float] | None
|
|
None
|
temporal_resolution
|
str
|
HANZE issues one query over the whole window, so
this is the sentinel |
'all'
|
path
|
Path | str | None
|
Output directory for the cached source files and the written table / vector file. Created by the parent class if absent. |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
country
|
str | list[str] | None
|
One ISO2 country code or a list of them ( |
None
|
region
|
str | list[str] | None
|
One NUTS-3 code or a list of them ( |
None
|
flood_type
|
str | list[str] | None
|
One flood type or a list of them — any of |
None
|
with_geometry
|
bool
|
When |
False
|
timeout
|
float
|
Per-request timeout in seconds for the Zenodo downloads. |
120.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a |
Source code in libs/providers/hazards/src/earthlens/hanze/backend.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
download(progress_bar=True)
#
Fetch HANZE and return the per-instance shape.
Runs the download + filter, writes the result to path (a CSV for the
tabular default, a GeoPackage for with_geometry), and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Whether to draw a download progress bar. Passed through
to the transport, so |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame | FeatureCollection
|
class: |
DataFrame | FeatureCollection
|
class: |
|
DataFrame | FeatureCollection
|
affected NUTS-3 regions ( |
|
DataFrame | FeatureCollection
|
under |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If a Zenodo download returns a non-2xx status. |
ValueError
|
If a download's body fails its content guard (an HTML
error page served with a 200 status), or |
Source code in libs/providers/hazards/src/earthlens/hanze/backend.py
HanzeFile
#
Bases: BaseModel
One downloadable Zenodo object of the pinned HANZE record.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The file name on the record. |
description |
str
|
One-line human-readable summary. |
Examples:
- The content URL is composed from the pinned record and file name:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
content_url(record)
#
Return the Zenodo REST content URL this file is served from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
int
|
The pinned version record id the file belongs to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
|
Examples:
- Compose the REST content URL for a file on a record:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
ZenodoRecord
#
Bases: BaseModel
The pinned Zenodo version record HANZE is fetched from.
Attributes:
| Name | Type | Description |
|---|---|---|
record |
int
|
The pinned Zenodo version record id ( |
concept_doi |
str
|
The moving concept DOI. Recorded so a refresh check can discover a newer version; never used to fetch. |
version |
str
|
The dataset version ( |
data_period |
str
|
The |
license |
str
|
SPDX-ish licence id ( |
attribution |
str
|
The citation obligation the licence carries. |
Examples:
- The record is the pinned version, not the concept DOI:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
empty_region_fc()
#
Return an empty region FeatureCollection with the canonical schema.
Used when the filtered events reference no region present in the boundary file, so callers always get the same columns / dtypes back regardless of hit count.
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
Zero rows, the :data: |
Examples:
- The schema is present even with no rows:
Source code in libs/providers/hazards/src/earthlens/hanze/geometry.py
join_events_to_regions(events, regions, *, regions_column, join_field, name_field)
#
Join filtered events to their affected NUTS-3 region polygons.
Splits each event's Regions affected (NUTS 3) list, counts the events per
region, selects the boundary polygons whose join_field is among the
affected codes, reprojects them to WGS84, and returns one feature per
affected region carrying its code, name and event count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
The filtered events table. |
required |
regions
|
FeatureCollection
|
The NUTS-3 boundary polygons, in the shapefile's stored CRS
( |
required |
regions_column
|
str
|
The events column holding the semicolon-separated NUTS-3
code list ( |
required |
join_field
|
str
|
The boundary attribute holding the NUTS-3 code ( |
required |
name_field
|
str
|
The boundary attribute holding the region name ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
One polygon per affected region, columns
|
Examples:
- Join two events to their affected region polygons and read the counts:
>>> import geopandas as gpd >>> import pandas as pd >>> from shapely.geometry import box >>> from earthlens.hanze.geometry import join_events_to_regions >>> regions = gpd.GeoDataFrame( ... {"Code": ["DE300", "NL414"], "Name": ["Berlin", "Zuidoost"]}, ... geometry=[box(13, 52, 14, 53), box(5, 51, 6, 52)], ... crs="EPSG:4326", ... ) >>> events = pd.DataFrame({"regions": ["DE300;NL414", "DE300"]}) >>> fc = join_events_to_regions( ... events, regions, regions_column="regions", ... join_field="Code", name_field="Name", ... ) >>> dict(zip(fc["nuts3_code"], fc["n_events"])) {'DE300': 2, 'NL414': 1} >>> fc.crs.to_epsg() 4326
Source code in libs/providers/hazards/src/earthlens/hanze/geometry.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
earthlens.hanze.backend
#
Backend that fetches HANZE historical European flood events and impacts.
HANZE(AbstractDataSource) downloads the HANZE (Historical Analysis of Natural
Hazards in Europe) database of observed European flood events and their impacts
(Paprotny et al.) from its pinned static Zenodo release, filters it, and returns
the event / impact records as a :class:pandas.DataFrame. It is the observed
hazard -> loss record — real floods with fatalities, persons affected, area
flooded and economic losses — so a modelled event set can be validated against
the observed loss distribution. Companion to the global emdat backend.
Three design points carry this backend:
- Per-instance
OUTPUT_KIND. The default istabular, returning a :class:pandas.DataFrameof events + impacts. Passingwith_geometry=Truemakes the instancevector: it additionally downloads the NUTS-3 region boundary shapefile and returns a pyramids :class:~pyramids.feature.collection.FeatureCollectionof the affected regions (theemdat/eumetsatper-instance pattern). The facade reads the instance attribute to know the return shape and to gateaggregate=. - Direct file download, not range-read. HANZE ships small individual Zenodo
objects (a 618 KB events CSV, a 2.4 MB region zip), so each is fetched whole
with :class:
~earthlens.base.http.HttpClientand cached underpath— none of caravan's multi-GB range-read machinery applies. - No new dependency.
HttpClient+ pandas +base/archive+ pyramids are all core, and the Zenodo record is public (CC-BY-4.0), so there is no auth and no[hanze]extra.
These are event records, not gridded rasters, so aggregate= is refused and
nothing here imports a gridded-array library (no xarray).
HANZE
#
Bases: AbstractDataSource
HANZE historical-flood-impacts backend (per-instance output kind).
Downloads the HANZE events / impacts table from its pinned Zenodo release,
filters it by country / region / flood type / date window, and returns a
:class:pandas.DataFrame. With with_geometry=True it instead returns a
:class:~pyramids.feature.collection.FeatureCollection of the affected
NUTS-3 regions.
The record is public (CC-BY-4.0); no credentials are needed.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Set per instance in :meth: |
REQUIRES_TIME_WINDOW |
|
Examples:
-
Pull DE + NL flood events, or the affected-region geometry, through the facade (both fetch from Zenodo, so this is illustrative, not a doctest):
from earthlens.core import EarthLens events = EarthLens( "hanze", start="1950", end="2020", country=["DE", "NL"] ).download() # a pandas.DataFrame of events + impacts regions = EarthLens( "hanze", start="1990", end="2020", country="DE", with_geometry=True ).download() # a FeatureCollection of the affected NUTS-3 regions
Source code in libs/providers/hazards/src/earthlens/hanze/backend.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
__init__(start=None, end=None, lat_lim=None, lon_lim=None, temporal_resolution='all', path=None, fmt='%Y-%m-%d', country=None, region=None, flood_type=None, with_geometry=False, timeout=120.0)
#
Initialise a HANZE backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str | None
|
Inclusive start of an optional window, parsed with |
None
|
end
|
str | None
|
Inclusive end of the optional window; |
None
|
lat_lim
|
list[float] | None
|
|
None
|
lon_lim
|
list[float] | None
|
|
None
|
temporal_resolution
|
str
|
HANZE issues one query over the whole window, so
this is the sentinel |
'all'
|
path
|
Path | str | None
|
Output directory for the cached source files and the written table / vector file. Created by the parent class if absent. |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
country
|
str | list[str] | None
|
One ISO2 country code or a list of them ( |
None
|
region
|
str | list[str] | None
|
One NUTS-3 code or a list of them ( |
None
|
flood_type
|
str | list[str] | None
|
One flood type or a list of them — any of |
None
|
with_geometry
|
bool
|
When |
False
|
timeout
|
float
|
Per-request timeout in seconds for the Zenodo downloads. |
120.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a |
Source code in libs/providers/hazards/src/earthlens/hanze/backend.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
download(progress_bar=True)
#
Fetch HANZE and return the per-instance shape.
Runs the download + filter, writes the result to path (a CSV for the
tabular default, a GeoPackage for with_geometry), and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Whether to draw a download progress bar. Passed through
to the transport, so |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame | FeatureCollection
|
class: |
DataFrame | FeatureCollection
|
class: |
|
DataFrame | FeatureCollection
|
affected NUTS-3 regions ( |
|
DataFrame | FeatureCollection
|
under |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If a Zenodo download returns a non-2xx status. |
ValueError
|
If a download's body fails its content guard (an HTML
error page served with a 200 status), or |
Source code in libs/providers/hazards/src/earthlens/hanze/backend.py
earthlens.hanze.catalog
#
Catalog for the HANZE historical-flood-impacts backend.
HANZE is a single tabular product — the database of observed European flood
events and their impacts (Paprotny et al.) — published as individual small files
on a pinned Zenodo version record. This module is the bridge between the
friendly request vocabulary (type="River", country="DE") and what the
release actually ships: the pinned record, the per-file names, the flood-type
vocabulary, the friendly-name -> CSV-header map, and the region-geometry join
configuration.
Four shapes are modelled, all frozen:
- :class:
ZenodoRecord— the pinned version record, its concept DOI,version,data_period, licence and attribution. Pinning a version rather than the moving concept DOI is what makes a request reproducible. - :class:
HanzeFile— one downloadable Zenodo object (its name, and the REST contenturlcomposed from the pinned record). HANZE ships small individual files, so each is a direct download, never a range-read. - :class:
FloodType— one row of theTypevocabulary (River,Flash,Coastal,River/Coastal). These are the catalog's dict-surface rows, keyed by type under the inherited :attr:datasetsfield. - :class:
GeometryJoin— the region-shapefile join: its member stem, the join field (Code), the name field, and the shapefile CRS (EPSG:3035).
:class:Catalog is a thin :class:earthlens.base.AbstractCatalog subclass that
loads the bundled hanze_data_catalog.yaml through the shared
:func:~earthlens.base.catalog_source.load_catalog (with a CatalogParseCache),
mirroring gdacs/catalog.py. :data:CATALOG_PATH is the path to the bundled
YAML and is monkey-patchable in tests.
Catalog
#
Bases: AbstractCatalog
Catalog for the HANZE backend.
Reads the bundled hanze_data_catalog.yaml (shipped as package data) and
exposes the pinned Zenodo record, the per-file names, the flood-Type
vocabulary (as :class:FloodType rows keyed by type under the inherited
:attr:datasets field — the cat["River"] / "River" in cat / len(cat)
dict surface), the friendly-name -> CSV-header map, and the region-geometry
join configuration. Instantiate with no arguments (Catalog()).
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, FloodType]
|
Map from a flood- |
record |
ZenodoRecord | None
|
The pinned :class: |
files |
dict[str, HanzeFile]
|
Map from a logical key ( |
geometry |
GeometryJoin | None
|
The :class: |
columns |
dict[str, str]
|
Friendly name -> exact HANZE CSV header. |
Examples:
- List the flood types and resolve one, and read the pinned record:
- An unknown flood type raises with a did-you-mean hint:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
column(friendly)
#
Return the exact HANZE CSV header for a friendly column name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
friendly
|
str
|
A friendly key from the catalog's |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The exact CSV header ( |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
- Map friendly keys to their exact HANZE headers:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
file(key)
#
Return the :class:HanzeFile for a logical key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
HanzeFile |
HanzeFile
|
The matching file descriptor. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
- Resolve the events and region file names:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
flood_types()
#
Return the registered flood-Type strings, sorted.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The flood types
( |
Examples:
- The registered types come back sorted:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
get_catalog()
#
Return the flood-type map (satisfies the abstract contract).
Returns:
| Type | Description |
|---|---|
dict[str, FloodType]
|
dict[str, FloodType]: Same object as :attr: |
Examples:
- The flood-type map is keyed by the
Typestring:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
get_flood_type(flood_type)
#
Return the :class:FloodType for flood_type, with a did-you-mean hint.
Thin alias over :meth:~earthlens.base.AbstractCatalog.get_dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flood_type
|
str
|
A HANZE flood- |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FloodType |
FloodType
|
The matching row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Resolve a type and read its description:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
load(catalog_path=None)
classmethod
#
Read the HANZE catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the module-level
:data: |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Loading the bundled catalog yields the pinned record and types:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
FloodType
#
Bases: BaseModel
One entry of the HANZE flood-Type vocabulary.
The type string ("River", "River/Coastal") is the parent key in
:attr:Catalog.datasets and is not stored on the row.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
Short note on what the flood type covers. |
Examples:
- Build a row directly:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
GeometryJoin
#
Bases: BaseModel
The region-shapefile join configuration for with_geometry.
Attributes:
| Name | Type | Description |
|---|---|---|
member_stem |
str
|
The shapefile member stem inside the region zip
( |
join_field |
str
|
The shapefile attribute holding the NUTS-3 code ( |
name_field |
str
|
The shapefile attribute holding the region name ( |
crs |
str
|
The shapefile's stored CRS ( |
Examples:
- The join field and CRS are what the geometry attach reads:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
HanzeFile
#
Bases: BaseModel
One downloadable Zenodo object of the pinned HANZE record.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The file name on the record. |
description |
str
|
One-line human-readable summary. |
Examples:
- The content URL is composed from the pinned record and file name:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
content_url(record)
#
Return the Zenodo REST content URL this file is served from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
int
|
The pinned version record id the file belongs to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
|
Examples:
- Compose the REST content URL for a file on a record:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
ZenodoRecord
#
Bases: BaseModel
The pinned Zenodo version record HANZE is fetched from.
Attributes:
| Name | Type | Description |
|---|---|---|
record |
int
|
The pinned Zenodo version record id ( |
concept_doi |
str
|
The moving concept DOI. Recorded so a refresh check can discover a newer version; never used to fetch. |
version |
str
|
The dataset version ( |
data_period |
str
|
The |
license |
str
|
SPDX-ish licence id ( |
attribution |
str
|
The citation obligation the licence carries. |
Examples:
- The record is the pinned version, not the concept DOI:
Source code in libs/providers/hazards/src/earthlens/hanze/catalog.py
earthlens.hanze.geometry
#
Attach affected-region geometry to HANZE flood events.
This module is the only place in the HANZE backend that touches a GIS vector
container, so per the pyramids policy it keeps all geometry / CRS handling inside
pyramids primitives. Each HANZE event names the NUTS-3 regions it affected as a
semicolon-separated code list in the Regions affected (NUTS 3) column; this
module splits that list, counts how many of the (already-filtered) events touch
each region, joins those codes to the NUTS-3 boundary polygons on the shapefile's
Code field, reprojects the result from the shapefile's stored ETRS89-LAEA CRS
(EPSG:3035) to WGS84, and returns a pyramids
:class:~pyramids.feature.collection.FeatureCollection of one polygon per
affected region.
The output schema is the same on the populated path (:func:join_events_to_regions)
and the empty path (:func:empty_region_fc) — nuts3_code, region_name,
n_events, and geometry — so a downstream to_file never chokes on a schema
mismatch between a hit and a miss.
Because HANZE's impact figures (fatalities, losses) are per event national /
multi-region totals rather than per-region values, they are deliberately not
summed onto the regions — doing so would double-count. The one honest per-region
metric is n_events, the number of the filtered events that affected each
region, which is what a choropleth map should show.
empty_region_fc()
#
Return an empty region FeatureCollection with the canonical schema.
Used when the filtered events reference no region present in the boundary file, so callers always get the same columns / dtypes back regardless of hit count.
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
Zero rows, the :data: |
Examples:
- The schema is present even with no rows:
Source code in libs/providers/hazards/src/earthlens/hanze/geometry.py
event_region_counts(events, regions_column)
#
Count how many events affect each NUTS-3 region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
The filtered events table. |
required |
regions_column
|
str
|
The column holding the semicolon-separated NUTS-3 code
list ( |
required |
Returns:
| Type | Description |
|---|---|
Counter[str]
|
Counter[str]: NUTS-3 code -> number of events referencing it. Each code is counted at most once per event, even if it appears twice in that event's list. |
Examples:
- Two events over three regions, counted per code (case-normalised):
Source code in libs/providers/hazards/src/earthlens/hanze/geometry.py
join_events_to_regions(events, regions, *, regions_column, join_field, name_field)
#
Join filtered events to their affected NUTS-3 region polygons.
Splits each event's Regions affected (NUTS 3) list, counts the events per
region, selects the boundary polygons whose join_field is among the
affected codes, reprojects them to WGS84, and returns one feature per
affected region carrying its code, name and event count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
The filtered events table. |
required |
regions
|
FeatureCollection
|
The NUTS-3 boundary polygons, in the shapefile's stored CRS
( |
required |
regions_column
|
str
|
The events column holding the semicolon-separated NUTS-3
code list ( |
required |
join_field
|
str
|
The boundary attribute holding the NUTS-3 code ( |
required |
name_field
|
str
|
The boundary attribute holding the region name ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
One polygon per affected region, columns
|
Examples:
- Join two events to their affected region polygons and read the counts:
>>> import geopandas as gpd >>> import pandas as pd >>> from shapely.geometry import box >>> from earthlens.hanze.geometry import join_events_to_regions >>> regions = gpd.GeoDataFrame( ... {"Code": ["DE300", "NL414"], "Name": ["Berlin", "Zuidoost"]}, ... geometry=[box(13, 52, 14, 53), box(5, 51, 6, 52)], ... crs="EPSG:4326", ... ) >>> events = pd.DataFrame({"regions": ["DE300;NL414", "DE300"]}) >>> fc = join_events_to_regions( ... events, regions, regions_column="regions", ... join_field="Code", name_field="Name", ... ) >>> dict(zip(fc["nuts3_code"], fc["n_events"])) {'DE300': 2, 'NL414': 1} >>> fc.crs.to_epsg() 4326
Source code in libs/providers/hazards/src/earthlens/hanze/geometry.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
split_nuts3(value)
#
Split one Regions affected (NUTS 3) cell into NUTS-3 codes.
The cell is a semicolon-separated list ("AL011;AL012;AL013"); surrounding
whitespace and empty segments are dropped. A missing / non-string cell
yields an empty list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
One cell of the |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The NUTS-3 codes, in order, with blanks removed. |
Examples:
- A semicolon list splits into its codes; a blank cell yields nothing: