@@ -89,8 +89,8 @@ def _compute_metrics_block(
8989
9090 Returns:
9191 vals_flat : 1D np.array (metrics for each curve, or concatenated for 'all')
92- titles : list of curve labels
93- per_curve_series : list of 1D arrays (for Metric='all')
92+ titles : list of metric labels
93+ per_curve_series : list of per-curve metric arrays (for Metric='all')
9494 """
9595 import numpy as np
9696
@@ -163,18 +163,19 @@ def _parse_stat_xy(m):
163163 else :
164164 out = np .nan
165165
166- # MATLAB passes tiny value instead of exact zero (survives nonzeros())
167166 if out == 0.0 :
168167 out = 1e-12
169168
170169 return np .array ([out ]), [f"curve{ idx_first } " ], []
171170
172- # --- metric='all': return concatenated series for each curve (minus initial ) ---
171+ # --- metric='all': return all finite Y values (one per data point ) ---
173172 if metric_str == "all" :
174173 for j in range (ncols ):
175- yj = Y_sel [:, j ].reshape (- 1 ) - initial_value
174+ yj = Y_sel [:, j ].reshape (- 1 )
175+ mask = np .isfinite (yj )
176+ yj = yj [mask ] - initial_value
176177 per_curve_series .append (yj )
177- titles .extend ([f"curve { j + 1 } " ] * yj . size )
178+ titles .extend ([f"point { k + 1 } _curve { j + 1 } " for k in range ( len ( yj ))] )
178179 vals_flat = np .concatenate (per_curve_series ) if per_curve_series else np .array ([])
179180 return vals_flat , titles , per_curve_series
180181
@@ -203,10 +204,8 @@ def _parse_stat_xy(m):
203204 elif metric_str == "start" :
204205 out = yj [0 ]
205206 elif metric_str == "ipct" :
206- # Not implemented in this port; keep parity-friendly placeholder
207- out = 1e-12
207+ out = 1e-12 # placeholder for parity
208208 else :
209- # Default fallback consistent with MATLAB's behavior path to non-zeros
210209 out = 1e-12
211210
212211 if out == 0.0 :
@@ -643,28 +642,33 @@ def read_csv_cached(path, **kwargs):
643642
644643 # --- MATLAB-compatible consistency checks (Metric='all' padding, etc.) ---
645644 vals_meas_entry = Save_Measured_Metric [- 1 ]
646- if isinstance (pp .Metric , str ) and pp .Metric .strip ().lower () == 'all' :
647- mvec = np .atleast_1d (vals_meas_entry )
648- pvec = np .atleast_1d (vals_pred_list )
649- len_m , len_p = mvec .size , len (pvec )
645+ metric_str = str (pp .Metric or '' ).strip ().lower ()
646+
647+ # Always flatten any nested list-of-arrays first
648+ flat_pred = np .concatenate ([
649+ np .atleast_1d (v ) for v in vals_pred_list if v is not None and np .size (v ) > 0
650+ ]) if any (np .size (v ) > 0 for v in vals_pred_list ) else np .array ([])
651+
652+ flat_meas = np .atleast_1d (vals_meas_entry ).ravel ()
653+
654+ if metric_str == 'all' :
655+ len_m , len_p = flat_meas .size , flat_pred .size
650656 if len_m != len_p :
651657 maxlen = max (len_m , len_p )
652658 if len_m < maxlen :
653- mvec = np .pad (mvec , (0 , maxlen - len_m ), constant_values = np .nan )
659+ flat_meas = np .pad (flat_meas , (0 , maxlen - len_m ), constant_values = np .nan )
654660 if len_p < maxlen :
655- pvec = np .pad (pvec , (0 , maxlen - len_p ), constant_values = np .nan )
656- Save_Measured_Metric [- 1 ] = mvec
657- vals_pred_list = pvec
661+ flat_pred = np .pad (flat_pred , (0 , maxlen - len_p ), constant_values = np .nan )
662+ Save_Measured_Metric [- 1 ] = flat_meas
658663 print (f"[dataplot] Padded { pp .Dataname } ({ pp .Quantity } ) from ({ len_m } ,{ len_p } ) to { maxlen } " )
659664 else :
660- len_m = np .size ( vals_meas_entry )
661- len_p = np .size ( vals_pred_list )
665+ len_m = flat_meas .size
666+ len_p = flat_pred .size
662667 if len_m != len_p :
663- print (f"[dataplot] Length mismatch at index { csv_rownum } : "
664- f"{ pp .Dataname } | { pp .Quantity } | "
665- f"Measured={ len_m } , Predicted={ len_p } " )
668+ print (f"[dataplot] Length mismatch at CSV row { csv_rownum } : "
669+ f"{ pp .Dataname } | { pp .Quantity } | Measured={ len_m } , Predicted={ len_p } " )
666670
667- Save_Predicted_Metric [- 1 ] = np . array ( vals_pred_list , dtype = object )
671+ Save_Predicted_Metric [- 1 ] = flat_pred
668672 Save_Predicted_Quantity [- 1 ] = np .array (qty_pred_list , dtype = object )
669673
670674 except Exception as e :
0 commit comments