OttoYu commited on
Commit
3ab1083
·
verified ·
1 Parent(s): d4bea00

Update pages/8_Rainfall.py

Browse files
Files changed (1) hide show
  1. pages/8_Rainfall.py +8 -5
pages/8_Rainfall.py CHANGED
@@ -2,14 +2,13 @@ import streamlit as st
2
  import requests
3
  from datetime import datetime, timedelta
4
  from pytz import timezone
5
- from PIL import Image
6
  from io import BytesIO
7
  import time
8
  import folium
9
  import base64
10
  import pandas as pd
11
  import numpy as np
12
- import plotly.graph_objs as go
13
 
14
  st.set_page_config(layout="wide", page_title="Rainfall Data Dashboard")
15
 
@@ -62,8 +61,12 @@ def filter_image_by_color(image, colors_to_extract_rgb):
62
  img_array[~color_mask] = [255, 255, 255, 0]
63
  return Image.fromarray(img_array)
64
 
 
 
 
65
  def create_map_with_radar_tile(image):
66
  filtered_image = filter_image_by_color(image, COLORS_TO_EXTRACT_RGB)
 
67
  m = folium.Map(location=[22.364, 114.148], zoom_start=10, min_zoom=10, max_zoom=19,
68
  tiles='https://mapapi.geodata.gov.hk/gs/api/v1.0.0/xyz/imagery/wgs84/{z}/{x}/{y}.png',
69
  attr="Map information from Lands Department", control_scale=True, name="Basemap")
@@ -73,12 +76,12 @@ def create_map_with_radar_tile(image):
73
  overlay=True,
74
  name="Labels"
75
  ).add_to(m)
76
- img_url = f"data:image/png;base64,{image_to_base64(filtered_image)}"
77
  folium.raster_layers.ImageOverlay(
78
  image=img_url,
79
  name="HKO Radar Image",
80
  bounds=[[22.893, 113.538], [21.716, 115.362]],
81
- opacity=0.75,
82
  interactive=False,
83
  cross_origin=False,
84
  zindex=1,
@@ -158,7 +161,7 @@ with col1:
158
  # Create and display the map
159
  map_html = create_map_with_radar_tile(image)
160
  map_placeholder.empty()
161
- map_placeholder = st.components.v1.html(map_html,height = 750)
162
 
163
  if actual_time != interval:
164
  info_placeholder.warning(
 
2
  import requests
3
  from datetime import datetime, timedelta
4
  from pytz import timezone
 
5
  from io import BytesIO
6
  import time
7
  import folium
8
  import base64
9
  import pandas as pd
10
  import numpy as np
11
+ from PIL import Image, ImageFilter
12
 
13
  st.set_page_config(layout="wide", page_title="Rainfall Data Dashboard")
14
 
 
61
  img_array[~color_mask] = [255, 255, 255, 0]
62
  return Image.fromarray(img_array)
63
 
64
+ def smooth_image(image):
65
+ return image.filter(ImageFilter.GaussianBlur(radius=3))
66
+
67
  def create_map_with_radar_tile(image):
68
  filtered_image = filter_image_by_color(image, COLORS_TO_EXTRACT_RGB)
69
+ smoothed_image = smooth_image(filtered_image)
70
  m = folium.Map(location=[22.364, 114.148], zoom_start=10, min_zoom=10, max_zoom=19,
71
  tiles='https://mapapi.geodata.gov.hk/gs/api/v1.0.0/xyz/imagery/wgs84/{z}/{x}/{y}.png',
72
  attr="Map information from Lands Department", control_scale=True, name="Basemap")
 
76
  overlay=True,
77
  name="Labels"
78
  ).add_to(m)
79
+ img_url = f"data:image/png;base64,{image_to_base64(smoothed_image)}"
80
  folium.raster_layers.ImageOverlay(
81
  image=img_url,
82
  name="HKO Radar Image",
83
  bounds=[[22.893, 113.538], [21.716, 115.362]],
84
+ opacity=0.9,
85
  interactive=False,
86
  cross_origin=False,
87
  zindex=1,
 
161
  # Create and display the map
162
  map_html = create_map_with_radar_tile(image)
163
  map_placeholder.empty()
164
+ map_placeholder = st.components.v1.html(map_html,height=750)
165
 
166
  if actual_time != interval:
167
  info_placeholder.warning(