Spaces:
Sleeping

rguilcas commited on
Commit
023c07b
·
verified ·
1 Parent(s): 516f61b

make precursors optionnal

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -157,6 +157,8 @@ class CMIPApp(param.Parameterized):
157
  _selection_index = param.List(default=[])
158
  # User-facing region selector for sidebar
159
  selected_regions = param.ListSelector(default=[], objects=list(gdf_regions.index), label="Selected Regions")
 
 
160
 
161
  # Shared color map for sectors
162
  sector_cmap = {
@@ -467,6 +469,7 @@ class CMIPApp(param.Parameterized):
467
  color='type', cmap=self.sector_cmap, alpha=1.0, line_width=0.5, line_color='grey', apply_ranges=False, tools=[]
468
  )
469
 
 
470
  # Add labels
471
  labels = [
472
  hv.Text(0, 0, 'minimal bias', fontsize=8),
@@ -480,7 +483,23 @@ class CMIPApp(param.Parameterized):
480
  hv.Text(70, -70, 'Cancelling', fontsize=9),
481
  ]
482
 
483
- return bg_polys * min_poly * hv.Overlay(labels)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
 
485
  @param.depends('model', 'season', 'term', 'nonlinear_pos', '_selection_index')
486
  def get_scatter_plot(self):
@@ -522,7 +541,10 @@ class CMIPApp(param.Parameterized):
522
  ylabel=y_label,
523
  frame_height=450,
524
  frame_width=500,
525
- hooks=[self.hook_scatter_selection]
 
 
 
526
  )
527
  if current_x_range and all(x is not None for x in current_x_range):
528
  opts['xlim'] = current_x_range
@@ -594,12 +616,16 @@ class CMIPApp(param.Parameterized):
594
  # Use HLine because axes are inverted
595
  vline_pos = hv.HLine(self.vmax).opts(color='red', line_dash='dashed', line_width=1.5, alpha=0.6)
596
  vline_neg = hv.HLine(-self.vmax).opts(color='red', line_dash='dashed', line_width=1.5, alpha=0.6)
 
597
 
598
- return pn.Column(bar_plot * vline_pos * vline_neg, width_policy='max', margin=(20, 0, 0, 20))
599
 
600
- @param.depends('_selection_index', 'season')
601
  def get_precursor_maps(self):
602
  """Display precursor maps (U850, V850, Z500) for selected regions in tabs."""
 
 
 
603
  if not self._selection_index:
604
  return pn.pane.Markdown("### Precursor maps: No region selected\n*Click on a map or scatter point to see precursor patterns*")
605
 
@@ -647,10 +673,14 @@ app = pn.template.MaterialTemplate(
647
  sidebar=[
648
  pn.Param(
649
  app_instance.param,
650
- parameters=['model', 'season', 'term', 'source', 'nonlinear_pos', 'vmax', 'selected_regions'],
651
  widgets={
652
  'nonlinear_pos': {
653
  'type': pn.widgets.Select,
 
 
 
 
654
  }
655
  }
656
  ),
 
157
  _selection_index = param.List(default=[])
158
  # User-facing region selector for sidebar
159
  selected_regions = param.ListSelector(default=[], objects=list(gdf_regions.index), label="Selected Regions")
160
+ # Toggle for performance-intensive precursor maps
161
+ show_precursors = param.Boolean(default=False, label="Show Precursor Maps (Slower)")
162
 
163
  # Shared color map for sectors
164
  sector_cmap = {
 
469
  color='type', cmap=self.sector_cmap, alpha=1.0, line_width=0.5, line_color='grey', apply_ranges=False, tools=[]
470
  )
471
 
472
+
473
  # Add labels
474
  labels = [
475
  hv.Text(0, 0, 'minimal bias', fontsize=8),
 
483
  hv.Text(70, -70, 'Cancelling', fontsize=9),
484
  ]
485
 
486
+ # Add constant apparent bias lines (x + y = k)
487
+ # k ranges from -140 to 140 in steps of 20, excluding 0
488
+ lines = []
489
+ for k in range(-140, 160, 20):
490
+ if k == 0: continue
491
+ # Line equation: y = -x + k
492
+ # Define points extending across the plot range
493
+ xs = np.array([-L, L])
494
+ ys = -xs + k
495
+ lines.append(hv.Curve((xs, ys)).opts(color='grey', line_width=0.5, line_dash='dashed', alpha=0.5))
496
+
497
+ # Add thicker line for 0 apparent bias (x+y=0)
498
+ xs = np.array([-L, L])
499
+ ys = -xs
500
+ lines.append(hv.Curve((xs, ys)).opts(color='black', line_width=1.0, line_dash='dashed', alpha=0.6))
501
+
502
+ return bg_polys * min_poly * hv.Overlay(lines).opts(apply_ranges=False) * hv.Overlay(labels)
503
 
504
  @param.depends('model', 'season', 'term', 'nonlinear_pos', '_selection_index')
505
  def get_scatter_plot(self):
 
541
  ylabel=y_label,
542
  frame_height=450,
543
  frame_width=500,
544
+ hooks=[self.hook_scatter_selection],
545
+ # Set initial view to (-100, 100)
546
+ xlim=(-100, 100),
547
+ ylim=(-100, 100)
548
  )
549
  if current_x_range and all(x is not None for x in current_x_range):
550
  opts['xlim'] = current_x_range
 
616
  # Use HLine because axes are inverted
617
  vline_pos = hv.HLine(self.vmax).opts(color='red', line_dash='dashed', line_width=1.5, alpha=0.6)
618
  vline_neg = hv.HLine(-self.vmax).opts(color='red', line_dash='dashed', line_width=1.5, alpha=0.6)
619
+ vline_zero = hv.HLine(0).opts(color='black', line_width=1.0, alpha=0.8)
620
 
621
+ return pn.Column(bar_plot * vline_pos * vline_neg * vline_zero, width_policy='max', margin=(20, 0, 0, 20))
622
 
623
+ @param.depends('_selection_index', 'season', 'show_precursors')
624
  def get_precursor_maps(self):
625
  """Display precursor maps (U850, V850, Z500) for selected regions in tabs."""
626
+ if not self.show_precursors:
627
+ return pn.pane.Markdown("### Precursor Maps Disabled\n*Enable 'Show Precursor Maps' in the sidebar to view patterns (may reduce performance)*")
628
+
629
  if not self._selection_index:
630
  return pn.pane.Markdown("### Precursor maps: No region selected\n*Click on a map or scatter point to see precursor patterns*")
631
 
 
673
  sidebar=[
674
  pn.Param(
675
  app_instance.param,
676
+ parameters=['model', 'season', 'term', 'source', 'nonlinear_pos', 'vmax', 'selected_regions', 'show_precursors'],
677
  widgets={
678
  'nonlinear_pos': {
679
  'type': pn.widgets.Select,
680
+ },
681
+ 'show_precursors': {
682
+ 'type': pn.widgets.Switch,
683
+ 'align': 'start'
684
  }
685
  }
686
  ),