@@ -826,46 +826,47 @@ def gen_metric(cls, meta, proc_aman):
826826 (meta .det_info .wafer_slot == ws ) & (meta .det_info .wafer .bandpass == bp )
827827 )[0 ]
828828
829- # get the coefficients for every detector
830- coeff = proc_aman .hwpss_stats .coeffs [subset ]
831- # mask those that were not set
832- nonzero = np .any (coeff != 0.0 , axis = 1 )
833-
834- # calculate amplitude of each mode
835- mode_labels = list (proc_aman .hwpss_stats .modes .vals )
836- num_re = re .compile ("^[SC](\d+)$" )
837- nums = sorted (list (set ([num_re .match (l ).group (1 ) for l in mode_labels ])))
838- coeff_amp = np .zeros ((coeff .shape [0 ], len (nums )), coeff .dtype )
839- amp_labels = []
840- for i , n in enumerate (nums ):
841- c_ind = mode_labels .index (f"C{ n } " )
842- s_ind = mode_labels .index (f"S{ n } " )
843- coeff_amp [:, i ] = np .sqrt (coeff [:, c_ind ]** 2 + coeff [:, s_ind ]** 2 )
844- amp_labels .append (f"A{ n } " )
845-
846- # record percentiles over detectors and fraction of samples flagged
847- perc = np .percentile (coeff_amp [nonzero ], cls ._influx_percentiles , axis = 0 )
848- mean = coeff_amp [nonzero ].mean (axis = 0 )
849-
850- tags_base = {
851- k : _get_tag (meta .det_info , k , subset [0 ]) for k in tag_keys if _has_tag (meta .det_info , k )
852- }
853- tags_base ["telescope" ] = meta .obs_info .telescope
854-
855- # loop over percentiles and coefficient labels
856- for pi , p in enumerate (cls ._influx_percentiles ):
829+ if len (subset ) > 0 :
830+ # get the coefficients for every detector
831+ coeff = proc_aman .hwpss_stats .coeffs [subset ]
832+ # mask those that were not set
833+ nonzero = np .any (coeff != 0.0 , axis = 1 )
834+
835+ # calculate amplitude of each mode
836+ mode_labels = list (proc_aman .hwpss_stats .modes .vals )
837+ num_re = re .compile ("^[SC](\d+)$" )
838+ nums = sorted (list (set ([num_re .match (l ).group (1 ) for l in mode_labels ])))
839+ coeff_amp = np .zeros ((coeff .shape [0 ], len (nums )), coeff .dtype )
840+ amp_labels = []
841+ for i , n in enumerate (nums ):
842+ c_ind = mode_labels .index (f"C{ n } " )
843+ s_ind = mode_labels .index (f"S{ n } " )
844+ coeff_amp [:, i ] = np .sqrt (coeff [:, c_ind ]** 2 + coeff [:, s_ind ]** 2 )
845+ amp_labels .append (f"A{ n } " )
846+
847+ # record percentiles over detectors and fraction of samples flagged
848+ perc = np .percentile (coeff_amp [nonzero ], cls ._influx_percentiles , axis = 0 )
849+ mean = coeff_amp [nonzero ].mean (axis = 0 )
850+
851+ tags_base = {
852+ k : _get_tag (meta .det_info , k , subset [0 ]) for k in tag_keys if _has_tag (meta .det_info , k )
853+ }
854+ tags_base ["telescope" ] = meta .obs_info .telescope
855+
856+ # loop over percentiles and coefficient labels
857+ for pi , p in enumerate (cls ._influx_percentiles ):
858+ for l in amp_labels :
859+ t_new = tags_base .copy ()
860+ t_new .update ({"mode" : l , "det_stat" : f"percentile_{ p } " })
861+ tags .append (t_new )
862+ vals += list (perc [pi ])
863+
864+ # finally also record the mean
857865 for l in amp_labels :
858866 t_new = tags_base .copy ()
859- t_new .update ({"mode" : l , "det_stat" : f"percentile_ { p } " })
867+ t_new .update ({"mode" : l , "det_stat" : "mean " })
860868 tags .append (t_new )
861- vals += list (perc [pi ])
862-
863- # finally also record the mean
864- for l in amp_labels :
865- t_new = tags_base .copy ()
866- t_new .update ({"mode" : l , "det_stat" : "mean" })
867- tags .append (t_new )
868- vals += list (mean )
869+ vals += list (mean )
869870
870871 obs_time = [meta .obs_info .timestamp ] * len (tags )
871872 return {
0 commit comments