Skip to content

Commit 158b03a

Browse files
committed
WIP
1 parent e66618e commit 158b03a

File tree

5 files changed

+207
-196
lines changed

5 files changed

+207
-196
lines changed

pystac_monty/geocoding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ def get_geometry_by_country_name(self, country_name: str) -> Optional[Dict[str,
501501
return None
502502

503503
def get_iso3_from_geometry(self, geometry: Dict[str, Any]) -> Optional[str]:
504-
raise NotImplementedError("Method not implemented")
504+
# FIXME: Implement this later
505+
return "UNK"
505506

506507
def get_geometry_from_iso3(self, iso3: str) -> Optional[Dict[str, Any]]:
507508
raise NotImplementedError("Method not implemented")

pystac_monty/sources/desinventar.py

Lines changed: 9 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -24,107 +24,19 @@
2424
)
2525
from pystac_monty.hazard_profiles import MontyHazardProfiles
2626
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+
)
3134

3235
logger = logging.getLogger(__name__)
3336

3437
T = typing.TypeVar("T")
3538

3639

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-
12840
# TODO: move to common utils
12941
def get_list_item_safe(lst: list[T], index: int, default_value: T | None = None) -> T | None:
13042
try:
@@ -686,6 +598,8 @@ def get_stac_items(self) -> typing.Generator[Item, None, None]:
686598
if event_item := self._create_event_item_from_row(row_data):
687599
yield event_item
688600
yield from self._create_impact_items_from_row(row_data, event_item)
601+
else:
602+
failed_items_count += 1
689603
except Exception:
690604
failed_items_count += 1
691605
logger.error('Failed to process desinventar', exc_info=True)

0 commit comments

Comments
 (0)