@@ -426,6 +426,7 @@ def flatten_telescope_data_vectorized(
426426 tel_config = None ,
427427 observatory = "veritas" ,
428428 max_tel_per_type = None ,
429+ preview_rows = 20 ,
429430):
430431 """
431432 Vectorized flattening of telescope array columns.
@@ -451,6 +452,8 @@ def flatten_telescope_data_vectorized(
451452 Observatory name for indexing mode detection. Default is "veritas".
452453 max_tel_per_type : int, optional
453454 Maximum number of telescopes to keep per mirror area type. If None, keep all.
455+ preview_rows : int, optional
456+ Number of events to include in the sorting preview log. Set to 0 to disable.
454457
455458 Returns
456459 -------
@@ -563,7 +566,14 @@ def flatten_telescope_data_vectorized(
563566 flat_features = filtered_features
564567
565568 index = _get_index (df , n_evt )
566- df_flat = flatten_telescope_variables (n_tel , flat_features , index , tel_config , analysis_type )
569+ df_flat = flatten_telescope_variables (
570+ n_tel ,
571+ flat_features ,
572+ index ,
573+ tel_config = tel_config ,
574+ analysis_type = analysis_type ,
575+ preview_rows = preview_rows ,
576+ )
567577 return pd .concat (
568578 [df_flat , extra_columns (df , analysis_type , training , index , tel_config , observatory )],
569579 axis = 1 ,
@@ -706,6 +716,7 @@ def flatten_feature_data(
706716 tel_config = None ,
707717 observatory = "veritas" ,
708718 max_tel_per_type = None ,
719+ preview_rows = 20 ,
709720):
710721 """
711722 Get flattened features for events.
@@ -728,6 +739,8 @@ def flatten_feature_data(
728739 Observatory name for indexing mode detection.
729740 max_tel_per_type : int, optional
730741 Maximum number of telescopes to keep per mirror area type. If None, keep all.
742+ preview_rows : int, optional
743+ Number of events to include in the sorting preview log. Set to 0 to disable.
731744 """
732745 df_flat = flatten_telescope_data_vectorized (
733746 group_df ,
@@ -738,6 +751,7 @@ def flatten_feature_data(
738751 tel_config = tel_config ,
739752 observatory = observatory ,
740753 max_tel_per_type = max_tel_per_type ,
754+ preview_rows = preview_rows ,
741755 )
742756 max_tel_id = tel_config ["max_tel_id" ] if tel_config else ntel - 1
743757 excluded_columns = set (features_module .target_features (analysis_type )) | set (
@@ -855,6 +869,7 @@ def load_training_data(model_configs, file_list, analysis_type):
855869 tel_config = tel_config ,
856870 observatory = model_configs .get ("observatory" , "veritas" ),
857871 max_tel_per_type = model_configs .get ("max_tel_per_type" , None ),
872+ preview_rows = model_configs .get ("preview_rows" , 20 ),
858873 )
859874 if analysis_type == "stereo_analysis" :
860875 new_cols = {
@@ -941,7 +956,14 @@ def apply_clip_intervals(df, n_tel=None, apply_log10=None):
941956 df .loc [mask_to_log , var_base ] = np .log10 (df .loc [mask_to_log , var_base ])
942957
943958
944- def flatten_telescope_variables (n_tel , flat_features , index , tel_config = None , analysis_type = None ):
959+ def flatten_telescope_variables (
960+ n_tel ,
961+ flat_features ,
962+ index ,
963+ tel_config = None ,
964+ analysis_type = None ,
965+ preview_rows = 20 ,
966+ ):
945967 """Generate dataframe for telescope variables flattened for all telescopes.
946968
947969 Creates features for all telescope IDs, using NaN as default value for missing data.
@@ -958,6 +980,8 @@ def flatten_telescope_variables(n_tel, flat_features, index, tel_config=None, an
958980 Telescope configuration with 'max_tel_id' key.
959981 analysis_type : str, optional
960982 Type of analysis, e.g. "classification" or "stereo_analysis".
983+ preview_rows : int, optional
984+ Number of events to include in the sorting preview log. Set to 0 to disable.
961985 """
962986 df_flat = pd .DataFrame (flat_features , index = index )
963987 df_flat = df_flat .astype (np .float32 )
@@ -988,11 +1012,13 @@ def flatten_telescope_variables(n_tel, flat_features, index, tel_config=None, an
9881012 size_cols = [c for c in df_flat .columns if c .startswith ("size_" )][: max_tel_id + 1 ]
9891013 area_cols = [c for c in df_flat .columns if c .startswith ("mirror_area_" )][: max_tel_id + 1 ]
9901014 disp_cols = [c for c in df_flat .columns if c .startswith ("Disp_T_" )][: max_tel_id + 1 ]
991- preview = df_flat [size_cols + area_cols + disp_cols ].head (20 )
992- _logger .info (
993- "Sorted telescope sizes (pre-clip/log10), first 20 events: \n "
994- f"{ preview .to_string (index = False )} "
995- )
1015+ if preview_rows and preview_rows > 0 :
1016+ preview = df_flat [size_cols + area_cols + disp_cols ].head (preview_rows )
1017+ _logger .info (
1018+ "Sorted telescope sizes (pre-clip/log10), first %d events: \n %s" ,
1019+ preview_rows ,
1020+ preview .to_string (index = False ),
1021+ )
9961022
9971023 apply_clip_intervals (
9981024 df_flat ,
@@ -1098,6 +1124,7 @@ def extra_columns(df, analysis_type, training, index, tel_config=None, observato
10981124 - _to_numpy_1d (df ["Yoff_intersect" ], np .float32 )
10991125 ).astype (np .float32 ),
11001126 "DispNImages" : _to_numpy_1d (df ["DispNImages" ], np .int32 ),
1127+ "img2_ang" : _to_numpy_1d (df ["img2_ang" ], np .float32 ),
11011128 # These may be absent in some datasets; if missing, fill with NaN
11021129 "Erec" : (
11031130 _to_numpy_1d (df ["Erec" ], np .float32 )
0 commit comments