@@ -371,11 +371,15 @@ def dataplot(config_filename,**kwargs):
371371 Save_Predicted_Quantity .append (None )
372372
373373 # -------------- PLOTTING + PRINT -----------------
374- # Read and prepare the experimental (d1) data, same for both cases
375374 E = pd .read_csv (expdir + pp .d1_Filename ,
376- header = int (pp .d1_Col_Name_Row - 1 ),
377- sep = ',' , engine = 'python' , quotechar = '"' )
375+ header = int (pp .d1_Col_Name_Row - 1 ),
376+ sep = ',' , engine = 'python' , quotechar = '"' ,
377+ skip_blank_lines = True ).dropna (how = 'all' ) # drop fully empty rows
378+
379+ # Drop trailing NaN rows across all columns (MATLAB csvread behavior)
380+ E = E .loc [:E .dropna (how = 'all' ).last_valid_index ()]
378381 E .columns = E .columns .str .strip ()
382+
379383 start_idx = int (pp .d1_Data_Row - pp .d1_Col_Name_Row - 1 )
380384 x , _ = get_data (E , pp .d1_Ind_Col_Name , start_idx )
381385 y , _ = get_data (E , pp .d1_Dep_Col_Name , start_idx )
@@ -449,29 +453,63 @@ def dataplot(config_filename,**kwargs):
449453 # --- Save measured (experimental) metric using MATLAB-equivalent logic ---
450454 if not gtest :
451455 try :
452- vals_meas , qty_meas , _ = _compute_metrics_block (
453- x = x ,
454- Y = y ,
455- metric = pp .Metric ,
456- initial_value = float (pp .d1_Initial_Value or 0.0 ),
457- comp_start = float (pp .d1_Comp_Start or np .nan ),
458- comp_end = float (pp .d1_Comp_End or np .nan ),
459- dep_comp_start = float (pp .d1_Dep_Comp_Start or np .nan ),
460- dep_comp_end = float (pp .d1_Dep_Comp_End or np .nan ),
461- variant_side = "d1" ,
462- )
463- Save_Measured_Metric [- 1 ] = vals_meas
464- Save_Measured_Quantity [- 1 ] = qty_meas
456+ vals_meas_list = []
457+ qty_meas_list = []
458+
459+ if y .ndim == 2 and x .ndim == 2 and y .shape [1 ] == x .shape [1 ]:
460+ for j in range (y .shape [1 ]):
461+ xj = np .ravel (x [:, j ])
462+ yj = np .ravel (y [:, j ])
463+ mask = np .isfinite (xj ) & np .isfinite (yj )
464+ xj = xj [mask ]
465+ yj = yj [mask ]
466+ if len (xj ) > 0 and len (yj ) > 0 :
467+ vals_meas , qty_meas , _ = _compute_metrics_block (
468+ x = xj ,
469+ Y = yj ,
470+ metric = pp .Metric ,
471+ initial_value = float (pp .d1_Initial_Value or 0.0 ),
472+ comp_start = float (pp .d1_Comp_Start or np .nan ),
473+ comp_end = float (pp .d1_Comp_End or np .nan ),
474+ dep_comp_start = float (pp .d1_Dep_Comp_Start or np .nan ),
475+ dep_comp_end = float (pp .d1_Dep_Comp_End or np .nan ),
476+ variant_side = "d1" ,
477+ )
478+ vals_meas_list .append (vals_meas )
479+ qty_meas_list .append (qty_meas )
480+ else :
481+ vals_meas , qty_meas , _ = _compute_metrics_block (
482+ x = x ,
483+ Y = y ,
484+ metric = pp .Metric ,
485+ initial_value = float (pp .d1_Initial_Value or 0.0 ),
486+ comp_start = float (pp .d1_Comp_Start or np .nan ),
487+ comp_end = float (pp .d1_Comp_End or np .nan ),
488+ dep_comp_start = float (pp .d1_Dep_Comp_Start or np .nan ),
489+ dep_comp_end = float (pp .d1_Dep_Comp_End or np .nan ),
490+ variant_side = "d1" ,
491+ )
492+ vals_meas_list = [vals_meas ]
493+ qty_meas_list = [qty_meas ]
494+
495+ Save_Measured_Metric [- 1 ] = np .array (vals_meas_list , dtype = object )
496+ Save_Measured_Quantity [- 1 ] = np .array (qty_meas_list , dtype = object )
497+
465498 except Exception as e :
466499 print (f"[dataplot] Error computing measured metric for { pp .Dataname } : { e } " )
467500 Save_Measured_Metric [- 1 ] = np .array ([])
468501 Save_Measured_Quantity [- 1 ] = []
469502
470503 # ------------------- MODEL (d2) -------------------
471504 M = pd .read_csv (cmpdir + pp .d2_Filename ,
472- header = int (pp .d2_Col_Name_Row - 1 ),
473- sep = ',' , engine = 'python' , quotechar = '"' )
505+ header = int (pp .d2_Col_Name_Row - 1 ),
506+ sep = ',' , engine = 'python' , quotechar = '"' ,
507+ skip_blank_lines = True ).dropna (how = 'all' ) # drop fully empty rows
508+
509+ # Drop trailing NaN rows across all columns (MATLAB csvread behavior)
510+ M = M .loc [:M .dropna (how = 'all' ).last_valid_index ()]
474511 M .columns = M .columns .str .strip ()
512+
475513 start_idx = int (pp .d2_Data_Row - pp .d2_Col_Name_Row - 1 )
476514
477515 # --- Define version string ---
@@ -546,42 +584,73 @@ def dataplot(config_filename,**kwargs):
546584 # --- Save predicted (model) metric using MATLAB-equivalent logic ---
547585 if not gtest :
548586 try :
549- vals_pred , qty_pred , _ = _compute_metrics_block (
550- x = x ,
551- Y = y ,
552- metric = pp .Metric ,
553- initial_value = float (pp .d2_Initial_Value or 0.0 ),
554- comp_start = float (pp .d2_Comp_Start or np .nan ),
555- comp_end = float (pp .d2_Comp_End or np .nan ),
556- dep_comp_start = float (pp .d2_Dep_Comp_Start or np .nan ),
557- dep_comp_end = float (pp .d2_Dep_Comp_End or np .nan ),
558- variant_side = "d2" ,
559- )
560-
561- # --- Early consistency & padding for Metric='all' ---
587+ vals_pred_list = []
588+ qty_pred_list = []
589+
590+ if y .ndim == 2 and x .ndim == 2 and y .shape [1 ] == x .shape [1 ]:
591+ # Multiple paired curves (e.g., z/L jet, 62 kW, 31 kW)
592+ for j in range (y .shape [1 ]):
593+ xj = np .ravel (x [:, j ])
594+ yj = np .ravel (y [:, j ])
595+ mask = np .isfinite (xj ) & np .isfinite (yj )
596+ xj = xj [mask ]
597+ yj = yj [mask ]
598+ if len (xj ) > 0 and len (yj ) > 0 :
599+ vals_pred , qty_pred , _ = _compute_metrics_block (
600+ x = xj ,
601+ Y = yj ,
602+ metric = pp .Metric ,
603+ initial_value = float (pp .d2_Initial_Value or 0.0 ),
604+ comp_start = float (pp .d2_Comp_Start or np .nan ),
605+ comp_end = float (pp .d2_Comp_End or np .nan ),
606+ dep_comp_start = float (pp .d2_Dep_Comp_Start or np .nan ),
607+ dep_comp_end = float (pp .d2_Dep_Comp_End or np .nan ),
608+ variant_side = "d2" ,
609+ )
610+ vals_pred_list .append (vals_pred )
611+ qty_pred_list .append (qty_pred )
612+ else :
613+ # Single curve (1D)
614+ vals_pred , qty_pred , _ = _compute_metrics_block (
615+ x = x ,
616+ Y = y ,
617+ metric = pp .Metric ,
618+ initial_value = float (pp .d2_Initial_Value or 0.0 ),
619+ comp_start = float (pp .d2_Comp_Start or np .nan ),
620+ comp_end = float (pp .d2_Comp_End or np .nan ),
621+ dep_comp_start = float (pp .d2_Dep_Comp_Start or np .nan ),
622+ dep_comp_end = float (pp .d2_Dep_Comp_End or np .nan ),
623+ variant_side = "d2" ,
624+ )
625+ vals_pred_list = [vals_pred ]
626+ qty_pred_list = [qty_pred ]
627+
628+ # --- MATLAB-compatible consistency checks (Metric='all' padding, etc.) ---
629+ vals_meas_entry = Save_Measured_Metric [- 1 ]
562630 if isinstance (pp .Metric , str ) and pp .Metric .strip ().lower () == 'all' :
563- mvec = np .atleast_1d (Save_Measured_Metric [ - 1 ] )
564- pvec = np .atleast_1d (vals_pred )
565- len_m , len_p = mvec .size , pvec . size
631+ mvec = np .atleast_1d (vals_meas_entry )
632+ pvec = np .atleast_1d (vals_pred_list )
633+ len_m , len_p = mvec .size , len ( pvec )
566634 if len_m != len_p :
567635 maxlen = max (len_m , len_p )
568636 if len_m < maxlen :
569637 mvec = np .pad (mvec , (0 , maxlen - len_m ), constant_values = np .nan )
570638 if len_p < maxlen :
571639 pvec = np .pad (pvec , (0 , maxlen - len_p ), constant_values = np .nan )
572640 Save_Measured_Metric [- 1 ] = mvec
573- vals_pred = pvec
641+ vals_pred_list = pvec
574642 print (f"[dataplot] Padded { pp .Dataname } ({ pp .Quantity } ) from ({ len_m } ,{ len_p } ) to { maxlen } " )
575643 else :
576- len_m = np .size (Save_Measured_Metric [ - 1 ] )
577- len_p = np .size (vals_pred )
644+ len_m = np .size (vals_meas_entry )
645+ len_p = np .size (vals_pred_list )
578646 if len_m != len_p :
579647 print (f"[dataplot] Length mismatch at index { csv_rownum } : "
580648 f"{ pp .Dataname } | { pp .Quantity } | "
581649 f"Measured={ len_m } , Predicted={ len_p } " )
582650
583- Save_Predicted_Metric [- 1 ] = vals_pred
584- Save_Predicted_Quantity [- 1 ] = qty_pred
651+ Save_Predicted_Metric [- 1 ] = np .array (vals_pred_list , dtype = object )
652+ Save_Predicted_Quantity [- 1 ] = np .array (qty_pred_list , dtype = object )
653+
585654 except Exception as e :
586655 print (f"[dataplot] Error computing predicted metric for { pp .Dataname } : { e } " )
587656 Save_Predicted_Metric [- 1 ] = np .array ([])
0 commit comments