diff --git a/flash_flood_pipeline/data_download/collect_data.py b/flash_flood_pipeline/data_download/collect_data.py index a67c299..6ab85f9 100644 --- a/flash_flood_pipeline/data_download/collect_data.py +++ b/flash_flood_pipeline/data_download/collect_data.py @@ -21,6 +21,9 @@ METEO_RAIN_SENSOR, ) from itertools import compress +import logging + +logger = logging.getLogger(__name__) class dataGetter: @@ -218,6 +221,7 @@ def get_rain_forecast(self): or not expected_cosmo_hindcast_path.exists() ): # switch to gfs + logger.info("COSMO-data not found, switching to GFS-data") hindcast_start = round_to_nearest_hour(datetime.now()) - timedelta( days=2, hours=3 ) @@ -307,6 +311,7 @@ def get_rain_forecast(self): ) gfs_data[row["placeCode"]] = gfs_precipitation else: + logger.info("Retrieving COSMO-data") ta_gdf_4326 = self.ta_gdf.copy() ta_gdf_4326.to_crs(4326, inplace=True) @@ -388,8 +393,7 @@ def get_rain_forecast(self): # val = val.set_index("datetime") # combined_rainfall.append(val) - # print(pd.concat(combined_rainfall, axis=1).head) # pd.concat(combined_rainfall, axis=1).to_csv( - # r"d:\VSCode\IBF-flash-flood-pipeline\flash_flood_pipeline\rainfall_test_gfs_sampling.csv" - # ) + # r"C:\Users\923265\Downloads\gfs_rainfall_prediction.csv" + return gfs_data diff --git a/flash_flood_pipeline/data_upload/upload_results.py b/flash_flood_pipeline/data_upload/upload_results.py index cc363db..caedb27 100644 --- a/flash_flood_pipeline/data_upload/upload_results.py +++ b/flash_flood_pipeline/data_upload/upload_results.py @@ -9,11 +9,11 @@ KARONGA_PLACECODES, RUMPHI_PLACECODES, BLANTYRE_PLACECODES, + THRESHOLD_CORRECTION_VALUES, ) from mapping_tables.exposure_mapping_tables import ( EXPOSURE_TYPES, TA_EXPOSURE_DICT, - POINT_EXPOSURE_DICT, GEOSERVER_EXPOSURE_DICT, ) from utils.api import api_post_request @@ -79,11 +79,20 @@ def upload_and_trigger_tas(self): ta_exposure_trigger = self.TA_exposure.copy() def determine_ta_trigger_state(row): + if row["placeCode"] in THRESHOLD_CORRECTION_VALUES: + threshold = int( + ALERT_THRESHOLD_VALUE + + THRESHOLD_CORRECTION_VALUES.get(row["placeCode"]) + ) + logger.info( + f"Adjusting threshold for {row['placeCode']} from {ALERT_THRESHOLD_VALUE} to {threshold}" + ) + else: + threshold = ALERT_THRESHOLD_VALUE + if pd.isnull(row[ALERT_THRESHOLD_PARAMETER]): return 0 - elif row[ - ALERT_THRESHOLD_PARAMETER - ] > ALERT_THRESHOLD_VALUE and self.lead_time not in [ + elif row[ALERT_THRESHOLD_PARAMETER] > threshold and self.lead_time not in [ "24-hour", "48-hour", ]: @@ -114,9 +123,6 @@ def determine_ta_trigger_state(row): exposed_tas = triggered_tas.loc[triggered_tas["trigger_value"] == 1] if len(exposed_tas) > 0: - print(distr_name) - print(exposed_tas) - for key, value in EXPOSURE_TYPES.items(): exposure_df = exposed_tas.astype({key: "float"}).astype( {key: "int"} @@ -135,7 +141,6 @@ def determine_ta_trigger_state(row): .to_dict("records") ) body["date"] = self.date.strftime("%Y-%m-%dT%H:%M:%SZ") - print(body) api_post_request("admin-area-dynamic-data/exposure", body=body) body = TA_EXPOSURE_DICT @@ -149,7 +154,6 @@ def determine_ta_trigger_state(row): .to_dict("records") ) body["date"] = self.date.strftime("%Y-%m-%dT%H:%M:%SZ") - print(body) api_post_request("admin-area-dynamic-data/exposure", body=body) def expose_point_assets(self): diff --git a/flash_flood_pipeline/logger_config/configure_logger.py b/flash_flood_pipeline/logger_config/configure_logger.py index cab7049..8591aa0 100644 --- a/flash_flood_pipeline/logger_config/configure_logger.py +++ b/flash_flood_pipeline/logger_config/configure_logger.py @@ -1,4 +1,5 @@ import logging +import datetime def configure_logger(): @@ -11,13 +12,23 @@ def configure_logger(): level=logging.INFO, filename="ex.log", ) + # set up logging to console console = logging.StreamHandler() console.setLevel(logging.INFO) + + log_file = logging.FileHandler( + rf"data/logs/container_log_{datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')}.log" + ) + log_file.setLevel(logging.INFO) + # set a format which is simpler for console use formatter = logging.Formatter("%(asctime)s : %(levelname)s : %(message)s") console.setFormatter(formatter) + log_file.setFormatter(formatter) + logging.getLogger("").addHandler(console) + logging.getLogger("").addHandler(log_file) global logger logger = logging.getLogger(__name__) diff --git a/flash_flood_pipeline/runPipeline.py b/flash_flood_pipeline/runPipeline.py index a1b057e..380b8b8 100644 --- a/flash_flood_pipeline/runPipeline.py +++ b/flash_flood_pipeline/runPipeline.py @@ -4,7 +4,13 @@ import geopandas as gpd import numpy as np import logging -from settings.base import DATA_FOLDER, ASSET_TYPES, ENVIRONMENT +from settings.base import ( + DATA_FOLDER, + ASSET_TYPES, + ENVIRONMENT, + ALERT_THRESHOLD_VALUE, + THRESHOLD_CORRECTION_VALUES, +) from logger_config.configure_logger import configure_logger from data_download.collect_data import dataGetter from data_upload.upload_results import DataUploader @@ -14,7 +20,7 @@ from utils.vector_utils.combine_vector_data import combine_vector_data from utils.api import api_post_request -from scenario_selector import scenarioSelector +from scenario_selection.scenario_selector import scenarioSelector import pandas as pd import sys @@ -41,18 +47,25 @@ def determine_trigger_states( if karonga_events: karonga_triggered_list = [] for key, value in karonga_events.items(): + if key in THRESHOLD_CORRECTION_VALUES: + threshold_value = ( + ALERT_THRESHOLD_VALUE + THRESHOLD_CORRECTION_VALUES.get(key) + ) + else: + threshold_value = ALERT_THRESHOLD_VALUE region_file = gpd.read_file( str(DATA_FOLDER / value / "region_statistics.gpkg") ) affected_people = region_file[region_file["placeCode"] == key][ "affected_people" ].values[0] + if affected_people is not None: karonga_triggered_list.append( region_file[region_file["placeCode"] == key][ "affected_people" ].values[0] - > 20 + > threshold_value ) else: karonga_triggered_list.append(False) @@ -63,6 +76,12 @@ def determine_trigger_states( if rumphi_events: rumphi_triggered_list = [] for key, value in rumphi_events.items(): + if key in THRESHOLD_CORRECTION_VALUES: + threshold_value = ( + ALERT_THRESHOLD_VALUE + THRESHOLD_CORRECTION_VALUES.get(key) + ) + else: + threshold_value = ALERT_THRESHOLD_VALUE region_file = gpd.read_file( str(DATA_FOLDER / value / "region_statistics.gpkg") ) @@ -74,7 +93,7 @@ def determine_trigger_states( region_file[region_file["placeCode"] == key][ "affected_people" ].values[0] - > 20 + > threshold_value ) else: rumphi_triggered_list.append(False) @@ -85,6 +104,13 @@ def determine_trigger_states( if blantyre_events: blantyre_triggered_list = [] for key, value in blantyre_events.items(): + if key in THRESHOLD_CORRECTION_VALUES: + threshold_value = ( + ALERT_THRESHOLD_VALUE + THRESHOLD_CORRECTION_VALUES.get(key) + ) + else: + threshold_value = ALERT_THRESHOLD_VALUE + region_file = gpd.read_file( str(DATA_FOLDER / value / "region_statistics.gpkg") ) @@ -96,7 +122,7 @@ def determine_trigger_states( region_file[region_file["placeCode"] == key][ "affected_people" ].values[0] - > 20 + > threshold_value ) else: blantyre_triggered_list.append(False) @@ -259,7 +285,7 @@ def main(): # step (2): scenarioselector: choose scenario per ta logger.info("step 2 started: scenario selection") - scenarios_selector = scenarioSelector(gfs_data) + scenarios_selector = scenarioSelector(gfs_data=gfs_data) ( karonga_leadtime, karonga_events, diff --git a/flash_flood_pipeline/scenario_selector.py b/flash_flood_pipeline/scenario_selection/scenario_selector.py similarity index 68% rename from flash_flood_pipeline/scenario_selector.py rename to flash_flood_pipeline/scenario_selection/scenario_selector.py index c29f2e9..10e6cfa 100644 --- a/flash_flood_pipeline/scenario_selector.py +++ b/flash_flood_pipeline/scenario_selection/scenario_selector.py @@ -1,5 +1,9 @@ import pandas as pd from datetime import datetime +from utils.general_utils.convert_placecode_to_district import ( + convert_placecode_to_district, +) +import numpy as np from mapping_tables.event_mapping import ( event_mapping_12hr, event_mapping_24hr, @@ -13,207 +17,13 @@ RUMPHI_PLACECODES, BLANTYRE_PLACECODES, SMALL_LAGTIME_PLACECODES, + SEVERITY_ORDER_DISTRICT_MAPPING, + EVENT_TRIGGER_HOURS, + UPSTREAM_MAP, ) COLUMNAME = "precipitation" -EVENT_TRIGGER_HOURS = [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 15, - 18, - 21, - 24, - 48, -] - -EVENT_SEVERITY_ORDER = [ - "5mm_1hr", - "10mm_12hr", - "10mm_4hr", - "10mm_2hr", - "20mm_12hr", - "20mm_4hr", - "10mm_1hr", - "20mm_2hr", - "15mm_1hr", - "30mm_12hr", - "50mm_48hr", - "50mm_24hr", - "30mm_4hr", - "30mm_2hr", - "20mm_1hr", - "25mm_1hr", - "40mm_12hr", - "40mm_4hr", - "40mm_2hr", - "30mm_1hr", - "75mm_24hr", - "100mm_48hr", - "50mm_12hr", - "60mm_12hr", - "50mm_4hr", - "50mm_2hr", - "35mm_1hr", - "40mm_1hr", - "100mm_24hr", - "70mm_12hr", - "80mm_12hr", - "60mm_4hr", - "60mm_2hr", - "45mm_1hr", - "50mm_1hr", - "90mm_12hr", - "70mm_4hr", - "70mm_2hr", - "125mm_24hr", - "150mm_48hr", - "100mm_12hr", - "150mm_24hr", - "200mm_48hr", - "200mm_24hr", -] - -UPSTREAM_MAP = { - "MW10410": ["MW10410"], - "MW10220": ["MW10220", "MW10203", "MW10104", "MW10106"], - "MW10203": ["MW10203", "MW10104", "MW10106"], - "MW10104": ["MW10104", "MW10106"], - "MW10106": ["MW10106"], - "MW10411": ["MW10411"], - "MW10503": ["MW10503"], - "MW10506": ["MW10506"], - "MW10502": ["MW10502", "MW10503"], - "MW10520": ["MW10520", "MW10506"], - "MW10510": ["MW10510", "MW10506"], - "MW10501": ["MW10501", "MW10510", "MW10506", "MW10520"], - "MW10505": ["MW10505", "MW10501", "MW10506", "MW10510", "MW10520"], - "MW10509": [ - "MW10509", - "MW10505", - "MW10501", - "MW10506", - "MW10510", - "MW10520", - "MW10511", - "MW10411", - ], - "MW10511": ["MW10511", "MW10411"], - "MW10401": [ - "MW10401", - "MW10509", - "MW10505", - "MW10501", - "MW10506", - "MW10510", - "MW10520", - "MW10511", - "MW10411", - ], - "MW10420": [ - "MW10420", - "MW10410", - "MW10401", - "MW10509", - "MW10505", - "MW10501", - "MW10506", - "MW10510", - "MW10520", - "MW10511", - "MW10411", - ], - "MW10504": [ - "MW10504", - "MW10502", - "MW10503", - "MW10420", - "MW10410", - "MW10401", - "MW10509", - "MW10505", - "MW10501", - "MW10506", - "MW10510", - "MW10520", - "MW10511", - "MW10411", - ], - "MW10407": [ - "MW10407", - "MW10504", - "MW10502", - "MW10503", - "MW10420", - "MW10410", - "MW10401", - "MW10509", - "MW10505", - "MW10501", - "MW10506", - "MW10510", - "MW10520", - "MW10511", - "MW10411", - ], - "MW10403": ["MW10403"], - "MW10404": ["MW10404"], - "MW10402": [ - "MW10402", - "MW10404", - "MW10403", - "MW10407", - "MW10504", - "MW10502", - "MW10503", - "MW10420", - "MW10410", - "MW10401", - "MW10509", - "MW10505", - "MW10501", - "MW10506", - "MW10510", - "MW10520", - "MW10511", - "MW10411", - ], - "MW31546": ["MW31546"], - "MW31545": ["MW31545"], - "MW31541": ["MW31541"], - "MW31548": ["MW31548"], - "MW31552": ["MW31552"], - "MW31540": ["MW31540"], - "MW31549": ["MW31549"], - "MW31543": ["MW31543"], - "MW31533": ["MW31533"], - "MW31539": ["MW31539"], - "MW31531": ["MW31531"], - "MW31553": ["MW31553"], - "MW31544": ["MW31544"], - "MW31542": ["MW31542"], - "MW31551": ["MW31551"], - "MW31537": ["MW31537"], - "MW31536": ["MW31536"], - "MW31535": ["MW31535"], - "MW31534": ["MW31534"], - "MW31538": ["MW31538"], - "MW31547": ["MW31547"], - "MW31550": ["MW31550"], - "MW31532": ["MW31532"], -} - class scenarioSelector: """Scenario Selector class for the malawi IBF pipeline. The class converts rainfall per TA into flood @@ -288,21 +98,35 @@ def event_selection(self): for key, df in gfs_data.items(): for index, row in df.iterrows(): + df.loc[index, "12hr"] = event_mapping_12hr(row["12hr"].item()) df.loc[index, "24hr"] = event_mapping_24hr(row["24hr"].item()) df.loc[index, "48hr"] = event_mapping_48hr(row["48hr"].item()) + if key in SMALL_LAGTIME_PLACECODES: for index, row in df.iterrows(): df.loc[index, "1hr"] = event_mapping_1hr(row["1hr"].item()) df.loc[index, "2hr"] = event_mapping_2hr(row["2hr"].item()) df.loc[index, "4hr"] = event_mapping_4hr(row["4hr"].item()) + else: df.drop(columns=["1hr", "2hr", "4hr"], inplace=True) + for column in df.columns: - df[column] = df[column].astype(int).astype(str) + "mm_" + str(column) + if convert_placecode_to_district(place_code=key) == "Blantyre City": + # round up to nearest 10 (since we did not calculate 5mm events for BC) + df[column] = np.ceil(df[column] / 10.0) * 10 + df[column] = ( + df[column].astype(int).astype(str) + "mm_" + str(column) + ) + else: + df[column] = ( + df[column].astype(int).astype(str) + "mm_" + str(column) + ) + return gfs_data - def find_worst_event(self, df_target_hours): + def find_worst_event(self, df_target_hours, district): """ Takes the dataframe with all events for a single TA and determines which event (e.g., 20mm in 1 hour) will give the largest flooding. The worst event (e.g., 40mm in 2 hours over 20mm in 1 hour) is stored and used to trigger/display in the IBF system. @@ -316,11 +140,17 @@ def find_worst_event(self, df_target_hours): df_hours_filtered = df_target_hours.drop(columns=["time_reference"]) events_list = df_hours_filtered.to_numpy().flatten() severity_index_list = [] + for item in events_list: if not str(item).startswith("0"): - severity_index_list.append(EVENT_SEVERITY_ORDER.index(item)) + severity_index_list.append( + SEVERITY_ORDER_DISTRICT_MAPPING.get(district).index(item) + ) + if severity_index_list: - most_severe_event = EVENT_SEVERITY_ORDER[max(severity_index_list)] + most_severe_event = SEVERITY_ORDER_DISTRICT_MAPPING.get(district)[ + max(severity_index_list) + ] most_severe_event_index = df_target_hours[ df_target_hours[most_severe_event.split("_")[1]] == most_severe_event ].first_valid_index() @@ -353,9 +183,14 @@ def select_scenarios(self): rumphi_events = {} blantyre_leadtimes = [] blantyre_events = {} + for key, df in event_data.items(): df_target_hours = df[df["time_reference"].isin(EVENT_TRIGGER_HOURS)] - event, leadtime = self.find_worst_event(df_target_hours) + event, leadtime = self.find_worst_event( + df_target_hours=df_target_hours, + district=convert_placecode_to_district(key), + ) + if event not in [ "0mm_1hr", "0mm_2hr", diff --git a/flash_flood_pipeline/settings/base.py b/flash_flood_pipeline/settings/base.py index 2b74622..bfd4a6f 100644 --- a/flash_flood_pipeline/settings/base.py +++ b/flash_flood_pipeline/settings/base.py @@ -13,7 +13,14 @@ "vulnerable_health_sites", "region_statistics", ] -KARONGA_PLACECODES = ["MW10106", "MW10104", "MW10203", "MW10220"] + +KARONGA_PLACECODES = [ + "MW10106", + "MW10104", + "MW10203", + "MW10220", +] + RUMPHI_PLACECODES = [ "MW10420", "MW10403", @@ -51,35 +58,102 @@ "MW31532", ] +THRESHOLD_CORRECTION_VALUES = { + "MW31546": 91.0, + "MW31545": 452.0, + "MW31541": 131.0, + "MW31548": 528.0, + "MW31552": 176.0, + "MW31540": 332.0, + "MW31549": 186.0, + "MW31543": 24.0, + "MW31533": 350.0, + "MW31539": 306.0, + "MW31531": 461.0, + "MW31553": 236.0, + "MW31544": 76.0, + "MW31542": 135.0, + "MW31551": 147.0, + "MW31537": 350.0, + "MW31536": 288.0, + "MW31535": 1042.0, + "MW31534": 297.0, + "MW31538": 48.0, + "MW31547": 47.0, + "MW31550": 248.0, + "MW31532": 239.0, +} # based on 20mm in 2 hours event, assuming this event has no impact + SMALL_LAGTIME_PLACECODES = [ "MW10420", "MW10407", - "31546", - "31545", - "31541", - "31548", - "31552", - "31540", - "31549", - "31543", - "31533", - "31539", - "31531", - "31553", - "31544", - "31542", - "31551", - "31537", - "31536", - "31535", - "31534", - "31538", - "31547", - "31550", - "31532", + "MW31546", + "MW31545", + "MW31541", + "MW31548", + "MW31552", + "MW31540", + "MW31549", + "MW31543", + "MW31533", + "MW31539", + "MW31531", + "MW31553", + "MW31544", + "MW31542", + "MW31551", + "MW31537", + "MW31536", + "MW31535", + "MW31534", + "MW31538", + "MW31547", + "MW31550", + "MW31532", ] -EVENT_SEVERITY_ORDER = [ +EVENT_SEVERITY_ORDER_URBAN_TUP = [ + (10, 12), + (10, 4), + (20, 12), + (50, 48), + (10, 2), + (10, 1), + (30, 12), + (50, 24), + (20, 4), + (100, 48), + (40, 12), + (75, 24), + (20, 2), + (50, 12), + (150, 48), + (200, 48), + (60, 12), + (100, 24), + (20, 1), + (70, 12), + (125, 24), + (80, 12), + (40, 4), + (30, 2), + (90, 12), + (150, 24), + (100, 12), + (50, 4), + (200, 24), + (30, 1), + (40, 2), + (60, 4), + (70, 4), + (70, 2), + (50, 2), + (40, 1), + (60, 2), + (50, 1), +] + +EVENT_SEVERITY_ORDER_TUP = [ (5, 1), (10, 12), (10, 4), @@ -126,7 +200,49 @@ (200, 24), ] -EVENT_SEVERITY_ORDER_STR = [ +EVENT_SEVERITY_ORDER_URBAN = [ + "10mm_12hr", + "10mm_4hr", + "20mm_12hr", + "50mm_48hr", + "10mm_2hr", + "10mm_1hr", + "30mm_12hr", + "50mm_24hr", + "20mm_4hr", + "100mm_48hr", + "40mm_12hr", + "75mm_24hr", + "20mm_2hr", + "50mm_12hr", + "30mm_4hr", # TODO RANDOM FOR NOW, STILL NEEDS TO BE RUN + "150mm_48hr", + "200mm_48hr", + "60mm_12hr", + "100mm_24hr", + "20mm_1hr", + "70mm_12hr", + "125mm_24hr", + "80mm_12hr", + "40mm_4hr", + "30mm_2hr", + "90mm_12hr", + "150mm_24hr", + "100mm_12hr", + "50mm_4hr", + "200mm_24hr", + "30mm_1hr", + "40mm_2hr", + "60mm_4hr", + "70mm_4hr", + "70mm_2hr", + "50mm_2hr", + "40mm_1hr", + "60mm_2hr", + "50mm_1hr", +] + +EVENT_SEVERITY_ORDER = [ "5mm_1hr", "10mm_12hr", "10mm_4hr", @@ -173,6 +289,163 @@ "200mm_24hr", ] +EVENT_TRIGGER_HOURS = [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 15, + 18, + 21, + 24, + 48, +] + +UPSTREAM_MAP = { + "MW10410": ["MW10410"], + "MW10220": ["MW10220", "MW10203", "MW10104", "MW10106"], + "MW10203": ["MW10203", "MW10104", "MW10106"], + "MW10104": ["MW10104", "MW10106"], + "MW10106": ["MW10106"], + "MW10411": ["MW10411"], + "MW10503": ["MW10503"], + "MW10506": ["MW10506"], + "MW10502": ["MW10502", "MW10503"], + "MW10520": ["MW10520", "MW10506"], + "MW10510": ["MW10510", "MW10506"], + "MW10501": ["MW10501", "MW10510", "MW10506", "MW10520"], + "MW10505": ["MW10505", "MW10501", "MW10506", "MW10510", "MW10520"], + "MW10509": [ + "MW10509", + "MW10505", + "MW10501", + "MW10506", + "MW10510", + "MW10520", + "MW10511", + "MW10411", + ], + "MW10511": ["MW10511", "MW10411"], + "MW10401": [ + "MW10401", + "MW10509", + "MW10505", + "MW10501", + "MW10506", + "MW10510", + "MW10520", + "MW10511", + "MW10411", + ], + "MW10420": [ + "MW10420", + "MW10410", + "MW10401", + "MW10509", + "MW10505", + "MW10501", + "MW10506", + "MW10510", + "MW10520", + "MW10511", + "MW10411", + ], + "MW10504": [ + "MW10504", + "MW10502", + "MW10503", + "MW10420", + "MW10410", + "MW10401", + "MW10509", + "MW10505", + "MW10501", + "MW10506", + "MW10510", + "MW10520", + "MW10511", + "MW10411", + ], + "MW10407": [ + "MW10407", + "MW10504", + "MW10502", + "MW10503", + "MW10420", + "MW10410", + "MW10401", + "MW10509", + "MW10505", + "MW10501", + "MW10506", + "MW10510", + "MW10520", + "MW10511", + "MW10411", + ], + "MW10403": ["MW10403"], + "MW10404": ["MW10404"], + "MW10402": [ + "MW10402", + "MW10404", + "MW10403", + "MW10407", + "MW10504", + "MW10502", + "MW10503", + "MW10420", + "MW10410", + "MW10401", + "MW10509", + "MW10505", + "MW10501", + "MW10506", + "MW10510", + "MW10520", + "MW10511", + "MW10411", + ], + "MW31546": ["MW31546"], + "MW31545": ["MW31545"], + "MW31541": ["MW31541"], + "MW31548": ["MW31548"], + "MW31552": ["MW31552"], + "MW31540": ["MW31540"], + "MW31549": ["MW31549"], + "MW31543": ["MW31543"], + "MW31533": ["MW31533"], + "MW31539": ["MW31539"], + "MW31531": ["MW31531"], + "MW31553": ["MW31553"], + "MW31544": ["MW31544"], + "MW31542": ["MW31542"], + "MW31551": ["MW31551"], + "MW31537": ["MW31537"], + "MW31536": ["MW31536"], + "MW31535": ["MW31535"], + "MW31534": ["MW31534"], + "MW31538": ["MW31538"], + "MW31547": ["MW31547"], + "MW31550": ["MW31550"], + "MW31532": ["MW31532"], +} + +SEVERITY_ORDER_DISTRICT_MAPPING = { + "Blantyre City": EVENT_SEVERITY_ORDER_URBAN, + "Karonga": EVENT_SEVERITY_ORDER, + "Rumphi": EVENT_SEVERITY_ORDER, + None: EVENT_SEVERITY_ORDER, +} + # alerts ALERT_THRESHOLD_VALUE = 20 ALERT_THRESHOLD_PARAMETER = "affected_people" diff --git a/flash_flood_pipeline/utils/general_utils/convert_placecode_to_district.py b/flash_flood_pipeline/utils/general_utils/convert_placecode_to_district.py new file mode 100644 index 0000000..0d4801d --- /dev/null +++ b/flash_flood_pipeline/utils/general_utils/convert_placecode_to_district.py @@ -0,0 +1,16 @@ +from settings.base import ( + KARONGA_PLACECODES, + RUMPHI_PLACECODES, + BLANTYRE_PLACECODES, +) + + +def convert_placecode_to_district(place_code): + if place_code in KARONGA_PLACECODES: + return "Karonga" + elif place_code in RUMPHI_PLACECODES: + return "Rumphi" + elif place_code in BLANTYRE_PLACECODES: + return "Blantyre City" + else: + return None diff --git a/flash_flood_pipeline/utils/vector_utils/combine_vector_data.py b/flash_flood_pipeline/utils/vector_utils/combine_vector_data.py index 2b9a621..3d78383 100644 --- a/flash_flood_pipeline/utils/vector_utils/combine_vector_data.py +++ b/flash_flood_pipeline/utils/vector_utils/combine_vector_data.py @@ -62,7 +62,7 @@ def combine_vector_data(ta_df, data_folder, asset_type): if len(features_within_ta) > 0: features_within_ta_filtered = features_within_ta[ - ["id", "vulnerability"] + ["id", "vulnerability", "geometry"] ] vector_layers.append(features_within_ta_filtered)