Skip to content
Open
Changes from 1 commit
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
93e924f
initial commit CAT Bonds
KaiOBerg Oct 31, 2025
f502208
change subarea building to resolution input
KaiOBerg Nov 3, 2025
2c23ff5
alter subarea creation test notebook
KaiOBerg Nov 3, 2025
3e9457e
take crs from exposure
KaiOBerg Nov 7, 2025
efe9a75
dont save exp_gdf and adjust plotting
KaiOBerg Nov 7, 2025
cbd9b94
add buffer to create subareas
KaiOBerg Nov 7, 2025
716d3a0
streamline calculations
KaiOBerg Nov 7, 2025
96c26c4
change calculation of attachment and prinipal
KaiOBerg Nov 7, 2025
cc4fdee
keep only grids with exposure point within
KaiOBerg Nov 7, 2025
16caea0
fix bugs
KaiOBerg Nov 7, 2025
6533b49
adjust calc savings
KaiOBerg Nov 7, 2025
bf54f9b
adjust test notebook to changed classes
KaiOBerg Nov 7, 2025
688027d
inititate bond simulation class
KaiOBerg Nov 7, 2025
0a35b87
delete pay_dam_subarea class
KaiOBerg Nov 7, 2025
519dcb4
update function descriptions
KaiOBerg Nov 7, 2025
8a2accf
fix bugs
KaiOBerg Nov 7, 2025
08bd04e
add total payout and damage
KaiOBerg Nov 7, 2025
3d59693
update function description
KaiOBerg Nov 7, 2025
edf6598
add net cash flow and premium simulation
KaiOBerg Nov 7, 2025
2388d7c
adjust metric naming
KaiOBerg Nov 7, 2025
7db291c
update test to classes
KaiOBerg Nov 7, 2025
f9c6cab
change function naming
KaiOBerg Nov 7, 2025
1168e62
inititate premium class
KaiOBerg Nov 7, 2025
8ef65cb
add IBRD CAT bonds data file
KaiOBerg Nov 7, 2025
6d30ad7
add ibrd based premium calculation
KaiOBerg Nov 7, 2025
fc3edc8
improve logging and fix bug chatoro
KaiOBerg Nov 7, 2025
c7d1134
fix path to data dir
KaiOBerg Nov 7, 2025
6bf627e
remove premium input
KaiOBerg Nov 7, 2025
c93b862
adjust test notebook to classes
KaiOBerg Nov 7, 2025
b820b8c
add benchmark premium calculation
KaiOBerg Nov 7, 2025
ce9952c
include all premium methods in test notebook
KaiOBerg Nov 7, 2025
0d5fbcd
remove buffer grid size
KaiOBerg Nov 7, 2025
82d185d
define variables
KaiOBerg Nov 7, 2025
d6a494c
rename bond_simulation to sng_bond_simulation
KaiOBerg Nov 7, 2025
7322e02
initialize multi country bond simulation
KaiOBerg Nov 7, 2025
d6250ff
add function to derive VaR and ES
KaiOBerg Nov 7, 2025
ac4c317
add jamaica bond
KaiOBerg Nov 9, 2025
c4d2d99
fix bugs exp and haz jamaica
KaiOBerg Nov 9, 2025
78e8b8e
test multi-country bond in notebook
KaiOBerg Nov 9, 2025
4b9c735
add minimum simulation year
KaiOBerg Nov 9, 2025
a440927
Update climada_petals/engine/cat_bonds/mlt_bond_simulation.py
KaiOBerg Nov 16, 2025
616bf60
make init loss more pythonic
KaiOBerg Nov 16, 2025
d50ceb5
change var es function
KaiOBerg Nov 16, 2025
ac20d79
adjust test notebook for confidence intervals
KaiOBerg Nov 16, 2025
50ac5ef
remove nested loop from bond simulation
KaiOBerg Nov 17, 2025
da53e8a
change fucntion description
KaiOBerg Nov 17, 2025
c02d1eb
fix type of single events in df_loss_month
KaiOBerg Nov 21, 2025
7c6458b
adjust to chanings in sng_simulation
KaiOBerg Nov 21, 2025
ad92d39
implement return simulation mlt bonds
KaiOBerg Nov 21, 2025
9c5ca13
rename funciton names
KaiOBerg Nov 21, 2025
0e95f18
init function to calculate returns with trances
KaiOBerg Nov 21, 2025
805bbe1
add required principal calculation
KaiOBerg Nov 21, 2025
d692bea
save required principal to mlt_bond class
KaiOBerg Nov 21, 2025
05a88ee
rename functions
KaiOBerg Nov 21, 2025
61802b5
make bond term function private
KaiOBerg Nov 21, 2025
2b3484b
adapt changes in mlt class to test notebook
KaiOBerg Nov 21, 2025
1d5897d
fix min year in requ_principal and initialze min_year at class init
KaiOBerg Nov 21, 2025
499bf97
add function for overlapping subareas
KaiOBerg Nov 21, 2025
0fef13e
add belize
KaiOBerg Nov 21, 2025
a53e32e
make build_subareas optional
KaiOBerg Nov 21, 2025
0b09fe5
minor adjustments
KaiOBerg Nov 21, 2025
6051337
rename class names
KaiOBerg Nov 21, 2025
d2ec6c4
initialize pooling optimization problems
KaiOBerg Nov 21, 2025
edfb591
add function to derive optimal fixed pools
KaiOBerg Nov 21, 2025
7efc9a2
move allocate tranche payout to utils
KaiOBerg Nov 24, 2025
5a29cc3
rename test notebook to tutorial
KaiOBerg Nov 24, 2025
58bf8e1
move tutorial
KaiOBerg Nov 27, 2025
9166134
initialize subareas with resolution
KaiOBerg Nov 27, 2025
e5d2d47
initiate subareas by resolution
KaiOBerg Nov 27, 2025
5abe3c1
implement pooling n pools
KaiOBerg Nov 27, 2025
d8f70a0
initialise class with optimized n pools
KaiOBerg Nov 28, 2025
fc1a62f
rename n to n_pools
KaiOBerg Nov 28, 2025
7186418
rename fct process_n to process_n_pools
KaiOBerg Nov 28, 2025
62e4808
add maximum principal wrapper function
KaiOBerg Nov 28, 2025
f5c774b
fix iterration bug
KaiOBerg Nov 28, 2025
5e14044
return whole dictionary conatining multiple class instances
KaiOBerg Nov 28, 2025
b311758
add logging to simulate_bond_pool_n
KaiOBerg Nov 28, 2025
b262e71
add max_principal pooling optimization function
KaiOBerg Nov 28, 2025
4dbea02
adapt to changes in mlt_cty_bond
KaiOBerg Nov 28, 2025
20b08fa
update funciton descriptions
KaiOBerg Nov 28, 2025
c486f9c
comment tutorial script
KaiOBerg Nov 28, 2025
ad94804
change inital guess values to percentiles of hazard intensity
KaiOBerg Nov 28, 2025
df09dd3
implement option to plug in manuall init guess
KaiOBerg Nov 28, 2025
a84e767
add function to initialize subarea class with a gdf
KaiOBerg Nov 28, 2025
d422c83
update function description
KaiOBerg Nov 28, 2025
9c4a252
move turotial to docs and create init
KaiOBerg Nov 28, 2025
e9078d4
fix file paths
KaiOBerg Nov 28, 2025
f30d74b
move explode into exp_gdf function
KaiOBerg Nov 28, 2025
fa871c8
initialize subaarea unit tests
KaiOBerg Nov 28, 2025
16ce43d
remove padding of exposure resolution
KaiOBerg Nov 28, 2025
d784b82
add 1.2 padding to exposure resolution
KaiOBerg Nov 28, 2025
b7e95b4
add testing of merging polygons
KaiOBerg Nov 28, 2025
c1f5d4d
add more test cases to merging polyons
KaiOBerg Nov 28, 2025
70cd21d
fromatting
KaiOBerg Dec 1, 2025
e5d515a
init test subarea_calculations
KaiOBerg Dec 1, 2025
9635151
clearify variable origin
KaiOBerg Dec 1, 2025
b353942
fix bug
KaiOBerg Dec 1, 2025
f2e8f90
add pay_vs_dam test function
KaiOBerg Dec 1, 2025
cd7432a
add test objective_function
KaiOBerg Dec 1, 2025
b264001
initiate test script for single country bonds
KaiOBerg Dec 1, 2025
56bee84
fix loop bug and remove simulated years
KaiOBerg Dec 1, 2025
5de50d6
test simulate loss
KaiOBerg Dec 1, 2025
a7305bd
finish tests for single country bonds
KaiOBerg Dec 1, 2025
f7aae42
formatting
KaiOBerg Dec 1, 2025
76b10bc
adjust descriptions
KaiOBerg Dec 1, 2025
f53bc2e
initialize test for premium calculations
KaiOBerg Dec 1, 2025
bcd29f7
format
KaiOBerg Dec 1, 2025
e63caaa
test benchmark sharpe ration function
KaiOBerg Dec 1, 2025
b8b65f1
formatting
KaiOBerg Dec 1, 2025
9434653
update function description
KaiOBerg Dec 1, 2025
bd5b76d
test multi_level_es function
KaiOBerg Dec 1, 2025
a3ca2a0
formatting
KaiOBerg Dec 1, 2025
64c233c
update logging to petals LOGGER
KaiOBerg Dec 12, 2025
301b485
restructure tests
KaiOBerg Dec 12, 2025
d857f33
changed structure of tests
KaiOBerg Dec 12, 2025
675f460
change structure of tests
KaiOBerg Dec 12, 2025
c8c5e24
adjust test structure
KaiOBerg Dec 12, 2025
8eaa0c0
change test structure
KaiOBerg Dec 12, 2025
da8d4c4
remove bug of missing last term
KaiOBerg Dec 12, 2025
c24c18e
fix bug of starting year
KaiOBerg Dec 12, 2025
ef05eae
test multi country cat bond class
KaiOBerg Dec 12, 2025
43dc34e
ensure valid results
KaiOBerg Dec 15, 2025
007155d
get country location even if risk concentration does not improve
KaiOBerg Dec 15, 2025
819677e
finsih mlt_bond_class tests
KaiOBerg Dec 15, 2025
e9917d7
remove unnecessary packages
KaiOBerg Dec 15, 2025
cdd99cd
reomve logging
KaiOBerg Jan 5, 2026
64830e7
remove unnecessary impf_set lines
KaiOBerg Jan 5, 2026
b7245ec
finish doc strings
KaiOBerg Jan 5, 2026
56998ec
finish doc strings and parameter types for premium_class
KaiOBerg Jan 5, 2026
305cc8c
add types to init
KaiOBerg Jan 5, 2026
ea3bb7e
finsih doc strings
KaiOBerg Jan 5, 2026
51be90f
finish doc strings for subarea_calculations
KaiOBerg Jan 5, 2026
ba0e777
finsih docstrings for subareas
KaiOBerg Jan 5, 2026
20f454f
finsih doc strings for utils
KaiOBerg Jan 5, 2026
dbaafb0
ensure cur_nominal is array
KaiOBerg Jan 5, 2026
051873f
add minimalistic doc strings
KaiOBerg Jan 5, 2026
1655f03
finalize testin script for premium class
KaiOBerg Jan 5, 2026
b921ec4
add test for monoexp
KaiOBerg Jan 5, 2026
2081797
add edge case for same month events and doc stings
KaiOBerg Jan 5, 2026
cef1d2f
test create_pay_vs_dam and _calc_impact and add doc stings
KaiOBerg Jan 5, 2026
3e7549b
fix naming inconsistencies
KaiOBerg Jan 5, 2026
a2c08cf
add test functions for from_resolution and from_geodataframe and doc …
KaiOBerg Jan 5, 2026
70b1425
add doc strings to test script for utils in cat_bonds
KaiOBerg Jan 5, 2026
5fffab7
remove ElementwiseProblem inheritance
KaiOBerg Jan 10, 2026
56ecb4a
initiate test function for pooling
KaiOBerg Jan 12, 2026
dbd66bb
clean up pooling_functions.py
KaiOBerg Jan 12, 2026
7d3c8af
add principal calculation to class methods
KaiOBerg Jan 12, 2026
8c2eb95
remove not necessary logging messages
KaiOBerg Jan 12, 2026
abeb227
update docstrings
KaiOBerg Jan 12, 2026
f1ad7f5
raise error if tranches share of principal does not equal 1
KaiOBerg Jan 12, 2026
1d8f207
insert comments and descriptions; add single-country vs multi-country…
KaiOBerg Jan 12, 2026
56e424c
small fixes
KaiOBerg Jan 14, 2026
5526149
review docstrings
KaiOBerg Jan 19, 2026
83ba37a
improve naming convettions and add comments for better clarity
KaiOBerg Jan 19, 2026
b559945
last bug fixes and renaming
KaiOBerg Jan 27, 2026
a3f0431
Add pymoo dependency
Feb 24, 2026
27b434f
Correct typo
Feb 24, 2026
eeb5274
create helper script to derive tc hazard data sets and wildfire hazar…
KaiOBerg Mar 24, 2026
80c2043
replace hazard and exposure calculation by external helper functions;…
KaiOBerg Mar 24, 2026
9429537
Merge branch 'feature/cat_bonds' of https://github.com/CLIMADA-projec…
KaiOBerg Mar 24, 2026
065741e
Refactor bond simulation classes to include start_year parameter for …
KaiOBerg Apr 10, 2026
e32bfb3
Replace date extraction with fromordinal method for improved date han…
KaiOBerg Apr 10, 2026
e71261b
add earthquake bond; get hazard and exposure from climada data api; i…
KaiOBerg Apr 10, 2026
1408ae3
Refactor create_hazards.py: comment out unused functions, add dummy e…
KaiOBerg Apr 10, 2026
acee5ab
Add start_year parameter to SingleCountryBondSimulation in tests
KaiOBerg Apr 11, 2026
bbe1fc8
Add short-circuit for single pool case in process_n_pools function to…
KaiOBerg Apr 11, 2026
cff4443
Fix Sharpe ratio calculation to handle division by zero in multi-coun…
KaiOBerg Apr 11, 2026
6e3fbab
Update MultiCountryBond tests to include start_year parameter for con…
KaiOBerg Apr 11, 2026
0192d08
Add IBRD bonds data as CSV and remove outdated Excel file
KaiOBerg Apr 11, 2026
f1c7a16
Update IBRD bonds data loading to use CSV format instead of Excel
KaiOBerg Apr 11, 2026
b5bc0dd
Refactor calibration test to use more hazard data points for payout f…
KaiOBerg Apr 11, 2026
75ad2a1
assign regional impact function to exposure
KaiOBerg Apr 12, 2026
b05c69e
Add fallback thresholds calculation and tests for optimization failur…
KaiOBerg Apr 17, 2026
313312b
Merge branch 'develop' into feature/cat_bonds
Apr 30, 2026
c0707c9
Add catbond tutorial to toc
Apr 30, 2026
9d8ed09
Update Changelog with NatCatBond.
Apr 30, 2026
7e871b0
Enhance warning message for optimization failures in SubareaCalculati…
KaiOBerg May 1, 2026
83d5aa6
Fix comments and update expected values in payout calculations for cl…
KaiOBerg May 1, 2026
1c9c003
Remove unnecessary logging statements in process_n_pools for cleaner …
KaiOBerg May 1, 2026
3fa351d
Refactor logging in Subareas class
KaiOBerg May 1, 2026
b719dc3
Optimize subarea calculations with vectorization for index_stat
KaiOBerg May 1, 2026
04bc508
Remove unused LOGGER import
KaiOBerg May 1, 2026
6c6e41a
Rename create_hazard.py script to utility_tutorial.py and add funcito…
KaiOBerg May 1, 2026
6af6bc8
change hazard sets to synthetic tracks and adjust documentation
KaiOBerg May 1, 2026
a3d065c
- rename script containing helper functions for tutorial
KaiOBerg May 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add function for overlapping subareas
  • Loading branch information
