clean up stop thread
Browse files- .DS_Store +0 -0
- pages/01-main.py +15 -12
- public/.DS_Store +0 -0
- public/ee_cnn.py +4 -3
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
pages/01-main.py
CHANGED
@@ -73,7 +73,6 @@ status_message = solara.reactive("Ready to start.")
|
|
73 |
timer_value = solara.reactive(0)
|
74 |
|
75 |
available_dates = solara.reactive(None)
|
76 |
-
|
77 |
selected_coordinates = solara.reactive(None)
|
78 |
selected_country = solara.reactive(None)
|
79 |
|
@@ -81,7 +80,7 @@ selected_country = solara.reactive(None)
|
|
81 |
thread_running = threading.Event() # A simple event to signal the thread.
|
82 |
|
83 |
@solara.component
|
84 |
-
def ModelControl(running, status_message):
|
85 |
|
86 |
def start_model():
|
87 |
running.value = True
|
@@ -89,12 +88,14 @@ def ModelControl(running, status_message):
|
|
89 |
|
90 |
|
91 |
def stop_model():
|
92 |
-
running.value = False
|
93 |
-
print(running)
|
94 |
-
timer_value.value = 0
|
95 |
-
thread_running.wait()
|
96 |
thread_running.clear() # Signal the thread to stop.
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
if running.value:
|
100 |
return solara.Button(label="Stop Execution",
|
@@ -129,11 +130,11 @@ def StatusBar(status_message, timer_value):
|
|
129 |
if timer_value.value == 1:
|
130 |
solara.ProgressLinear(True, color= 'green')
|
131 |
elif timer_value.value == 0:
|
132 |
-
solara.ProgressLinear(False
|
133 |
|
134 |
if status_message.value == "Ready to start." or status_message.value == "Model is running...":
|
135 |
solara.Info(f"Status: {status_message.value}")
|
136 |
-
elif status_message.value == "Model stopped by user.":
|
137 |
solara.Warning(f"Status: {status_message.value}")
|
138 |
elif status_message.value == 'Requires Date Selection':
|
139 |
solara.Error(f"Status: {status_message.value}")
|
@@ -170,16 +171,18 @@ def CombinedThread(running, timer_value, status_message, available_dates, select
|
|
170 |
# Reset after model completion.
|
171 |
status_message.value = "Model run complete!"
|
172 |
running.value = False
|
|
|
173 |
thread_running.clear()
|
|
|
174 |
|
175 |
|
176 |
elif not available_dates.value:
|
177 |
status_message.value = 'Requires Date Selection'
|
178 |
running.value = False
|
179 |
-
|
180 |
thread_running.clear()
|
181 |
timer_value.value = 0
|
182 |
-
|
183 |
|
184 |
|
185 |
|
@@ -220,7 +223,7 @@ def Page():
|
|
220 |
display( map_ui.display_map())
|
221 |
|
222 |
# Control buttons
|
223 |
-
ModelControl(running, status_message)
|
224 |
# Call the CombinedThread
|
225 |
CombinedThread(running, timer_value, status_message, available_dates, selected_coordinates, selected_country)
|
226 |
# Status display
|
|
|
73 |
timer_value = solara.reactive(0)
|
74 |
|
75 |
available_dates = solara.reactive(None)
|
|
|
76 |
selected_coordinates = solara.reactive(None)
|
77 |
selected_country = solara.reactive(None)
|
78 |
|
|
|
80 |
thread_running = threading.Event() # A simple event to signal the thread.
|
81 |
|
82 |
@solara.component
|
83 |
+
def ModelControl(running, status_message,available_dates,selected_coordinates,selected_country ):
|
84 |
|
85 |
def start_model():
|
86 |
running.value = True
|
|
|
88 |
|
89 |
|
90 |
def stop_model():
|
|
|
|
|
|
|
|
|
91 |
thread_running.clear() # Signal the thread to stop.
|
92 |
+
running.value = False
|
93 |
+
timer_value.value = 0
|
94 |
+
status_message.value = "Model stopped by user.Reselect Dates and Region."
|
95 |
+
available_dates.value = None
|
96 |
+
selected_coordinates.value = None
|
97 |
+
selected_country.value = None
|
98 |
+
|
99 |
|
100 |
if running.value:
|
101 |
return solara.Button(label="Stop Execution",
|
|
|
130 |
if timer_value.value == 1:
|
131 |
solara.ProgressLinear(True, color= 'green')
|
132 |
elif timer_value.value == 0:
|
133 |
+
solara.ProgressLinear(False)
|
134 |
|
135 |
if status_message.value == "Ready to start." or status_message.value == "Model is running...":
|
136 |
solara.Info(f"Status: {status_message.value}")
|
137 |
+
elif status_message.value == "Model stopped by user.Reselect Dates and Region.":
|
138 |
solara.Warning(f"Status: {status_message.value}")
|
139 |
elif status_message.value == 'Requires Date Selection':
|
140 |
solara.Error(f"Status: {status_message.value}")
|
|
|
171 |
# Reset after model completion.
|
172 |
status_message.value = "Model run complete!"
|
173 |
running.value = False
|
174 |
+
thread_running.wait()
|
175 |
thread_running.clear()
|
176 |
+
return final_df
|
177 |
|
178 |
|
179 |
elif not available_dates.value:
|
180 |
status_message.value = 'Requires Date Selection'
|
181 |
running.value = False
|
182 |
+
thread_running.wait()
|
183 |
thread_running.clear()
|
184 |
timer_value.value = 0
|
185 |
+
|
186 |
|
187 |
|
188 |
|
|
|
223 |
display( map_ui.display_map())
|
224 |
|
225 |
# Control buttons
|
226 |
+
ModelControl(running, status_message,available_dates, selected_coordinates, selected_country )
|
227 |
# Call the CombinedThread
|
228 |
CombinedThread(running, timer_value, status_message, available_dates, selected_coordinates, selected_country)
|
229 |
# Status display
|
public/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
public/ee_cnn.py
CHANGED
@@ -11,6 +11,8 @@ import datetime as dt
|
|
11 |
import keras
|
12 |
import keras as k
|
13 |
import keras.backend as kr
|
|
|
|
|
14 |
import multiprocessing as mp
|
15 |
from pysolar.solar import get_altitude_fast
|
16 |
import tensorflow as tf
|
@@ -288,7 +290,7 @@ def CNN(dates_list, coordinates=None, country = None):
|
|
288 |
|
289 |
|
290 |
num_cores = mp.cpu_count()
|
291 |
-
with mp.Pool(num_cores
|
292 |
a = pool.imap(get_SZA, DF[["Date",'lat', 'lon']].itertuples(name=None), chunksize=10)
|
293 |
DF['SZA'] = [x for x in a]
|
294 |
|
@@ -309,15 +311,14 @@ def CNN(dates_list, coordinates=None, country = None):
|
|
309 |
|
310 |
# Get the project root directory
|
311 |
project_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
312 |
-
|
313 |
module_path = os.path.join(project_root, 'public')
|
314 |
-
print(module_path)
|
315 |
# Add the module path to the Python path
|
316 |
sys.path.append(module_path)
|
317 |
|
318 |
|
319 |
MODEL = os.path.join(project_root,'public', 'Models/')
|
320 |
SCALAR = os.path.join(project_root,'public', 'Scalars/')
|
|
|
321 |
|
322 |
|
323 |
#SCALAR = DP + "/Scalars/" # Universal Scalers
|
|
|
11 |
import keras
|
12 |
import keras as k
|
13 |
import keras.backend as kr
|
14 |
+
import keras.losses
|
15 |
+
import h5py
|
16 |
import multiprocessing as mp
|
17 |
from pysolar.solar import get_altitude_fast
|
18 |
import tensorflow as tf
|
|
|
290 |
|
291 |
|
292 |
num_cores = mp.cpu_count()
|
293 |
+
with mp.Pool(num_cores) as pool:
|
294 |
a = pool.imap(get_SZA, DF[["Date",'lat', 'lon']].itertuples(name=None), chunksize=10)
|
295 |
DF['SZA'] = [x for x in a]
|
296 |
|
|
|
311 |
|
312 |
# Get the project root directory
|
313 |
project_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
|
314 |
module_path = os.path.join(project_root, 'public')
|
|
|
315 |
# Add the module path to the Python path
|
316 |
sys.path.append(module_path)
|
317 |
|
318 |
|
319 |
MODEL = os.path.join(project_root,'public', 'Models/')
|
320 |
SCALAR = os.path.join(project_root,'public', 'Scalars/')
|
321 |
+
|
322 |
|
323 |
|
324 |
#SCALAR = DP + "/Scalars/" # Universal Scalers
|