|
24 | 24 | ) |
25 | 25 | from pystac_monty.hazard_profiles import MontyHazardProfiles |
26 | 26 | from pystac_monty.sources.common import MontyDataTransformer |
27 | | - |
28 | | -STAC_EVENT_ID_PREFIX = "desinventar-event-" |
29 | | -STAC_HAZARD_ID_PREFIX = "desinventar-hazard-" |
30 | | -STAC_IMPACT_ID_PREFIX = "desinventar-impact-" |
| 27 | +from pystac_monty.validators.desinventar import ( |
| 28 | + STAC_EVENT_ID_PREFIX, |
| 29 | + STAC_HAZARD_ID_PREFIX, |
| 30 | + STAC_IMPACT_ID_PREFIX, |
| 31 | + DataRow, |
| 32 | + GeoDataEntry, |
| 33 | +) |
31 | 34 |
|
32 | 35 | logger = logging.getLogger(__name__) |
33 | 36 |
|
34 | 37 | T = typing.TypeVar("T") |
35 | 38 |
|
36 | 39 |
|
37 | | -class GeoDataEntry(TypedDict): |
38 | | - level: Optional[str] |
39 | | - property_code: Optional[str] |
40 | | - shapefile_data: Optional[gpd.GeoDataFrame] |
41 | | - |
42 | | - |
43 | | -# Properties extracted from desinventar |
44 | | -class DataRow(pydantic.BaseModel): |
45 | | - serial: str |
46 | | - comment: str | None |
47 | | - # source: str | None |
48 | | - |
49 | | - deaths: float | None |
50 | | - injured: float | None |
51 | | - missing: float | None |
52 | | - houses_destroyed: float | None |
53 | | - houses_damaged: float | None |
54 | | - directly_affected: float | None |
55 | | - indirectly_affected: float | None |
56 | | - relocated: float | None |
57 | | - evacuated: float | None |
58 | | - losses_in_dollar: float | None |
59 | | - losses_local_currency: float | None |
60 | | - # education_centers: str | None |
61 | | - # hospitals: str | None |
62 | | - damages_in_crops_ha: float | None |
63 | | - lost_cattle: float | None |
64 | | - damages_in_roads_mts: float | None |
65 | | - |
66 | | - level0: str | None |
67 | | - level1: str | None |
68 | | - level2: str | None |
69 | | - # name0: str | None |
70 | | - # name1: str | None |
71 | | - # name2: str | None |
72 | | - # latitude: str | None |
73 | | - # longitude: str | None |
74 | | - |
75 | | - # haz_maxvalue: str | None |
76 | | - event: str | None |
77 | | - # glide: str | None |
78 | | - location: str | None |
79 | | - |
80 | | - # duration: str | None |
81 | | - year: int |
82 | | - month: int | None |
83 | | - day: int | None |
84 | | - |
85 | | - # Added fields |
86 | | - |
87 | | - iso3: str |
88 | | - data_source_url: str | None |
89 | | - |
90 | | - @property |
91 | | - def event_stac_id(self): |
92 | | - return f"{STAC_EVENT_ID_PREFIX}{self.iso3}-{self.serial}" |
93 | | - |
94 | | - @property |
95 | | - def event_title(self): |
96 | | - return f"{self.event} in {self.location} on {self.event_start_date}" |
97 | | - |
98 | | - @property |
99 | | - def event_description(self): |
100 | | - return f"{self.event} in {self.location}: {self.comment}" |
101 | | - |
102 | | - @property |
103 | | - def event_start_date(self): |
104 | | - if self.year is None: |
105 | | - return |
106 | | - |
107 | | - start_year = self.year |
108 | | - start_month = self.month or 1 |
109 | | - start_day = self.day or 1 |
110 | | - |
111 | | - try: |
112 | | - start_dt = datetime(start_year, start_month, start_day) |
113 | | - return pytz.utc.localize(start_dt) |
114 | | - except Exception: |
115 | | - return None |
116 | | - |
117 | | - @property |
118 | | - def lowest_level(self): |
119 | | - if self.level2 is not None: |
120 | | - return 'level2' |
121 | | - if self.level1 is not None: |
122 | | - return 'level1' |
123 | | - if self.level0 is not None: |
124 | | - return 'level0' |
125 | | - return None |
126 | | - |
127 | | - |
128 | 40 | # TODO: move to common utils |
129 | 41 | def get_list_item_safe(lst: list[T], index: int, default_value: T | None = None) -> T | None: |
130 | 42 | try: |
@@ -686,6 +598,8 @@ def get_stac_items(self) -> typing.Generator[Item, None, None]: |
686 | 598 | if event_item := self._create_event_item_from_row(row_data): |
687 | 599 | yield event_item |
688 | 600 | yield from self._create_impact_items_from_row(row_data, event_item) |
| 601 | + else: |
| 602 | + failed_items_count += 1 |
689 | 603 | except Exception: |
690 | 604 | failed_items_count += 1 |
691 | 605 | logger.error('Failed to process desinventar', exc_info=True) |
|
0 commit comments