UCS2014 commited on
Commit
fafebcc
·
verified ·
1 Parent(s): b6e23ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -288,6 +288,15 @@ def cross_plot_static(actual, pred):
288
  # Track plot (Plotly)
289
  # =========================
290
  def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
 
 
 
 
 
 
 
 
 
291
  depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
292
  if depth_col is not None:
293
  y = pd.Series(df[depth_col]).astype(float)
@@ -299,9 +308,14 @@ def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
299
  y_range = [float(y.max()), float(y.min())]
300
 
301
  # X (GR) range & ticks
302
- x_series = pd.Series(df.get(pred_col, pd.Series(dtype=float))).astype(float)
303
  if include_actual and actual_col in df.columns:
304
- x_series = pd.concat([x_series, pd.Series(df[actual_col]).astype(float)], ignore_index=True)
 
 
 
 
 
305
  x_lo, x_hi = float(x_series.min()), float(x_series.max())
306
  x_pad = 0.03 * (x_hi - x_lo if x_hi > x_lo else 1.0)
307
  xmin, xmax = x_lo - x_pad, x_hi + x_pad
@@ -309,14 +323,14 @@ def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
309
 
310
  fig = go.Figure()
311
  fig.add_trace(go.Scatter(
312
- x=df[pred_col], y=y, mode="lines",
313
  line=dict(color=COLORS["pred"], width=1.8),
314
- name="GR_Pred",
315
  hovertemplate="GR_Pred: %{x:.0f}<br>"+ylab+": %{y}<extra></extra>"
316
  ))
317
- if include_actual and actual_col in df.columns:
318
  fig.add_trace(go.Scatter(
319
- x=df[actual_col], y=y, mode="lines",
320
  line=dict(color=COLORS["actual"], width=2.0, dash="dot"),
321
  name="GR (actual)",
322
  hovertemplate="GR (actual): %{x:.0f}<br>"+ylab+": %{y}<extra></extra>"
@@ -352,6 +366,7 @@ def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
352
  )
353
  return fig
354
 
 
355
  # ---------- Preview modal (matplotlib) ----------
356
  def preview_tracks(df: pd.DataFrame, cols: list[str]):
357
  cols = [c for c in cols if c in df.columns]
@@ -566,12 +581,11 @@ if st.session_state.app_step == "dev":
566
 
567
  col_track, col_cross = st.columns([2, 3], gap="large")
568
  with col_track:
569
- df_for_plot = df.rename(columns={"GR_Actual":"GR"})
570
- st.plotly_chart(
571
- track_plot(df_for_plot, include_actual=True, pred_col="GR_Pred", actual_col="GR"),
572
- use_container_width=False,
573
- config={"displayModeBar": False, "scrollZoom": True}
574
- )
575
  with col_cross:
576
  st.pyplot(cross_plot_static(df["GR_Actual"], df["GR_Pred"]), use_container_width=False)
577
 
@@ -653,11 +667,11 @@ if st.session_state.app_step == "validate":
653
 
654
  col_track, col_cross = st.columns([2, 3], gap="large")
655
  with col_track:
656
- st.plotly_chart(
657
- track_plot(st.session_state.results["Validate"].rename(columns={"GR_Actual":"GR"}),
658
- include_actual=True, pred_col="GR_Pred", actual_col="GR"),
659
- use_container_width=False, config={"displayModeBar": False, "scrollZoom": True}
660
- )
661
  with col_cross:
662
  st.pyplot(
663
  cross_plot_static(st.session_state.results["Validate"]["GR_Actual"],
 
288
  # Track plot (Plotly)
289
  # =========================
290
  def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
291
+ # --- helper to guarantee a 1D series even if there are duplicate column names
292
+ def _col_1d(frame: pd.DataFrame, col: str) -> pd.Series:
293
+ if col not in frame.columns:
294
+ return pd.Series(dtype=float)
295
+ v = frame[col]
296
+ if isinstance(v, pd.DataFrame): # happens when there are duplicate column names
297
+ v = v.iloc[:, 0]
298
+ return pd.Series(v, dtype=float)
299
+
300
  depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
301
  if depth_col is not None:
302
  y = pd.Series(df[depth_col]).astype(float)
 
308
  y_range = [float(y.max()), float(y.min())]
309
 
310
  # X (GR) range & ticks
311
+ x_pred = _col_1d(df, pred_col)
312
  if include_actual and actual_col in df.columns:
313
+ x_act = _col_1d(df, actual_col)
314
+ x_series = pd.concat([x_pred, x_act], ignore_index=True)
315
+ else:
316
+ x_act = None
317
+ x_series = x_pred
318
+
319
  x_lo, x_hi = float(x_series.min()), float(x_series.max())
320
  x_pad = 0.03 * (x_hi - x_lo if x_hi > x_lo else 1.0)
321
  xmin, xmax = x_lo - x_pad, x_hi + x_pad
 
323
 
324
  fig = go.Figure()
325
  fig.add_trace(go.Scatter(
326
+ x=x_pred, y=y, mode="lines",
327
  line=dict(color=COLORS["pred"], width=1.8),
328
+ name=pred_col,
329
  hovertemplate="GR_Pred: %{x:.0f}<br>"+ylab+": %{y}<extra></extra>"
330
  ))
331
+ if include_actual and x_act is not None:
332
  fig.add_trace(go.Scatter(
333
+ x=x_act, y=y, mode="lines",
334
  line=dict(color=COLORS["actual"], width=2.0, dash="dot"),
335
  name="GR (actual)",
336
  hovertemplate="GR (actual): %{x:.0f}<br>"+ylab+": %{y}<extra></extra>"
 
366
  )
367
  return fig
368
 
369
+
370
  # ---------- Preview modal (matplotlib) ----------
371
  def preview_tracks(df: pd.DataFrame, cols: list[str]):
372
  cols = [c for c in cols if c in df.columns]
 
581
 
582
  col_track, col_cross = st.columns([2, 3], gap="large")
583
  with col_track:
584
+ st.plotly_chart(
585
+ track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR_Actual"),
586
+ use_container_width=False,
587
+ config={"displayModeBar": False, "scrollZoom": True}
588
+ )
 
589
  with col_cross:
590
  st.pyplot(cross_plot_static(df["GR_Actual"], df["GR_Pred"]), use_container_width=False)
591
 
 
667
 
668
  col_track, col_cross = st.columns([2, 3], gap="large")
669
  with col_track:
670
+ st.plotly_chart(
671
+ track_plot(st.session_state.results["Validate"],
672
+ include_actual=True, pred_col="GR_Pred", actual_col="GR_Actual"),
673
+ use_container_width=False, config={"displayModeBar": False, "scrollZoom": True}
674
+ )
675
  with col_cross:
676
  st.pyplot(
677
  cross_plot_static(st.session_state.results["Validate"]["GR_Actual"],