KaiOBerg committed Nov 21, 2025
commit 499bf9714c9d61abd653d6ce2aaa1202a95124d1
107 changes: 104 additions & 3 deletions climada_petals/engine/cat_bonds/subareas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rasterio.transform import from_bounds
from sklearn.neighbors import NearestNeighbors
import cartopy.crs as ccrs
import networkx as nx

import logging

Expand Down Expand Up @@ -174,7 +175,7 @@ def _crop_grid_cells_to_polygon(self, exp_gdf):
# Loop through each polygon in the GeoDataFrame
for idx, polygon in exp_gdf.iterrows():

# Pad the geometry bounds by 1% of width/height for better coverage
# Pad the geometry bounds by 2% of width/height for better coverage
minx, miny, maxx, maxy = polygon.geometry.bounds
pad_x = (maxx - minx) * 0.02
pad_y = (maxy - miny) * 0.02
Expand All @@ -186,6 +187,16 @@ def _crop_grid_cells_to_polygon(self, exp_gdf):
LOGGER.info(
f"Processing polygon with bounds: {minx}, {miny}, {maxx}, {maxy}"
)
if maxx - minx < self._resolution or maxy - miny < self._resolution:
LOGGER.info(
"Polygon smaller than resolution; adding polygon bounding box."
)
# Add a rectangle (bounding box) with 2% buffer around the polygon
buffered_bbox = box(minx, miny, maxx, maxy)
cropped_cells.append(
gpd.GeoDataFrame(geometry=[buffered_bbox], crs=exp_gdf.crs)
)
continue

