44
55from abc import ABC
66from collections .abc import Mapping
7- from datetime import datetime
8- from typing import Any , Dict , Generic , Iterator , Literal , TypeVar , Union , cast
7+ from typing import Any , Generic , Iterator , Literal , TypeVar , Union , cast
98
109import pystac
1110import pystac .extensions
1211import pystac .extensions .ext
1312from pystac .extensions import item_assets
1413from pystac .extensions .base import ExtensionManagementMixin , PropertiesExtension
1514from pystac .extensions .hooks import ExtensionHooks
16- from pystac .utils import StringEnum , get_opt , get_required , map_opt , str_to_datetime
15+ from pystac .utils import StringEnum , get_opt , get_required , map_opt
1716
1817from pystac_monty .hazard_profiles import HazardProfiles
1918from pystac_monty .paring import Pairing
2019
2120__version__ = "0.1.0"
2221
23- T = TypeVar (
24- "T" , pystac .Collection , pystac .Item , pystac .Asset , item_assets .AssetDefinition
25- )
22+ T = TypeVar ("T" , pystac .Collection , pystac .Item , pystac .Asset , item_assets .AssetDefinition )
2623
2724SCHEMA_URI = "https://ifrcgo.github.io/monty/v0.1.0/schema.json"
2825
@@ -158,8 +155,8 @@ def __init__(self) -> None:
158155 MontyImpactExposureCategory .AID_CONTRIBUTIONS_NON_INFLATION_ADJUSTED : "Aid Contributions Non-Inflation-Adjusted" ,
159156 MontyImpactExposureCategory .AID_CONTRIBUTIONS_UNSPECIFIED : "Aid Contributions (Unspecified-Inflation-Adjustment)" ,
160157 MontyImpactExposureCategory .RECONSTRUCTION_COSTS_INFLATION_ADJUSTED : "Reconstruction Costs Inflation-Adjusted" ,
161- MontyImpactExposureCategory .RECONSTRUCTION_COSTS_NON_INFLATION_ADJUSTED : "Reconstruction Costs Non-Inflation-Adjusted" ,
162- MontyImpactExposureCategory .RECONSTRUCTION_COSTS_UNSPECIFIED : "Reconstruction Costs (Unspecified-Inflation-Adjustment)" ,
158+ MontyImpactExposureCategory .RECONSTRUCTION_COSTS_NON_INFLATION_ADJUSTED : "Reconstruction Costs Non-Inflation-Adjusted" , # noqa: E501
159+ MontyImpactExposureCategory .RECONSTRUCTION_COSTS_UNSPECIFIED : "Reconstruction Costs (Unspecified-Inflation-Adjustment)" , # noqa: E501
163160 MontyImpactExposureCategory .INSURED_COSTS_INFLATION_ADJUSTED : "Insured Costs Inflation-Adjusted" ,
164161 MontyImpactExposureCategory .INSURED_COSTS_NON_INFLATION_ADJUSTED : "Insured Costs Non-Inflation-Adjusted" ,
165162 MontyImpactExposureCategory .INSURED_COSTS_UNSPECIFIED : "Insured Costs (Unspecified-Inflation-Adjustment)" ,
@@ -173,11 +170,11 @@ def __init__(self) -> None:
173170 MontyImpactExposureCategory .TOTAL_DIRECT_COSTS_NON_INFLATION_ADJUSTED : "Total Direct Costs Non-Inflation-Adjusted" ,
174171 MontyImpactExposureCategory .TOTAL_DIRECT_COSTS_UNSPECIFIED : "Total Direct Costs (Unspecified-Inflation-Adjustment)" ,
175172 MontyImpactExposureCategory .TOTAL_INDIRECT_COSTS_INFLATION_ADJUSTED : "Total Indirect Costs Inflation-Adjusted" ,
176- MontyImpactExposureCategory .TOTAL_INDIRECT_COSTS_NON_INFLATION_ADJUSTED : "Total Indirect Costs Non-Inflation-Adjusted" ,
177- MontyImpactExposureCategory .TOTAL_INDIRECT_COSTS_UNSPECIFIED : "Total Indirect Costs (Unspecified-Inflation-Adjustment)" ,
173+ MontyImpactExposureCategory .TOTAL_INDIRECT_COSTS_NON_INFLATION_ADJUSTED : "Total Indirect Costs Non-Inflation-Adjusted" , # noqa: E501
174+ MontyImpactExposureCategory .TOTAL_INDIRECT_COSTS_UNSPECIFIED : "Total Indirect Costs (Unspecified-Inflation-Adjustment)" , # noqa: E501
178175 MontyImpactExposureCategory .CATTLE : "Cattle" ,
179176 MontyImpactExposureCategory .ALERTSCORE : "Alertscore" ,
180- MontyImpactExposureCategory .IFRC_AID_CONTRIBUTIONS_UNSPECIFIED : "IFRC Aid Contributions (Unspecified-Inflation-Adjustment)" ,
177+ MontyImpactExposureCategory .IFRC_AID_CONTRIBUTIONS_UNSPECIFIED : "IFRC Aid Contributions (Unspecified-Inflation-Adjustment)" , # noqa: E501
181178 }
182179
183180 def __getitem__ (self , key : MontyImpactExposureCategory ) -> str :
@@ -245,7 +242,7 @@ def __init__(self) -> None:
245242 MontyImpactType .LOSS_COST : "Loss (Cost)" ,
246243 MontyImpactType .HOMELESS : "Homeless" ,
247244 MontyImpactType .INTERNALLY_DISPLACED_PERSONS : "Internally Displaced Persons (IDPs)" ,
248- MontyImpactType .REFUGEES_ASYLUM_SEEKERS_EXTERNALLY_DISPLACED_PERSONS : "Refugees, Asylum Seekers and Externally Displaced Persons" ,
245+ MontyImpactType .REFUGEES_ASYLUM_SEEKERS_EXTERNALLY_DISPLACED_PERSONS : "Refugees, Asylum Seekers and Externally Displaced Persons" , # noqa: E501
249246 MontyImpactType .DISPLACED_PERSONS : "Displaced Persons (Internal & External)" ,
250247 MontyImpactType .ALERTSCORE : "Alertscore" ,
251248 }
@@ -340,9 +337,7 @@ def to_dict(self) -> dict[str, Any]:
340337
341338 @staticmethod
342339 def from_dict (d : dict [str , Any ]) -> HazardDetail :
343- cluster : str = get_required (
344- d .get (HAZDET_CLUSTER_PROP ), "hazard_detail" , HAZDET_CLUSTER_PROP
345- )
340+ cluster : str = get_required (d .get (HAZDET_CLUSTER_PROP ), "hazard_detail" , HAZDET_CLUSTER_PROP )
346341
347342 return HazardDetail (cluster )
348343
@@ -405,7 +400,7 @@ def value(self) -> float:
405400 ITEM_IMPACT_DETAIL_PROP ,
406401 IMPDET_VALUE_PROP ,
407402 )
408-
403+
409404 @value .setter
410405 def value (self , v : float ) -> None :
411406 self .properties [IMPDET_VALUE_PROP ] = v
@@ -433,18 +428,13 @@ def to_dict(self) -> dict[str, Any]:
433428
434429 @staticmethod
435430 def from_dict (d : dict [str , Any ]) -> ImpactDetail :
436- category : str = get_required (
437- d .get (IMPDET_CATEGORY_PROP ), "impact_detail" , IMPDET_CATEGORY_PROP
438- )
439- type : str = get_required (
440- d .get (IMPDET_TYPE_PROP ), "impact_detail" , IMPDET_TYPE_PROP
441- )
442- value : float = get_required (
443- d .get (IMPDET_VALUE_PROP ), "impact_detail" , IMPDET_VALUE_PROP
444- )
431+ category : str = get_required (d .get (IMPDET_CATEGORY_PROP ), "impact_detail" , IMPDET_CATEGORY_PROP )
432+ type : str = get_required (d .get (IMPDET_TYPE_PROP ), "impact_detail" , IMPDET_TYPE_PROP )
433+ value : float = get_required (d .get (IMPDET_VALUE_PROP ), "impact_detail" , IMPDET_VALUE_PROP )
445434
446435 return ImpactDetail (category , type , value )
447436
437+
448438class MontyExtension (
449439 Generic [T ],
450440 PropertiesExtension ,
@@ -492,9 +482,7 @@ def apply(
492482 @property
493483 def correlation_id (self ) -> str :
494484 """A unique correlation identifier for the event of the data."""
495- result = get_required (
496- self ._get_property (ITEM_CORR_ID_PROP , str ), self , ITEM_CORR_ID_PROP
497- )
485+ result = get_required (self ._get_property (ITEM_CORR_ID_PROP , str ), self , ITEM_CORR_ID_PROP )
498486 return result
499487
500488 @correlation_id .setter
@@ -529,23 +517,19 @@ def hazard_codes(self, v: list[str] | None) -> None:
529517 @property
530518 def hazard_detail (self ) -> HazardDetail | None :
531519 """The details of the hazard."""
532- result = map_opt (
533- self ._get_property (ITEM_HAZARD_DETAIL_PROP , dict ), HazardDetail
534- )
520+ result = map_opt (self ._get_property (ITEM_HAZARD_DETAIL_PROP , dict ), HazardDetail )
535521 return result
536522
537523 @hazard_detail .setter
538524 def hazard_detail (self , v : HazardDetail | None ) -> None :
539525 self ._set_property (ITEM_HAZARD_DETAIL_PROP , map_opt (lambda x : x .to_dict (), v ))
540-
526+
541527 @property
542528 def impact_detail (self ) -> ImpactDetail | None :
543529 """The details of the impact."""
544- result = map_opt (
545- self ._get_property (ITEM_IMPACT_DETAIL_PROP , dict ), ImpactDetail
546- )
530+ result = map_opt (self ._get_property (ITEM_IMPACT_DETAIL_PROP , dict ), ImpactDetail )
547531 return result
548-
532+
549533 @impact_detail .setter
550534 def impact_detail (self , v : ImpactDetail | None ) -> None :
551535 self ._set_property (ITEM_IMPACT_DETAIL_PROP , map_opt (lambda x : x .to_dict (), v ))
@@ -560,9 +544,7 @@ def episode_number(self, v: int) -> None:
560544 self .properties [ITEM_EPISODE_NUMBER_PROP ] = v
561545
562546 def compute_and_set_correlation_id (self , hazard_profiles : HazardProfiles ) -> None :
563- correlation_id = self .pairing .generate_correlation_id (
564- self .item , hazard_profiles
565- )
547+ correlation_id = self .pairing .generate_correlation_id (self .item , hazard_profiles )
566548 self .correlation_id = correlation_id
567549
568550 @classmethod
@@ -595,9 +577,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> MontyExtension[T]:
595577
596578 @staticmethod
597579 def enable_extension () -> None :
598- pystac .extensions .ext .ItemExt .monty = property (
599- lambda self : MontyExtension .ext (self )
600- )
580+ pystac .extensions .ext .ItemExt .monty = property (lambda self : MontyExtension .ext (self ))
601581
602582
603583class CollectionMontyExtension (MontyExtension [pystac .Collection ]):
@@ -638,24 +618,15 @@ def __init__(self, item: pystac.Item):
638618
639619 def is_source_event (self ) -> bool :
640620 """Indicates if the item is a source event."""
641- return (
642- MontyRoles .SOURCE in self .item .properties ["roles" ]
643- and MontyRoles .EVENT in self .item .properties ["roles" ]
644- )
621+ return MontyRoles .SOURCE in self .item .properties ["roles" ] and MontyRoles .EVENT in self .item .properties ["roles" ]
645622
646623 def is_source_hazard (self ) -> bool :
647624 """Indicates if the item is a source hazard."""
648- return (
649- MontyRoles .SOURCE in self .item .properties ["roles" ]
650- and MontyRoles .HAZARD in self .item .properties ["roles" ]
651- )
652-
625+ return MontyRoles .SOURCE in self .item .properties ["roles" ] and MontyRoles .HAZARD in self .item .properties ["roles" ]
626+
653627 def is_source_impact (self ) -> bool :
654628 """Indicates if the item is a source impact."""
655- return (
656- MontyRoles .SOURCE in self .item .properties ["roles" ]
657- and MontyRoles .IMPACT in self .item .properties ["roles" ]
658- )
629+ return MontyRoles .SOURCE in self .item .properties ["roles" ] and MontyRoles .IMPACT in self .item .properties ["roles" ]
659630
660631 def __repr__ (self ) -> str :
661632 return f"<ItemMontyExtension Item id={ self .item .id } >"
0 commit comments