-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from kleok/dev
Oct 2024 improves
- Loading branch information
Showing
8 changed files
with
287 additions
and
161 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import geopandas as gpd | ||
import pandas as pd | ||
import os | ||
import matplotlib.pyplot as plt | ||
|
||
def plot_flooded_area_over_time(Floodpy_app, Floodpy_app_objs): | ||
|
||
colorTones = { | ||
6: '#CC3A5D', # dark pink | ||
5: '#555555', # dark grey | ||
4: '#A17C44', # dark brown | ||
3: '#8751A1', # dark purple | ||
2: '#C1403D', # dark red | ||
1: '#2E5A87', # dark blue | ||
0: '#57A35D', # dark green | ||
} | ||
|
||
Flooded_regions_areas_km2 = {} | ||
for flood_date in Floodpy_app_objs.keys(): | ||
# calculate the area of flooded regions | ||
Flood_map_vector_data = gpd.read_file(Floodpy_app_objs[flood_date].Flood_map_vector_dataset_filename) | ||
Flood_map_vector_data_projected = Flood_map_vector_data.to_crs(Flood_map_vector_data.estimate_utm_crs()) | ||
area_km2 = round(Flood_map_vector_data_projected.area.sum()/1000000,2 ) | ||
Flooded_regions_areas_km2[flood_date] = area_km2 | ||
|
||
|
||
def getcolor(val): | ||
return colorTones[Floodpy_app.flood_datetimes.index(val)] | ||
|
||
Flooded_regions_areas_km2_df = pd.DataFrame.from_dict(Flooded_regions_areas_km2, orient='index', columns=['Flooded area (km2)']) | ||
Flooded_regions_areas_km2_df['Datetime'] = pd.to_datetime(Flooded_regions_areas_km2_df.index) | ||
Flooded_regions_areas_km2_df['color'] = Flooded_regions_areas_km2_df['Datetime'].apply(getcolor) | ||
|
||
df = Flooded_regions_areas_km2_df.copy() | ||
# Plot the data | ||
fig = plt.figure(figsize=(6, 5)) | ||
plt.bar(df['Datetime'].astype(str), df['Flooded area (km2)'], color=df['color'], width=0.7) | ||
|
||
# Adjust the plot | ||
plt.ylabel('Flooded area (km²)', fontsize=16) | ||
plt.title('Flooded Area(km²) Over Time', fontsize=16) | ||
plt.xticks(df['Datetime'].astype(str), df['Datetime'].dt.strftime('%d-%b-%Y'), rotation=30, ha='right', fontsize=16) # Set custom date format | ||
plt.yticks(fontsize=16) | ||
plt.tight_layout() # Adjust layout for better fit | ||
|
||
# Display the plot | ||
fig_filename = os.path.join(Floodpy_app.Results_dir, '{}.svg'.format(Floodpy_app.flood_event)) | ||
plt.savefig(fig_filename,format="svg") | ||
# plt.close() | ||
print('The figure can be found at: {}'.format(fig_filename)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters