Skip to content

Commit

Permalink
Merge pull request #20 from c-hydro/glofas_v4
Browse files Browse the repository at this point in the history
commit_20240521_09:35
  • Loading branch information
AndreaLibe authored May 21, 2024
2 parents 536b92e + 21df669 commit 4a818ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions hydro/bulletin_hydro_glofas.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"exposed_map": "/home/andrea/Desktop/Working_dir/GLOFASv4/data/GHS_POP_E2025_africa_wgs84.tif",
"decode_map": "/home/andrea/Desktop/Working_dir/GLOFASv4/data/decode_map_africa.tif",
"aoi": {
"domains": ["N_Interior" ,"Nile", "Congo", "EastCoast", "Senegal", "S_Interior", "LakeChad", "Niger", "Madagascar", "Zambezi", "MedCoast", "WestCoast", "ShebJuba", "IndiOcean", "Orange", "Volta", "AngolaC", "Limpopo", "SA_WCoast", "SA_SCoast", "GuineaGulf", "Namibia", "NWCoast", "RiftValley", "RedSea"],
"domains": ["EastCoast", "N_Interior" ,"Nile", "Congo", "Senegal", "S_Interior", "LakeChad", "Niger", "Madagascar", "Zambezi", "MedCoast", "WestCoast", "ShebJuba", "IndiOcean", "Orange", "Volta", "AngolaC", "Limpopo", "SA_WCoast", "SA_SCoast", "GuineaGulf", "Namibia", "NWCoast", "RiftValley", "RedSea"],
"domain_map": "/home/andrea/Desktop/Working_dir/GLOFASv4/data/AOI/AoI_{domain}.tif",
"decode_table":
{"filename": "/home/andrea/Desktop/Working_dir/GLOFASv4/data/GloFAS_IDs_singleIndex.csv",
Expand All @@ -91,7 +91,7 @@
},
"flood_maps": {
"file_name": "/home/andrea/Desktop/Working_dir/GLOFASv4/data/maps/Africa_RP{return_period}_filled_depth.tif",
"associated_rp": [2,5,10,20,50,100,200,500]
"associated_rp": [10,10,10,20,50,100,200,500]
},
"weight_hazard_levels": [0.02,0.1,0.5,1,1,1,1,1],
"risk_thresholds": {
Expand Down
12 changes: 6 additions & 6 deletions hydro/bulletin_hydro_glofas.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,9 @@ def main():
logging.info( "--> Mosaic flood maps..")
impact_dict["temp_folder"] = os.path.join(paths["ancillary"],"flood_maps","")
os.makedirs(impact_dict["temp_folder"], exist_ok=True)
#mosaic_weigthed_map = create_flood_map(th_levels, impact_dict)
mosaic_weigthed_map = os.path.join(impact_dict["temp_folder"], "flood_map_merged.tif")
mosaic_weigthed_map = create_flood_map(th_levels, impact_dict)
logging.info(" --> Write flood map...")
os.system('gdal_calc.py -A ' + mosaic_weigthed_map + " --outfile=" + out_file_flood_tif + ' --calc="A/A" --type=Int16 --NoDataValue=0 --co="COMPRESS=DEFLATE" --overwrite')
os.system('gdal_calc.py -A ' + mosaic_weigthed_map + " --outfile=" + out_file_flood_tif + ' --calc="A/A" --type=Byte --NoDataValue=0 --co="COMPRESS=DEFLATE" --overwrite --quiet')
logging.info("--> Classify warning levels..")
classify_warning_levels_impact_based(shp_df_hydro_model, mosaic_weigthed_map, out_file_shp, impact_dict)
logging.info("--> Classify warning levels..DONE")
Expand Down Expand Up @@ -332,7 +331,7 @@ def intersect_aoi(mosaic_flood_map, flood_map_level_name, aoi_map, level, codes_
logging.info(' ---> Edit ranges')
flood_map_level = flood_map_level.reindex_like(aoi_map, method='nearest')
# if flood_map_level is > 99999 or <0 set to 0, else set to 1
flood_map_level.values = np.where((flood_map_level.values > 99999) | (flood_map_level.values < 0), 0, 1)
flood_map_level.values = np.where((flood_map_level.values > 99999) | (flood_map_level.values <= 0) | np.isnan(flood_map_level.values), 0, 1)

if level == 2:
logging.info(' ---> Create mosaic map')
Expand Down Expand Up @@ -373,8 +372,9 @@ def create_flood_map(th_levels, impact_dict):
for aoi in impact_dict["aoi"]["domains"]:
logging.info(' ---> Computing domain ' + str(aoi))
aoi_map = impact_dict["aoi"]["domain_map"].format(domain=aoi)
aoi_map = xr.open_rasterio(aoi_map, cache=False).squeeze() #.astype(np.int32)
aoi_map.values[aoi_map.values < 0] = 0
aoi_map = rx.open_rasterio(aoi_map, cache=False).squeeze() #.astype(np.int32)
aoi_map.rio.write_nodata(-9999, inplace=True)
aoi_map.values[(aoi_map.values < 0) | (np.isnan(aoi_map.values))] = 0
aoi_maps = {}

if aoi_map.sizes["x"] * aoi_map.sizes["y"] > 1000000000:
Expand Down

0 comments on commit 4a818ce

Please sign in to comment.