From cc1578a53591f85cb48652d16aee6668ee294cdc Mon Sep 17 00:00:00 2001 From: Sam Gamble Date: Fri, 25 Sep 2026 09:55:32 +0100 Subject: [PATCH] Example PiCyberPreAnalysis --- PiCyberPreAnalysis/LICENSE | 25 ++++++ PiCyberPreAnalysis/README.md | 16 ++++ .../keys_data/AnnualRevenueMap.csv | 6 ++ .../keys_data/area_peril_dict.csv | 7 ++ .../keys_data/lookup_config.json | 73 ++++++++++++++++++ .../keys_data/vulnerability_dict.csv | 7 ++ .../model_data/damage_bin_dict.bin | Bin 0 -> 40 bytes .../model_data/damage_bin_dict.csv | 3 + PiCyberPreAnalysis/model_data/events.bin | Bin 0 -> 48 bytes PiCyberPreAnalysis/model_data/events.csv | 13 ++++ PiCyberPreAnalysis/model_data/footprint.bin.z | Bin 0 -> 428 bytes PiCyberPreAnalysis/model_data/footprint.csv | 73 ++++++++++++++++++ PiCyberPreAnalysis/model_data/footprint.idx.z | Bin 0 -> 240 bytes PiCyberPreAnalysis/model_data/model_to_bin.sh | 24 ++++++ PiCyberPreAnalysis/model_data/occurrence.bin | Bin 0 -> 44 bytes PiCyberPreAnalysis/model_data/occurrence.csv | 4 + .../model_data/returnperiods.bin | Bin 0 -> 16 bytes .../model_data/returnperiods.csv | 5 ++ .../model_data/vulnerability.bin | Bin 0 -> 196 bytes .../model_data/vulnerability.csv | 13 ++++ .../src/exposure_modification/__init__.py | 0 .../exposure_pre_analysis_revenue.py | 26 +++++++ PiCyberPreAnalysis/tests/test_1/account.csv | 5 ++ .../tests/test_1/analysis_settings.json | 18 +++++ .../tests/test_1/exposure_pre_analysis.json | 3 + PiCyberPreAnalysis/tests/test_1/oasislmf.json | 9 +++ 26 files changed, 330 insertions(+) create mode 100644 PiCyberPreAnalysis/LICENSE create mode 100644 PiCyberPreAnalysis/README.md create mode 100644 PiCyberPreAnalysis/keys_data/AnnualRevenueMap.csv create mode 100644 PiCyberPreAnalysis/keys_data/area_peril_dict.csv create mode 100644 PiCyberPreAnalysis/keys_data/lookup_config.json create mode 100644 PiCyberPreAnalysis/keys_data/vulnerability_dict.csv create mode 100644 PiCyberPreAnalysis/model_data/damage_bin_dict.bin create mode 100644 PiCyberPreAnalysis/model_data/damage_bin_dict.csv create mode 100644 PiCyberPreAnalysis/model_data/events.bin create mode 100644 PiCyberPreAnalysis/model_data/events.csv create mode 100644 PiCyberPreAnalysis/model_data/footprint.bin.z create mode 100644 PiCyberPreAnalysis/model_data/footprint.csv create mode 100644 PiCyberPreAnalysis/model_data/footprint.idx.z create mode 100644 PiCyberPreAnalysis/model_data/model_to_bin.sh create mode 100644 PiCyberPreAnalysis/model_data/occurrence.bin create mode 100644 PiCyberPreAnalysis/model_data/occurrence.csv create mode 100644 PiCyberPreAnalysis/model_data/returnperiods.bin create mode 100644 PiCyberPreAnalysis/model_data/returnperiods.csv create mode 100644 PiCyberPreAnalysis/model_data/vulnerability.bin create mode 100644 PiCyberPreAnalysis/model_data/vulnerability.csv create mode 100644 PiCyberPreAnalysis/src/exposure_modification/__init__.py create mode 100644 PiCyberPreAnalysis/src/exposure_modification/exposure_pre_analysis_revenue.py create mode 100644 PiCyberPreAnalysis/tests/test_1/account.csv create mode 100644 PiCyberPreAnalysis/tests/test_1/analysis_settings.json create mode 100644 PiCyberPreAnalysis/tests/test_1/exposure_pre_analysis.json create mode 100644 PiCyberPreAnalysis/tests/test_1/oasislmf.json diff --git a/PiCyberPreAnalysis/LICENSE b/PiCyberPreAnalysis/LICENSE new file mode 100644 index 00000000..1cbb6737 --- /dev/null +++ b/PiCyberPreAnalysis/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2017, Oasis Loss Modelling Framework +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/PiCyberPreAnalysis/README.md b/PiCyberPreAnalysis/README.md new file mode 100644 index 00000000..d8d7620e --- /dev/null +++ b/PiCyberPreAnalysis/README.md @@ -0,0 +1,16 @@ +Oasis LMF logo + +# PiCyber Pre-Analysis + +A copy of the [PiCyber](../PiCyber) model with an exposure pre-analysis hook, to check that pre-analysis works for account only portfolios (no location file), as used by cyber and liability models. + +The hook, `src/exposure_modification/exposure_pre_analysis_revenue.py`, multiplies each account's `AnnualRevenue` by `revenue_scale_factor` (set in `tests/test_1/exposure_pre_analysis.json`). The lookup maps `AnnualRevenue` into revenue bands, so the scaled accounts can be assigned a different area peril and vulnerability. + +After a run, the modified account file is in `runs/losses-/input/account.csv`. + +## Running the model + +``` +cd tests/test_1 +oasislmf model run --config oasislmf.json +``` diff --git a/PiCyberPreAnalysis/keys_data/AnnualRevenueMap.csv b/PiCyberPreAnalysis/keys_data/AnnualRevenueMap.csv new file mode 100644 index 00000000..a6ab10d0 --- /dev/null +++ b/PiCyberPreAnalysis/keys_data/AnnualRevenueMap.csv @@ -0,0 +1,6 @@ +0 +100000 +1000000 +10000000 +50000000 +100000000 diff --git a/PiCyberPreAnalysis/keys_data/area_peril_dict.csv b/PiCyberPreAnalysis/keys_data/area_peril_dict.csv new file mode 100644 index 00000000..55539115 --- /dev/null +++ b/PiCyberPreAnalysis/keys_data/area_peril_dict.csv @@ -0,0 +1,7 @@ +area_peril_id,revenuecategory,countrycode,peril_id +1,1,GB,CSB +2,2,GB,CSB +3,3,GB,CSB +4,4,GB,CSB +5,5,GB,CSB +6,6,GB,CSB diff --git a/PiCyberPreAnalysis/keys_data/lookup_config.json b/PiCyberPreAnalysis/keys_data/lookup_config.json new file mode 100644 index 00000000..dc0a598e --- /dev/null +++ b/PiCyberPreAnalysis/keys_data/lookup_config.json @@ -0,0 +1,73 @@ +{ + "model": { + "supplier_id": "OasisLMF", + "model_id": "PiCyberPreAnalysis", + "model_version": "0.0.1" + }, + "builtin_lookup_type": "new_lookup", + "keys_data_path": "./", + "step_definition": { + "coverage_type": { + "type": "prepare", + "parameters": { + "coverage_type": { + "default": 10 + } + } + + }, + "annual_revenue_map": { + "type": "interval_to_index", + "columns": [ + "annualrevenue" + ], + "parameters": { + "sorted_array": "%%KEYS_DATA_PATH%%/AnnualRevenueMap.csv", + "value_column_name": "annualrevenue", + "index_column_name": "revenuecategory" + } + }, + "area_peril": { + "type": "merge", + "columns": [ + "revenuecategory", + "countrycode" + ], + "parameters": { + "file_path": "%%KEYS_DATA_PATH%%/area_peril_dict.csv", + "id_columns": ["area_peril_id"], + "usecols": [ + "revenuecategory", + "countrycode", + "area_peril_id", + "peril_id" + ] + + } + }, + "vulnerability": { + "type": "merge", + "columns": [ + "revenuecategory", + "countrycode" + ], + "parameters": { + "file_path": "%%KEYS_DATA_PATH%%/vulnerability_dict.csv", + "id_columns": ["vulnerability_id"], + "usecols": [ + "revenuecategory", + "countrycode", + "vulnerability_id", + "peril_id" + ] + + } + } + }, + "strategy": [ + "coverage_type", + "annual_revenue_map", + "area_peril", + "vulnerability" + ] +} diff --git a/PiCyberPreAnalysis/keys_data/vulnerability_dict.csv b/PiCyberPreAnalysis/keys_data/vulnerability_dict.csv new file mode 100644 index 00000000..d39c39e6 --- /dev/null +++ b/PiCyberPreAnalysis/keys_data/vulnerability_dict.csv @@ -0,0 +1,7 @@ +vulnerability_id,revenuecategory,countrycode,peril_id +1,1,GB,CSB +2,2,GB,CSB +3,3,GB,CSB +4,4,GB,CSB +5,5,GB,CSB +6,6,GB,CSB diff --git a/PiCyberPreAnalysis/model_data/damage_bin_dict.bin b/PiCyberPreAnalysis/model_data/damage_bin_dict.bin new file mode 100644 index 0000000000000000000000000000000000000000..272416f72f3931d0bad58f7957e23ac6dfe72bc4 GIT binary patch literal 40 ccmZQ%fCGC5h6Xzjj|n0K;sdb*5Hm0U04L4@egFUf literal 0 HcmV?d00001 diff --git a/PiCyberPreAnalysis/model_data/damage_bin_dict.csv b/PiCyberPreAnalysis/model_data/damage_bin_dict.csv new file mode 100644 index 00000000..fa4ec885 --- /dev/null +++ b/PiCyberPreAnalysis/model_data/damage_bin_dict.csv @@ -0,0 +1,3 @@ +bin_index,bin_from,bin_to,interpolation,damage_type +1,0,0.5,0.25,0 +2,0.5,1,0.75,0 diff --git a/PiCyberPreAnalysis/model_data/events.bin b/PiCyberPreAnalysis/model_data/events.bin new file mode 100644 index 0000000000000000000000000000000000000000..8956160621609b3f25d09c1457a4291d29a3df82 GIT binary patch literal 48 hcmWN=hYbKA3;>`y>-zs*A)!P>wb>m`)8+PfeSQVt08an_ literal 0 HcmV?d00001 diff --git a/PiCyberPreAnalysis/model_data/events.csv b/PiCyberPreAnalysis/model_data/events.csv new file mode 100644 index 00000000..360ec036 --- /dev/null +++ b/PiCyberPreAnalysis/model_data/events.csv @@ -0,0 +1,13 @@ +event_id +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 \ No newline at end of file diff --git a/PiCyberPreAnalysis/model_data/footprint.bin.z b/PiCyberPreAnalysis/model_data/footprint.bin.z new file mode 100644 index 0000000000000000000000000000000000000000..1f01928b0fcba8eb2043f5b29d8b7095f44cfd2d GIT binary patch literal 428 zcmZQ#fPjiQ$tej52`LPXY}INCCs|UBl{+^pbZ%Da+^pEi%rNm2%gj+F0~{^@k`b7%PxJ1x<_%$ls18#t!7)LK6eI i<1d;RCy=ke2oZ$2g$u}aMib)(ilw26@c_j-(Zm2j2?t#O literal 0 HcmV?d00001 diff --git a/PiCyberPreAnalysis/model_data/model_to_bin.sh b/PiCyberPreAnalysis/model_data/model_to_bin.sh new file mode 100644 index 00000000..1dd34ffa --- /dev/null +++ b/PiCyberPreAnalysis/model_data/model_to_bin.sh @@ -0,0 +1,24 @@ +#!/bin/bash + + +# damage bin dict +csvtobin damagebin -i damage_bin_dict.csv -o damage_bin_dict.bin + +# events +csvtobin eve -i events.csv -o events.bin + +# footprint +csvtobin footprint -z -m2 -n -i footprint.csv -o footprint.bin.z -x footprint.idx.z + +# occurrence +csvtobin occurrence -P10 -i occurrence.csv -o occurrence.bin + +# return periods +csvtobin returnperiods -i returnperiods.csv -o returnperiods.bin + +# vulnerability +csvtobin vulnerability -d2 -N -i vulnerability.csv -o vulnerability.bin + + + + diff --git a/PiCyberPreAnalysis/model_data/occurrence.bin b/PiCyberPreAnalysis/model_data/occurrence.bin new file mode 100644 index 0000000000000000000000000000000000000000..cc55a37fad4cda762377c12bfa350e1cf65e584b GIT binary patch literal 44 jcmZQ%U|`?^Vn!$q^5SM-0