Skip to content

Commit

Permalink
Add vulnerability functions.
Browse files Browse the repository at this point in the history
We add here the vulnerability funcions to use the data from
the ECB's stress test article from 2023.

Co-authored-by: Víctor de Luna <[email protected]>
Co-authored-by: Arfima Dev <[email protected]>

Signed-off-by: Virginia Morales <[email protected]>
  • Loading branch information
VMarfima committed Aug 7, 2024
1 parent 1719987 commit 0725864
Show file tree
Hide file tree
Showing 19 changed files with 1,720 additions and 173 deletions.
9 changes: 9 additions & 0 deletions src/physrisk/api/v1/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Dict, List, Optional, Union

import numpy as np
Expand All @@ -23,6 +24,14 @@ class Array(np.ndarray, metaclass=ArrayMeta):
pass


class UseCaseId(Enum):
"""Enumeration to select the 'use case' identifier used in vulnerability models and risk measures calculations."""

DEFAULT = 0
STRESS_TEST = 1
GENERIC = 2


class Asset(BaseModel, extra="allow"):
"""Defines an asset. An asset is identified first by its asset_class and then by its type within the class.
An asset's value may be impacted through damage or through disruption
Expand Down
13 changes: 10 additions & 3 deletions src/physrisk/api/v1/impact_req_resp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
VulnerabilityDistrib,
)
from physrisk.api.v1.hazard_data import Scenario
from physrisk.api.v1.common import UseCaseId


class CalcSettings(BaseModel):
Expand All @@ -36,9 +37,13 @@ class AssetImpactRequest(BaseModel):
include_calc_details: bool = Field(
True, description="If true, include impact calculation details."
)
use_case_id: str = Field(
"",
description="Identifier for 'use case' used in the risk measures calculation.",
use_case_id: UseCaseId = Field(
UseCaseId.DEFAULT,
description=(
"Enumeration to select the 'use case' identifier"
"used in vulnerability models and risk measures calculations."
"Options: DEFAULT, STRESSTEST, GENERIC"
),
)
provider_max_requests: Dict[str, int] = Field(
{},
Expand Down Expand Up @@ -70,6 +75,8 @@ class Category(int, Enum):
HIGH = 3
REDFLAG = 4

NORISK = -1


class RiskMeasureDefinition(BaseModel):
measure_id: str = Field(None, description="Identifier for the risk measure.")
Expand Down
13 changes: 2 additions & 11 deletions src/physrisk/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

from dependency_injector import containers, providers

from physrisk.kernel import calculation as calc
from physrisk.data.hazard_data_provider import SourcePath
from physrisk.data.inventory import EmbeddedInventory
from physrisk.data.inventory_reader import InventoryReader
from physrisk.data.pregenerated_hazard_model import ZarrHazardModel
from physrisk.data.zarr_reader import ZarrReader
from physrisk.kernel import calculation as calc
from physrisk.kernel.hazard_model import HazardModelFactory
from physrisk.kernel.vulnerability_model import (
DictBasedVulnerabilityModels,
VulnerabilityModels,
VulnerabilityModelsFactory,
)
from physrisk.kernel.vulnerability_model import DictBasedVulnerabilityModelsFactory
from physrisk.requests import Requester, _create_inventory, create_source_paths


Expand Down Expand Up @@ -41,11 +37,6 @@ def hazard_model(
)


class DictBasedVulnerabilityModelsFactory(VulnerabilityModelsFactory):
def vulnerability_models(self) -> VulnerabilityModels:
return DictBasedVulnerabilityModels(calc.get_default_vulnerability_models())


class Container(containers.DeclarativeContainer):
config = providers.Configuration(default={"zarr_sources": ["embedded", "hazard"]})

Expand Down
3 changes: 1 addition & 2 deletions src/physrisk/data/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import physrisk.data.colormap_provider as colormap_provider
import physrisk.data.static.hazard
from physrisk.api.v1.hazard_data import HazardResource, Period
from physrisk.data.inventory_reader import HazardModels

from ..api.v1.hazard_data import HazardResource, Period

# from physrisk.kernel.hazards import ChronicHeat


Expand Down
Loading

0 comments on commit 0725864

Please sign in to comment.