Spaces:
Sleeping
Sleeping
Update pages/6_Heat island.py
Browse files- pages/6_Heat island.py +24 -17
pages/6_Heat island.py
CHANGED
|
@@ -28,14 +28,14 @@ def compute_difference_geojson(geojson_2013, geojson_2023):
|
|
| 28 |
difference_geojson = {"type": "FeatureCollection", "features": []}
|
| 29 |
|
| 30 |
name_to_hot_nights_2013 = {
|
| 31 |
-
feature['properties']['NAME_EN']: feature['properties']['
|
| 32 |
for feature in geojson_2013['features']
|
| 33 |
}
|
| 34 |
|
| 35 |
for feature in geojson_2023['features']:
|
| 36 |
name_en = feature['properties']['NAME_EN']
|
| 37 |
hot_nights_2013 = name_to_hot_nights_2013.get(name_en, 0)
|
| 38 |
-
hot_nights_2023 = feature['properties']['
|
| 39 |
difference = hot_nights_2023 - hot_nights_2013
|
| 40 |
|
| 41 |
feature['properties']['Difference'] = difference
|
|
@@ -47,7 +47,7 @@ def geojson_to_dataframe(geojson_data, year):
|
|
| 47 |
features = geojson_data['features']
|
| 48 |
data = {
|
| 49 |
'District': [feature['properties']['NAME_EN'] for feature in features],
|
| 50 |
-
'
|
| 51 |
'Year': [year] * len(features) # Add year column
|
| 52 |
}
|
| 53 |
return pd.DataFrame(data)
|
|
@@ -55,8 +55,8 @@ def geojson_to_dataframe(geojson_data, year):
|
|
| 55 |
geojson_2013 = load_geojson('ref/2013_hot.geojson')
|
| 56 |
geojson_2023 = load_geojson('ref/2023_hot.geojson')
|
| 57 |
|
| 58 |
-
hot_nights_2013 = [feature['properties']['
|
| 59 |
-
hot_nights_2023 = [feature['properties']['
|
| 60 |
all_hot_nights = hot_nights_2013 + hot_nights_2023
|
| 61 |
|
| 62 |
colormap = folium.LinearColormap(
|
|
@@ -69,31 +69,38 @@ colormap = folium.LinearColormap(
|
|
| 69 |
difference_geojson = compute_difference_geojson(geojson_2013, geojson_2023)
|
| 70 |
|
| 71 |
diff_colormap = folium.LinearColormap(
|
| 72 |
-
colors=['blue', 'lightblue', 'white', '
|
| 73 |
-
index=[-
|
| 74 |
-
vmin=-
|
| 75 |
vmax=50,
|
| 76 |
caption='Change in Hot Nights'
|
| 77 |
)
|
| 78 |
|
| 79 |
-
m = folium.Map(location=[22.35994791346238, 114.15924623933743], zoom_start=11, tiles='https://landsd.azure-api.net/dev/osm/xyz/basemap/gs/WGS84/tile/{z}/{x}/{y}.png?key=f4d3e21d4fc14954a1d5930d4dde3809',attr="Map
|
|
|
|
| 80 |
folium.TileLayer(
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
feature_group_2013 = folium.FeatureGroup(name='2013 Hot Nights', show=False)
|
| 85 |
feature_group_2023 = folium.FeatureGroup(name='2023 Hot Nights', show=False)
|
| 86 |
feature_group_diff = folium.FeatureGroup(name='Change in Hot Nights', show=True)
|
| 87 |
|
| 88 |
-
plot_geojson(feature_group_2013, geojson_2013, '
|
| 89 |
-
plot_geojson(feature_group_2023, geojson_2023, '
|
| 90 |
plot_geojson(feature_group_diff, difference_geojson, 'Difference', diff_colormap)
|
| 91 |
|
| 92 |
feature_group_2013.add_to(m)
|
| 93 |
feature_group_2023.add_to(m)
|
| 94 |
feature_group_diff.add_to(m)
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
colormap.add_to(m)
|
| 99 |
diff_colormap.add_to(m)
|
|
@@ -107,9 +114,9 @@ def plot_combined_box_plot(df):
|
|
| 107 |
fig = px.box(
|
| 108 |
df,
|
| 109 |
x='Year',
|
| 110 |
-
y='
|
| 111 |
title='Hot Nights (2013 vs 2023)',
|
| 112 |
-
labels={'
|
| 113 |
color='Year'
|
| 114 |
)
|
| 115 |
fig.update_layout(
|
|
@@ -183,4 +190,4 @@ with col3:
|
|
| 183 |
st.caption(
|
| 184 |
'From data from the CO-WIN network, there has been a significant increase in the number of hot nights in Hong Kong. "Hot nights" refers to nights where the temperature remains above 28 degrees. Within the period from 2013 to 2023, 9 districts in Hong Kong have experienced an increase in the frequency of hot nights, the most significant are those in the urban.')
|
| 185 |
|
| 186 |
-
st.plotly_chart(plot_combined_box_plot(combined_df), use_container_width=True ,height=380)
|
|
|
|
| 28 |
difference_geojson = {"type": "FeatureCollection", "features": []}
|
| 29 |
|
| 30 |
name_to_hot_nights_2013 = {
|
| 31 |
+
feature['properties']['NAME_EN']: feature['properties']['Hot_nights']
|
| 32 |
for feature in geojson_2013['features']
|
| 33 |
}
|
| 34 |
|
| 35 |
for feature in geojson_2023['features']:
|
| 36 |
name_en = feature['properties']['NAME_EN']
|
| 37 |
hot_nights_2013 = name_to_hot_nights_2013.get(name_en, 0)
|
| 38 |
+
hot_nights_2023 = feature['properties']['Hot_nights']
|
| 39 |
difference = hot_nights_2023 - hot_nights_2013
|
| 40 |
|
| 41 |
feature['properties']['Difference'] = difference
|
|
|
|
| 47 |
features = geojson_data['features']
|
| 48 |
data = {
|
| 49 |
'District': [feature['properties']['NAME_EN'] for feature in features],
|
| 50 |
+
'Hot_nights': [feature['properties']['Hot_nights'] for feature in features],
|
| 51 |
'Year': [year] * len(features) # Add year column
|
| 52 |
}
|
| 53 |
return pd.DataFrame(data)
|
|
|
|
| 55 |
geojson_2013 = load_geojson('ref/2013_hot.geojson')
|
| 56 |
geojson_2023 = load_geojson('ref/2023_hot.geojson')
|
| 57 |
|
| 58 |
+
hot_nights_2013 = [feature['properties']['Hot_nights'] for feature in geojson_2013['features']]
|
| 59 |
+
hot_nights_2023 = [feature['properties']['Hot_nights'] for feature in geojson_2023['features']]
|
| 60 |
all_hot_nights = hot_nights_2013 + hot_nights_2023
|
| 61 |
|
| 62 |
colormap = folium.LinearColormap(
|
|
|
|
| 69 |
difference_geojson = compute_difference_geojson(geojson_2013, geojson_2023)
|
| 70 |
|
| 71 |
diff_colormap = folium.LinearColormap(
|
| 72 |
+
colors=['blue', 'lightblue', 'white', 'yellow', 'red'],
|
| 73 |
+
index=[-20, -5, 0, 10, 50],
|
| 74 |
+
vmin=-20,
|
| 75 |
vmax=50,
|
| 76 |
caption='Change in Hot Nights'
|
| 77 |
)
|
| 78 |
|
| 79 |
+
m = folium.Map(location=[22.35994791346238, 114.15924623933743], zoom_start=11, tiles='https://landsd.azure-api.net/dev/osm/xyz/basemap/gs/WGS84/tile/{z}/{x}/{y}.png?key=f4d3e21d4fc14954a1d5930d4dde3809', attr="Map information from Lands Department", control_scale=True)
|
| 80 |
+
|
| 81 |
folium.TileLayer(
|
| 82 |
+
tiles='https://mapapi.geodata.gov.hk/gs/api/v1.0.0/xyz/label/hk/en/wgs84/{z}/{x}/{y}.png',
|
| 83 |
+
attr="Map information from Lands Department",
|
| 84 |
+
overlay=True,
|
| 85 |
+
name="Labels"
|
| 86 |
+
).add_to(m)
|
| 87 |
|
| 88 |
feature_group_2013 = folium.FeatureGroup(name='2013 Hot Nights', show=False)
|
| 89 |
feature_group_2023 = folium.FeatureGroup(name='2023 Hot Nights', show=False)
|
| 90 |
feature_group_diff = folium.FeatureGroup(name='Change in Hot Nights', show=True)
|
| 91 |
|
| 92 |
+
plot_geojson(feature_group_2013, geojson_2013, 'Hot_nights', colormap)
|
| 93 |
+
plot_geojson(feature_group_2023, geojson_2023, 'Hot_nights', colormap)
|
| 94 |
plot_geojson(feature_group_diff, difference_geojson, 'Difference', diff_colormap)
|
| 95 |
|
| 96 |
feature_group_2013.add_to(m)
|
| 97 |
feature_group_2023.add_to(m)
|
| 98 |
feature_group_diff.add_to(m)
|
| 99 |
|
| 100 |
+
folium.LayerControl().add_to(m)
|
| 101 |
+
|
| 102 |
+
colormap.add_to(m)
|
| 103 |
+
diff_colormap.add_to(m)
|
| 104 |
|
| 105 |
colormap.add_to(m)
|
| 106 |
diff_colormap.add_to(m)
|
|
|
|
| 114 |
fig = px.box(
|
| 115 |
df,
|
| 116 |
x='Year',
|
| 117 |
+
y='Hot_nights',
|
| 118 |
title='Hot Nights (2013 vs 2023)',
|
| 119 |
+
labels={'Hot_nights': 'Number of Hot Nights', 'Year': 'Year'},
|
| 120 |
color='Year'
|
| 121 |
)
|
| 122 |
fig.update_layout(
|
|
|
|
| 190 |
st.caption(
|
| 191 |
'From data from the CO-WIN network, there has been a significant increase in the number of hot nights in Hong Kong. "Hot nights" refers to nights where the temperature remains above 28 degrees. Within the period from 2013 to 2023, 9 districts in Hong Kong have experienced an increase in the frequency of hot nights, the most significant are those in the urban.')
|
| 192 |
|
| 193 |
+
st.plotly_chart(plot_combined_box_plot(combined_df), use_container_width=True ,height=380)
|