cleanup: update app.py
Browse files
app.py
CHANGED
|
@@ -175,7 +175,7 @@ def compute_convective_core_masks(ir_data):
|
|
| 175 |
# ------------------ Streamlit UI ------------------
|
| 176 |
st.set_page_config(page_title="TCIR Daily Input", layout="wide")
|
| 177 |
|
| 178 |
-
st.title("Tropical Cyclone
|
| 179 |
|
| 180 |
ir_images = st.file_uploader("Upload 8 IR images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
| 181 |
pmw_images = st.file_uploader("Upload 8 PMW images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
|
@@ -188,16 +188,6 @@ else:
|
|
| 188 |
st.header("Input Latitude, Longitude, Vmax")
|
| 189 |
lat_values, lon_values, vmax_values = [], [], []
|
| 190 |
|
| 191 |
-
# col1, col2, col3 = st.columns(3)
|
| 192 |
-
# with col1:
|
| 193 |
-
# for i in range(8):
|
| 194 |
-
# lat_values.append(st.number_input(f"Latitude {i+1}", key=f"lat{i}"))
|
| 195 |
-
# with col2:
|
| 196 |
-
# for i in range(8):
|
| 197 |
-
# lon_values.append(st.number_input(f"Longitude {i+1}", key=f"lon{i}"))
|
| 198 |
-
# with col3:
|
| 199 |
-
# for i in range(8):
|
| 200 |
-
# vmax_values.append(st.number_input(f"Vmax {i+1}", key=f"vmax{i}"))
|
| 201 |
import pandas as pd
|
| 202 |
|
| 203 |
import numpy as np
|
|
@@ -220,7 +210,6 @@ if csv_file is not None:
|
|
| 220 |
vmax_values = np.array(vmax_values)
|
| 221 |
|
| 222 |
st.success("CSV file loaded and processed successfully!")
|
| 223 |
-
# Optional: Show dataframe or data shape
|
| 224 |
st.write(df.head())
|
| 225 |
|
| 226 |
else:
|
|
@@ -258,24 +247,18 @@ if st.button("Submit for Processing"):
|
|
| 258 |
elif model_choice == "spatiotemporalLSTM":
|
| 259 |
from spaio_temp import predict_stlstm
|
| 260 |
model_predict_fn = predict_stlstm
|
| 261 |
-
|
| 262 |
-
# from convlstm import predict_lstm
|
| 263 |
-
# from cnn3d import predict_3dcnn
|
| 264 |
-
# from trjgru import predict_trajgru
|
| 265 |
-
# from spaio_temp import predict_stlstm
|
| 266 |
-
# from unetlstm import predict_unetlstm
|
| 267 |
ir_arrays = []
|
| 268 |
pmw_arrays = []
|
| 269 |
train_vmax_2d = reshape_vmax(np.array(vmax_values))
|
| 270 |
-
|
| 271 |
train_vmax_3d= create_3d_vmax(train_vmax_2d)
|
| 272 |
-
|
| 273 |
lat_processed = process_lat_values(lat_values)
|
| 274 |
lon_processed = process_lon_values(lon_values)
|
| 275 |
-
|
| 276 |
-
# st.write("Lon 2D shape:", lon_processed.shape)
|
| 277 |
v_max_diff = calculate_intensity_difference(train_vmax_2d)
|
| 278 |
-
|
| 279 |
for ir in ir_images:
|
| 280 |
img = Image.open(ir).convert("L")
|
| 281 |
arr = np.array(img).astype(np.float32)
|
|
@@ -290,50 +273,26 @@ if st.button("Submit for Processing"):
|
|
| 290 |
pmw_arrays.append(resized)
|
| 291 |
ir=np.array(ir_arrays)
|
| 292 |
pmw=np.array(pmw_arrays)
|
|
|
|
| 293 |
# Stack into (8, 95, 95)
|
| 294 |
ir_seq = process_images(ir)
|
| 295 |
pmw_seq = process_images(pmw)
|
| 296 |
|
| 297 |
-
# st.write(f"IR sequence shape: {ir_seq.shape}")
|
| 298 |
-
# st.write(f"PMW sequence shape: {pmw_seq.shape}")
|
| 299 |
|
| 300 |
# For demonstration: create batches
|
| 301 |
X_train_new = ir_seq.reshape((1, 8, 95, 95)) # Shape: (1, 8, 95, 95)
|
| 302 |
-
|
| 303 |
-
# st.write(f"X_train_new shape: {X_train_new.shape}")
|
| 304 |
cc_mask= compute_convective_core_masks(X_train_new)
|
| 305 |
-
# st.write("CC Mask Shape:", cc_mask.shape)
|
| 306 |
hov_m_train = generate_hovmoller(X_train_new)
|
| 307 |
-
# hov_m_test = generate_hovmoller(X_test_new)
|
| 308 |
-
# hov_m_valid = generate_hovmoller(X_valid)
|
| 309 |
hov_m_train[np.isnan(hov_m_train)] = 0
|
| 310 |
hov_m_train = hov_m_train.transpose(0, 2, 3, 1)
|
| 311 |
-
|
| 312 |
-
# st.write("Hovmöller Train Shape:", hov_m_train.shape)
|
| 313 |
-
# st.write("Hovmöller Test Shape:", hov_m_test.shape)
|
| 314 |
-
# st.write("Hovmöller Valid Shape:", hov_m_valid.shape)
|
| 315 |
-
|
| 316 |
-
# Visualize first sample
|
| 317 |
-
# st.subheader("Hovmöller Sample (Train Set)")
|
| 318 |
-
# for t in range(8):
|
| 319 |
-
# st.image(hov_m_train[0, t], caption=f"Time Step {t+1}", clamp=True, width=150)
|
| 320 |
-
# st.write(hov_m_train[0,0])
|
| 321 |
cc_mask[np.isnan(cc_mask)] = 0
|
| 322 |
cc_mask=cc_mask.reshape(1, 8, 95, 95, 1)
|
| 323 |
i_images=cc_mask+ir_seq
|
| 324 |
reduced_images = np.concatenate([i_images,pmw_seq ], axis=-1)
|
| 325 |
reduced_images[np.isnan(reduced_images)] = 0
|
| 326 |
-
|
| 327 |
-
# y=np.isnan(reduced_images).sum()
|
| 328 |
-
# st.write("Reduced Images NaN Count:", y)
|
| 329 |
-
# model_predict_fn = {
|
| 330 |
-
# "ConvGRU": predict,
|
| 331 |
-
# "ConvLSTM": predict_lstm,
|
| 332 |
-
# "3DCNN":predict_3dcnn,
|
| 333 |
-
# "Traj-GRU": predict_trajgru,
|
| 334 |
-
# "spatiotemporalLSTM": predict_stlstm,
|
| 335 |
-
# "Unet_LSTM": predict_unetlstm,
|
| 336 |
-
# }[model_choice]
|
| 337 |
if model_choice == "Unet_LSTM":
|
| 338 |
import tensorflow as tf
|
| 339 |
|
|
|
|
| 175 |
# ------------------ Streamlit UI ------------------
|
| 176 |
st.set_page_config(page_title="TCIR Daily Input", layout="wide")
|
| 177 |
|
| 178 |
+
st.title("Tropical Cyclone U-Net Wind Speed (Intensity) Predictor")
|
| 179 |
|
| 180 |
ir_images = st.file_uploader("Upload 8 IR images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
| 181 |
pmw_images = st.file_uploader("Upload 8 PMW images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
|
|
|
| 188 |
st.header("Input Latitude, Longitude, Vmax")
|
| 189 |
lat_values, lon_values, vmax_values = [], [], []
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
import pandas as pd
|
| 192 |
|
| 193 |
import numpy as np
|
|
|
|
| 210 |
vmax_values = np.array(vmax_values)
|
| 211 |
|
| 212 |
st.success("CSV file loaded and processed successfully!")
|
|
|
|
| 213 |
st.write(df.head())
|
| 214 |
|
| 215 |
else:
|
|
|
|
| 247 |
elif model_choice == "spatiotemporalLSTM":
|
| 248 |
from spaio_temp import predict_stlstm
|
| 249 |
model_predict_fn = predict_stlstm
|
| 250 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
ir_arrays = []
|
| 252 |
pmw_arrays = []
|
| 253 |
train_vmax_2d = reshape_vmax(np.array(vmax_values))
|
| 254 |
+
|
| 255 |
train_vmax_3d= create_3d_vmax(train_vmax_2d)
|
| 256 |
+
|
| 257 |
lat_processed = process_lat_values(lat_values)
|
| 258 |
lon_processed = process_lon_values(lon_values)
|
| 259 |
+
|
|
|
|
| 260 |
v_max_diff = calculate_intensity_difference(train_vmax_2d)
|
| 261 |
+
|
| 262 |
for ir in ir_images:
|
| 263 |
img = Image.open(ir).convert("L")
|
| 264 |
arr = np.array(img).astype(np.float32)
|
|
|
|
| 273 |
pmw_arrays.append(resized)
|
| 274 |
ir=np.array(ir_arrays)
|
| 275 |
pmw=np.array(pmw_arrays)
|
| 276 |
+
|
| 277 |
# Stack into (8, 95, 95)
|
| 278 |
ir_seq = process_images(ir)
|
| 279 |
pmw_seq = process_images(pmw)
|
| 280 |
|
|
|
|
|
|
|
| 281 |
|
| 282 |
# For demonstration: create batches
|
| 283 |
X_train_new = ir_seq.reshape((1, 8, 95, 95)) # Shape: (1, 8, 95, 95)
|
| 284 |
+
|
|
|
|
| 285 |
cc_mask= compute_convective_core_masks(X_train_new)
|
|
|
|
| 286 |
hov_m_train = generate_hovmoller(X_train_new)
|
|
|
|
|
|
|
| 287 |
hov_m_train[np.isnan(hov_m_train)] = 0
|
| 288 |
hov_m_train = hov_m_train.transpose(0, 2, 3, 1)
|
| 289 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
cc_mask[np.isnan(cc_mask)] = 0
|
| 291 |
cc_mask=cc_mask.reshape(1, 8, 95, 95, 1)
|
| 292 |
i_images=cc_mask+ir_seq
|
| 293 |
reduced_images = np.concatenate([i_images,pmw_seq ], axis=-1)
|
| 294 |
reduced_images[np.isnan(reduced_images)] = 0
|
| 295 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
if model_choice == "Unet_LSTM":
|
| 297 |
import tensorflow as tf
|
| 298 |
|