5454 "instability" : "#F44336" , # red
5555 "recovery" : "#4CAF50" , # green
5656}
57- REGIME_ALPHA = 0.18
57+ REGIME_ALPHA = 0.15 # polished (manuscript) – slightly softer than original
58+ REGIME_ALPHA_UNPOLISHED = 0.18 # original value, kept for debug reproducibility
59+
60+ # Minimum contiguous-block length (samples) for a transition marker to be shown
61+ # in the polished figure. Short-lived blocks within the same consolidated regime
62+ # are suppressed. Matches the min_dwell parameter used in detect_regimes.
63+ _MIN_TRANSITION_BLOCK = 30
5864
5965# ── Paths ─────────────────────────────────────────────────────────────────────
60- _DATA_PATH = os .path .join (_REPO_ROOT , "data" , "synthetic" , "eic_timeseries.csv" )
61- _FIG_DIR = os .path .join (_REPO_ROOT , "figures" , "stage5_regime_transitions" )
66+ _DATA_PATH = os .path .join (_REPO_ROOT , "data" , "synthetic" , "eic_timeseries.csv" )
67+ _FIG_DIR = os .path .join (_REPO_ROOT , "figures" , "stage5_regime_transitions" )
68+ _MANUSCRIPT_DIR = os .path .join (_FIG_DIR , "manuscript" )
69+ _DEBUG_DIR = os .path .join (_FIG_DIR , "debug" )
6270
6371
6472# ── Data loading ──────────────────────────────────────────────────────────────
@@ -125,11 +133,45 @@ def plot_regime_segmentation(
125133 delta_phi : np .ndarray ,
126134 regime_labels ,
127135 out_path : str ,
136+ * ,
137+ polished : bool = True ,
128138) -> None :
129- """Plot broad regime bands with ΔΦ(t) overlaid and transition markers."""
130- intervals = regime_shading_intervals (regime_labels )
139+ """Plot broad regime bands with ΔΦ(t) overlaid and transition markers.
140+
141+ Parameters
142+ ----------
143+ polished : bool, default True
144+ When *True* (manuscript output) applies light visual refinements:
145+ softer regime-band alpha, thicker ΔΦ(t) curve, lighter/thinner
146+ transition lines, and suppression of short-lived transition markers.
147+ When *False* (debug output) the original visual parameters are used.
148+ Neither mode alters the underlying segmentation logic or thresholds.
149+ """
150+ intervals = regime_shading_intervals (regime_labels )
131151 transitions = extract_transition_events (regime_labels )
132152
153+ # ── Visual parameters ─────────────────────────────────────────────────────
154+ if polished :
155+ regime_alpha = REGIME_ALPHA # 0.15 – slightly softer bands
156+ curve_lw = 1.5 # thicker ΔΦ(t) for readability
157+ trans_color = "#9E9E9E" # lighter gray
158+ trans_lw = 0.6 # slightly thinner
159+ trans_alpha = 0.45
160+ # Suppress transition markers for short-lived blocks (visual clutter).
161+ major_starts = {
162+ iv .start
163+ for iv in intervals
164+ if (iv .stop - iv .start ) >= _MIN_TRANSITION_BLOCK and iv .start > 0
165+ }
166+ visible_transitions = [ev for ev in transitions if ev .index in major_starts ]
167+ else :
168+ regime_alpha = REGIME_ALPHA_UNPOLISHED # 0.18 – original
169+ curve_lw = 1.0
170+ trans_color = "#616161"
171+ trans_lw = 0.8
172+ trans_alpha = 0.6
173+ visible_transitions = transitions
174+
133175 fig , ax = plt .subplots (figsize = (14 , 5 ))
134176
135177 # ── Broad colored regime bands ────────────────────────────────────────────
@@ -140,27 +182,27 @@ def plot_regime_segmentation(
140182 ax .axvspan (
141183 t_start ,
142184 t_end ,
143- alpha = REGIME_ALPHA ,
185+ alpha = regime_alpha ,
144186 color = REGIME_COLORS .get (iv .regime , "#CCCCCC" ),
145187 linewidth = 0 ,
146188 )
147189
148- # ── Clean boundary lines at transitions ─ ─────────────────────────────────
149- for ev in transitions :
190+ # ── Boundary lines at (major) transitions ─────────────────────────────────
191+ for ev in visible_transitions :
150192 ax .axvline (
151193 t [ev .index ],
152- color = "#616161" ,
153- linewidth = 0.8 ,
194+ color = trans_color ,
195+ linewidth = trans_lw ,
154196 linestyle = "--" ,
155- alpha = 0.6 ,
197+ alpha = trans_alpha ,
156198 zorder = 3 ,
157199 )
158200
159201 # ── ΔΦ(t) overlaid as a single curve ─────────────────────────────────────
160202 ax .plot (
161203 t , delta_phi ,
162204 color = "#212121" ,
163- linewidth = 1.0 ,
205+ linewidth = curve_lw ,
164206 zorder = 4 ,
165207 label = r"$\Delta\Phi(t)$" ,
166208 )
@@ -185,16 +227,16 @@ def plot_regime_segmentation(
185227 ]
186228 transition_handle = Line2D (
187229 [0 ], [0 ],
188- color = "#616161" ,
189- linewidth = 0.8 ,
230+ color = trans_color ,
231+ linewidth = trans_lw ,
190232 linestyle = "--" ,
191- alpha = 0.6 ,
233+ alpha = trans_alpha ,
192234 label = "Transition" ,
193235 )
194236 delta_phi_handle = Line2D (
195237 [0 ], [0 ],
196238 color = "#212121" ,
197- linewidth = 1.0 ,
239+ linewidth = curve_lw ,
198240 label = r"$\Delta\Phi(t)$" ,
199241 )
200242 ax .legend (
@@ -214,7 +256,9 @@ def plot_regime_segmentation(
214256# ── Entry point ───────────────────────────────────────────────────────────────
215257
216258def main () -> None :
217- os .makedirs (_FIG_DIR , exist_ok = True )
259+ os .makedirs (_FIG_DIR , exist_ok = True )
260+ os .makedirs (_MANUSCRIPT_DIR , exist_ok = True )
261+ os .makedirs (_DEBUG_DIR , exist_ok = True )
218262
219263 # ── 1. Load data ──────────────────────────────────────────────────────────
220264 series , t = _load_series (_DATA_PATH )
@@ -234,12 +278,22 @@ def main() -> None:
234278 out_path = os .path .join (_FIG_DIR , "delta_phi_thresholds.png" ),
235279 )
236280
237- # ── 5. Plot regime segmentation ───────────────────────────────────────────
281+ # ── 5. Plot regime segmentation – unpolished (debug, for reproducibility) ─
282+ plot_regime_segmentation (
283+ t ,
284+ delta_phi ,
285+ regime_labels = regime_result .labels ,
286+ out_path = os .path .join (_DEBUG_DIR , "regime_segmentation_unpolished.png" ),
287+ polished = False ,
288+ )
289+
290+ # ── 6. Plot regime segmentation – polished (manuscript) ───────────────────
238291 plot_regime_segmentation (
239292 t ,
240293 delta_phi ,
241294 regime_labels = regime_result .labels ,
242- out_path = os .path .join (_FIG_DIR , "regime_segmentation.png" ),
295+ out_path = os .path .join (_MANUSCRIPT_DIR , "regime_segmentation.png" ),
296+ polished = True ,
243297 )
244298
245299
0 commit comments