JoshOD commited on
Commit
07eec83
·
verified ·
1 Parent(s): a06635d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -196,7 +196,7 @@ def compute_classified_data_v3(model, season, term, nonlinear_pos, source_tuple,
196
 
197
  # 6. Saturated colors for readable hover text
198
  text_cmap = {
199
- 'Minimal': '#1B5E20', # Dark Green
200
  'Conversion': '#B8860B', # Dark Gold
201
  'Dynamical': '#0277BD', # Dark Blue
202
  'Compounding': '#7B1FA2', # Dark Purple
@@ -230,7 +230,7 @@ class CMIPApp(param.Parameterized):
230
 
231
  # Shared color map for sectors
232
  sector_cmap = {
233
- 'Minimal': '#C8E6C9', # Pale Green
234
  'Conversion': '#FDFD96', # Pale Yellow
235
  'Dynamical': '#ADD8E6', # Pale Blue
236
  'Compounding': '#E1BEE7', # Pale Purple
@@ -239,9 +239,8 @@ class CMIPApp(param.Parameterized):
239
 
240
  def __init__(self, **params):
241
  super().__init__(**params)
242
- # Separate streams for each view to prevent source-swapping issues
243
- self.v_map_s = streams.Selection1D()
244
- self.t_map_s = streams.Selection1D()
245
  self.scat_s = streams.Selection1D()
246
  self.sel_map_s = streams.Selection1D()
247
 
@@ -250,8 +249,7 @@ class CMIPApp(param.Parameterized):
250
  self.scat_r = streams.RangeXY()
251
 
252
  # Link all streams to update the master selection
253
- self.v_map_s.param.watch(self._sync_selection, 'index')
254
- self.t_map_s.param.watch(self._sync_selection, 'index')
255
  self.scat_s.param.watch(self._sync_selection, 'index')
256
  self.sel_map_s.param.watch(self._sync_selection, 'index')
257
 
@@ -328,14 +326,14 @@ class CMIPApp(param.Parameterized):
328
  def get_value_map(self):
329
  return self._render_map_base(self.term, 'BrBG', (-self.vmax, self.vmax),
330
  f"{' + '.join(self.source)} heavy precip. {self.term} (%)",
331
- self.v_map_s, self.map_r)
332
 
333
  # OPTIMIZATION 3: Remove _selection_index from depends
334
  @param.depends('model', 'season', 'term', 'nonlinear_pos', 'min_bias_threshold', 'slope_control')
335
  def get_type_map(self):
336
  return self._render_map_base('Type', self.sector_cmap,
337
  title=f"{self.term.capitalize()} Classification: {self.model} {self.season}",
338
- sel_stream=self.t_map_s, range_stream=self.map_r,
339
  show_value=False)
340
 
341
  def _render_map_base(self, color_col, cmap, clim=None, title="", sel_stream=None, range_stream=None, show_value=True):
@@ -616,8 +614,7 @@ class CMIPApp(param.Parameterized):
616
 
617
  return bg * hv.Overlay(labels)
618
 
619
- # OPTIMIZATION 5: Remove _selection_index dependency - use DynamicMap instead
620
- @param.depends('model', 'season', 'term', 'nonlinear_pos', 'min_bias_threshold', 'slope_control', 'vmax')
621
  def get_scatter_plot(self):
622
  # Get standardized classified data (cached)
623
  df_scatter = self._get_classified_data()
@@ -660,7 +657,13 @@ class CMIPApp(param.Parameterized):
660
  aspect=0.85,
661
  hooks=[self.hook_scatter_selection],
662
  xlim=(-self.vmax, self.vmax),
663
- ylim=(-self.vmax, self.vmax)
 
 
 
 
 
 
664
  )
665
 
666
  scatter = df_scatter.hvplot.scatter(
@@ -684,6 +687,11 @@ class CMIPApp(param.Parameterized):
684
  self.scat_r.source = scatter
685
 
686
  return plot
 
 
 
 
 
687
 
688
  def hook_scatter_selection(self, plot, element):
689
  if 'source' in plot.handles:
@@ -1150,7 +1158,7 @@ class CMIPApp(param.Parameterized):
1150
  @param.depends('term')
1151
  def main_view(self):
1152
  scatter_pane = pn.Column(
1153
- pn.panel(self.get_scatter_plot, sizing_mode='scale_width'), # Removed loading_indicator
1154
  margin=(0, 0, 0, 5),
1155
  sizing_mode='scale_width'
1156
  )
 
196
 
197
  # 6. Saturated colors for readable hover text
198
  text_cmap = {
199
+ 'Minimal': '#1B5E20',
200
  'Conversion': '#B8860B', # Dark Gold
201
  'Dynamical': '#0277BD', # Dark Blue
202
  'Compounding': '#7B1FA2', # Dark Purple
 
230
 
231
  # Shared color map for sectors
232
  sector_cmap = {
233
+ 'Minimal': '#C8E6C9',
234
  'Conversion': '#FDFD96', # Pale Yellow
235
  'Dynamical': '#ADD8E6', # Pale Blue
236
  'Compounding': '#E1BEE7', # Pale Purple
 
239
 
240
  def __init__(self, **params):
241
  super().__init__(**params)
242
+ # FIXED: Use single shared stream for both map tabs to maintain selection across tabs
243
+ self.shared_map_s = streams.Selection1D()
 
244
  self.scat_s = streams.Selection1D()
245
  self.sel_map_s = streams.Selection1D()
246
 
 
249
  self.scat_r = streams.RangeXY()
250
 
251
  # Link all streams to update the master selection
252
+ self.shared_map_s.param.watch(self._sync_selection, 'index')
 
253
  self.scat_s.param.watch(self._sync_selection, 'index')
254
  self.sel_map_s.param.watch(self._sync_selection, 'index')
255
 
 
326
  def get_value_map(self):
327
  return self._render_map_base(self.term, 'BrBG', (-self.vmax, self.vmax),
328
  f"{' + '.join(self.source)} heavy precip. {self.term} (%)",
329
+ self.shared_map_s, self.map_r)
330
 
331
  # OPTIMIZATION 3: Remove _selection_index from depends
332
  @param.depends('model', 'season', 'term', 'nonlinear_pos', 'min_bias_threshold', 'slope_control')
333
  def get_type_map(self):
334
  return self._render_map_base('Type', self.sector_cmap,
335
  title=f"{self.term.capitalize()} Classification: {self.model} {self.season}",
336
+ sel_stream=self.shared_map_s, range_stream=self.map_r,
337
  show_value=False)
338
 
339
  def _render_map_base(self, color_col, cmap, clim=None, title="", sel_stream=None, range_stream=None, show_value=True):
 
614
 
615
  return bg * hv.Overlay(labels)
616
 
617
+ # OPTIMIZATION 5: Use bound function to ensure scatter updates on selection
 
618
  def get_scatter_plot(self):
619
  # Get standardized classified data (cached)
620
  df_scatter = self._get_classified_data()
 
657
  aspect=0.85,
658
  hooks=[self.hook_scatter_selection],
659
  xlim=(-self.vmax, self.vmax),
660
+ ylim=(-self.vmax, self.vmax),
661
+ # FIXED: Add selection styling options
662
+ selection_fill_alpha=1.0,
663
+ selection_line_width=2.0,
664
+ selection_line_color='black',
665
+ nonselection_fill_alpha=0.3,
666
+ nonselection_line_alpha=0.3
667
  )
668
 
669
  scatter = df_scatter.hvplot.scatter(
 
687
  self.scat_r.source = scatter
688
 
689
  return plot
690
+
691
+ # Create bound version that depends on selection for use in Panel
692
+ @param.depends('model', 'season', 'term', 'nonlinear_pos', 'min_bias_threshold', 'slope_control', 'vmax', '_selection_index')
693
+ def get_scatter_plot_bound(self):
694
+ return self.get_scatter_plot()
695
 
696
  def hook_scatter_selection(self, plot, element):
697
  if 'source' in plot.handles:
 
1158
  @param.depends('term')
1159
  def main_view(self):
1160
  scatter_pane = pn.Column(
1161
+ pn.panel(self.get_scatter_plot_bound, sizing_mode='scale_width'), # Use bound version
1162
  margin=(0, 0, 0, 5),
1163
  sizing_mode='scale_width'
1164
  )