“Namhyun-Kim” commited on
Commit
3be3431
·
1 Parent(s): 820f773

Order SNR legends and dropdowns

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -321,6 +321,10 @@ def plot_tsne(
321
  sampled_df["x"] = projections[:, 0]
322
  sampled_df["y"] = projections[:, 1]
323
 
 
 
 
 
324
  fig = px.scatter(
325
  sampled_df,
326
  x="x",
@@ -329,6 +333,7 @@ def plot_tsne(
329
  hover_data=["tech", "snr", "mod", "mob"],
330
  title=f"t-SNE of {representation} ({len(sampled_df)} samples)",
331
  template="plotly_white",
 
332
  )
333
  height = 680 if color_label == "SNR" else 640
334
  fig.update_layout(legend_title_text=color_label, width=640, height=height)
@@ -700,7 +705,7 @@ has_moe_column = df["moe_embedding"].apply(lambda x: x is not None)
700
  joint_eval_df = df[has_moe_column & df["joint_label_id"].notna()]
701
 
702
  tech_choices = sorted(df["tech"].unique())
703
- snr_choices = sorted(df["snr"].unique())
704
  mod_choices = sorted(df["mod"].unique())
705
  mob_choices = sorted(df["mob"].unique())
706
 
@@ -713,9 +718,10 @@ COLOR_OPTIONS: Dict[str, str] = {
713
  "Modulation": "mod",
714
  "Mobility": "mob",
715
  }
 
716
  TECH_EXPERT_ORDER = ["LTE", "WiFi", "5G"]
717
  TECH_TO_EXPERT_IDX = {name: idx for idx, name in enumerate(TECH_EXPERT_ORDER)}
718
- DEFAULT_TSNE_SAMPLES_PER_SNR = 200
719
 
720
  default_tech = tech_choices[:1] if tech_choices else []
721
  initial_spec_mod_choices = TECH_TO_MODS.get(default_tech[0], mod_choices) if default_tech else mod_choices
@@ -727,6 +733,11 @@ def update_modulation_choices(selected_tech: Optional[str]):
727
  choices = TECH_TO_MODS.get(selected_tech, mod_choices)
728
  return gr.Dropdown.update(choices=choices, value=None)
729
 
 
 
 
 
 
730
  with gr.Blocks(title="LWM-Spectro Lab") as demo:
731
  gr.Markdown("# 🔬 LWM-Spectro Interactive Demo")
732
  gr.Markdown(
 
321
  sampled_df["x"] = projections[:, 0]
322
  sampled_df["y"] = projections[:, 1]
323
 
324
+ category_orders = {}
325
+ if color_column == "snr":
326
+ category_orders["snr"] = [snr for snr in SNR_ORDER if snr in sampled_df["snr"].unique()]
327
+
328
  fig = px.scatter(
329
  sampled_df,
330
  x="x",
 
333
  hover_data=["tech", "snr", "mod", "mob"],
334
  title=f"t-SNE of {representation} ({len(sampled_df)} samples)",
335
  template="plotly_white",
336
+ category_orders=category_orders,
337
  )
338
  height = 680 if color_label == "SNR" else 640
339
  fig.update_layout(legend_title_text=color_label, width=640, height=height)
 
705
  joint_eval_df = df[has_moe_column & df["joint_label_id"].notna()]
706
 
707
  tech_choices = sorted(df["tech"].unique())
708
+ snr_choices = _sort_snrs(df["snr"].unique())
709
  mod_choices = sorted(df["mod"].unique())
710
  mob_choices = sorted(df["mob"].unique())
711
 
 
718
  "Modulation": "mod",
719
  "Mobility": "mob",
720
  }
721
+ SNR_ORDER = ["SNR-5dB", "SNR0dB", "SNR5dB", "SNR10dB", "SNR15dB", "SNR20dB", "SNR25dB"]
722
  TECH_EXPERT_ORDER = ["LTE", "WiFi", "5G"]
723
  TECH_TO_EXPERT_IDX = {name: idx for idx, name in enumerate(TECH_EXPERT_ORDER)}
724
+ DEFAULT_TSNE_SAMPLES_PER_SNR = 500
725
 
726
  default_tech = tech_choices[:1] if tech_choices else []
727
  initial_spec_mod_choices = TECH_TO_MODS.get(default_tech[0], mod_choices) if default_tech else mod_choices
 
733
  choices = TECH_TO_MODS.get(selected_tech, mod_choices)
734
  return gr.Dropdown.update(choices=choices, value=None)
735
 
736
+
737
+ def _sort_snrs(labels: List[str] | np.ndarray) -> List[str]:
738
+ ordering = {snr: idx for idx, snr in enumerate(SNR_ORDER)}
739
+ return sorted(labels, key=lambda x: ordering.get(x, len(ordering)))
740
+
741
  with gr.Blocks(title="LWM-Spectro Lab") as demo:
742
  gr.Markdown("# 🔬 LWM-Spectro Interactive Demo")
743
  gr.Markdown(