num_cells_x = int((maxx - minx) / self._resolution) + 1
num_cells_y = int((maxy - miny) / self._resolution) + 1
Expand Down Expand Up @@ -222,8 +233,10 @@ def _crop_grid_cells_to_polygon(self, exp_gdf):
grids = gpd.GeoDataFrame(
pd.concat(cropped_cells, ignore_index=True), crs=exp_gdf.crs
)
grids.reset_index(drop=True, inplace=True)
subareas = grids[~grids.is_empty]
# Merge overlapping grid cells into single polygons
merged_grids = self.merge_overlapping_grids_nx(grids)
merged_grids.reset_index(drop=True, inplace=True)
subareas = merged_grids[~merged_grids.is_empty]
subareas = subareas.reset_index(drop=True)

LOGGER.info("Subareas created.")
Expand Down Expand Up @@ -288,3 +301,91 @@ def _create_exp_gdf(self):
LOGGER.info("Exposure perimeter polygon created.")

return exp_gdf


def merge_overlapping_grids(self, gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame:

"""
Merges overlapping grid cells in a GeoDataFrame into single polygons.

Parameters
----------
gdf : geopandas.GeoDataFrame
GeoDataFrame containing grid cell geometries.

Returns
-------
merged_gdf : geopandas.GeoDataFrame
GeoDataFrame with overlapping grid cells merged into single polygons.
"""

LOGGER.info("Merging overlapping grid cells into single polygons.")

geoms = gdf.geometry.tolist()
to_delete = []
for idx, geom in enumerate(geoms):
for idx_inner, candidate in enumerate(geoms):
if idx >= idx_inner:
continue
else:
# Example grid cells
cell1 = box(geom.bounds[0], geom.bounds[1], geom.bounds[2], geom.bounds[3])
cell2 = box(candidate.bounds[0], candidate.bounds[1], candidate.bounds[2], candidate.bounds[3])
is_contained_1 = cell1.contains(cell2)
is_contained_2 = cell2.contains(cell1)
if is_contained_1:
to_delete.append(idx_inner)
continue
elif is_contained_2:
geoms[idx] = geoms[idx_inner]
to_delete.append(idx_inner)
continue
else:
# Calculate intersection area
overlap = cell1.intersection(cell2).area
print("Overlapping area:", overlap)
if overlap > 0:
geoms[idx] = geoms[idx].union(geoms[idx_inner])
to_delete.append(idx_inner)
continue
else:
continue
geoms = [geom for i, geom in enumerate(geoms) if i not in to_delete]
merged_gdf = gpd.GeoDataFrame(geometry=geoms, crs=gdf.crs)
LOGGER.info("Merging completed.")
return merged_gdf

def merge_overlapping_grids_nx(self, gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
LOGGER.info("Merging overlapping grid cells into single polygons.")

geoms = gdf.geometry.tolist()
# Step 1: Remove polygons strictly within others
to_remove = set()
for i, geom in enumerate(geoms):
for j, candidate in enumerate(geoms):
if i == j or j in to_remove:
continue
if geom.within(candidate):
to_remove.add(i)
elif candidate.within(geom):
to_remove.add(j)
geoms_filtered = [geom for i, geom in enumerate(geoms) if i not in to_remove]

# Step 2: Merge polygons that overlap with positive area
G = nx.Graph()
G.add_nodes_from(range(len(geoms_filtered)))
for i, geom in enumerate(geoms_filtered):
for j, candidate in enumerate(geoms_filtered):
if i >= j:
continue
if geom.intersection(candidate).area > 1e-9:
G.add_edge(i, j)

merged_polys = [
gpd.GeoSeries([geoms_filtered[idx] for idx in comp]).unary_union
for comp in nx.connected_components(G)
]

merged_gdf = gpd.GeoDataFrame(geometry=merged_polys, crs=gdf.crs)
LOGGER.info("Merging completed.")
return merged_gdf