Source code for djura.hazard_consistency.models
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2025-2026 Djura | Risk - Data - Engineering S.r.l.
from pydantic import BaseModel, field_validator
from typing import List, Dict
[docs]
class HazardModelSchema(BaseModel):
s: List[float]
mafe: List[float]
s_fit: List[float]
mafe_fit: List[float]
method: str
coef: List[float]
return_periods: List[float] = None
[docs]
class ConfigDict:
extra = 'forbid'
[docs]
@field_validator('coef', mode="before")
def check_coef_length(cls, coef, values):
if 'method' in values and values['method'] == "power-law" and \
len(coef) != 2:
raise ValueError("For 'power-law' method length of coef must be 2")
if 'method' in values and values['method'] != 'power-law' and \
len(coef) != 3:
raise ValueError("For any method other than 'power-law' "
"the length of coef must be 3")
return coef
[docs]
class HazardSchema(BaseModel):
s: List[float]
poe: List[float]
[docs]
class ConfigDict:
extra = 'forbid'
[docs]
class HazardBatchSchema(BaseModel):
root: Dict[str, HazardSchema]
[docs]
class ConfigDict:
arbitrary_types_allowed = True