@@ -169,9 +169,11 @@ class PreprocessValidDets(PreprocessQA):
169169 The config entry supports a `process_args` block where the following options can be
170170 specified:
171171
172- tags : list
173- Keys into `metadata.det_info` to record as tags with the Influx line.
174- Added to the default list ["wafer_slot", "tel_tube", "wafer.bandpass"].
172+ tags : dict
173+ The values are keys into `metadata.det_info` to record as tags with
174+ the Influx line. The keys are addded to the default list
175+ ["wafer_slot", "tel_tube", "bandpass"] with "bandpass" being taken
176+ from "wafer.bandpass" or "det_cal.bandpass" if the former isn't found.
175177 thresh : float
176178 The threshold for the fraction of valid samples above which a detector is
177179 deemed good (default 0.75)
@@ -192,24 +194,35 @@ def __init__(
192194 # bypass the PreprocessQA __init__
193195 super (PreprocessQA , self ).__init__ (* args , ** kwargs )
194196 # extract parameters
195- self ._tags = process_args .get ("tags" , [] )
197+ self ._tags = process_args .get ("tags" , {} )
196198 self ._thresh = process_args .get ("thresh" , 0.75 )
197199 self ._key = process_args .get ("process_name" , "glitches" )
198200
199201 def _process (self , meta ):
200202
201203 # add specified tags
202- tag_keys = ["wafer_slot" , "tel_tube" , "wafer.bandpass" ]
203- tag_keys += [t for t in self ._tags if t not in tag_keys ]
204+ tag_keys = {
205+ "wafer_slot" : "wafer_slot" ,
206+ "tel_tube" : "tel_tube" ,
207+ }
208+
209+ if _has_tag (meta .det_info , 'wafer.bandpass' ):
210+ bandpasses = meta .det_info .wafer .bandpass
211+ tag_keys ["bandpass" ] = "wafer.bandpass"
212+ else :
213+ bandpasses = meta .det_info .det_cal .bandpass
214+ tag_keys ["bandpass" ] = "det_cal.bandpass"
215+
216+ tag_keys .update (self ._tags )
204217
205218 # record one metric per wafer slot, per bandpass
206219 # extract these tags for the metric
207220 tags = []
208221 vals = []
209- for bp in np .unique (meta . det_info . wafer . bandpass ):
222+ for bp in np .unique (bandpasses ):
210223 for ws in np .unique (meta .det_info .wafer_slot ):
211224 subset = np .where (
212- (meta .det_info .wafer_slot == ws ) & (meta . det_info . wafer . bandpass == bp )
225+ (meta .det_info .wafer_slot == ws ) & (bandpasses == bp )
213226 )[0 ]
214227
215228 if len (subset ) > 0 :
@@ -224,7 +237,7 @@ def _process(self, meta):
224237
225238 # get the tags for this wafer (all detectors in this subset share these)
226239 tags_i = {
227- k : _get_tag (meta .det_info , k , subset [0 ]) for k in tag_keys if _has_tag (meta .det_info , k )
240+ k : _get_tag (meta .det_info , i , subset [0 ]) for k , i in tag_keys . items () if _has_tag (meta .det_info , i )
228241 }
229242 tags_i ["telescope" ] = meta .obs_info .telescope
230243
@@ -248,9 +261,11 @@ class PreprocessArrayNET(PreprocessQA):
248261 The config entry supports a `process_args` block where the following
249262 options can be specified:
250263
251- tags : list
252- Keys into `metadata.det_info` to record as tags with the Influx line.
253- Added to the default list ["wafer_slot", "tel_tube", "wafer.bandpass"].
264+ tags : dict
265+ The values are keys into `metadata.det_info` to record as tags with
266+ the Influx line. The keys are addded to the default list
267+ ["wafer_slot", "tel_tube", "bandpass"] with "bandpass" being taken
268+ from "wafer.bandpass" or "det_cal.bandpass" if the former isn't found.
254269 noise_aman : str
255270 The name of the axis manager that holds the white noise array.
256271 (default 'noise')
@@ -269,22 +284,34 @@ def __init__(
269284 # bypass the PreprocessQA __init__
270285 super (PreprocessQA , self ).__init__ (* args , ** kwargs )
271286 # extract parameters
272- self ._tags = process_args .get ("tags" , [] )
287+ self ._tags = process_args .get ("tags" , {} )
273288 self ._noise_aman = process_args .get ("noise_aman" , "noise" )
274- self ._unit_factor = process_args .get ("unit_factor" , 1e6 )
289+ self ._field_name = process_args .get ("field_name" , "" )
290+ self ._unit_factor = process_args .get ("unit_factor" , 1 )
275291
276292 def _process (self , meta ):
277293
278294 # record one metric per wafer_slot per bandpass
279295 # extract these tags for the metric
280- tag_keys = ["wafer_slot" , "tel_tube" , "wafer.bandpass" ]
281- tag_keys += [t for t in self ._tags if t not in tag_keys ]
296+ tag_keys = {
297+ "wafer_slot" : "wafer_slot" ,
298+ "tel_tube" : "tel_tube" ,
299+ }
300+
301+ if _has_tag (meta .det_info , 'wafer.bandpass' ):
302+ bandpasses = meta .det_info .wafer .bandpass
303+ tag_keys ["bandpass" ] = "wafer.bandpass"
304+ else :
305+ bandpasses = meta .det_info .det_cal .bandpass
306+ tag_keys ["bandpass" ] = "det_cal.bandpass"
307+
308+ tag_keys .update (self ._tags )
282309 tags = []
283310 vals = []
284- for bp in np .unique (meta . det_info . wafer . bandpass ):
311+ for bp in np .unique (bandpasses ):
285312 for ws in np .unique (meta .det_info .wafer_slot ):
286313 subset = np .where (
287- (meta .det_info .wafer_slot == ws ) & (meta . det_info . wafer . bandpass == bp )
314+ (meta .det_info .wafer_slot == ws ) & (bandpasses == bp )
288315 )[0 ]
289316
290317 white_noise = meta .preprocess [self ._noise_aman ].white_noise [subset ] * self ._unit_factor
@@ -294,14 +321,14 @@ def _process(self, meta):
294321 vals .append (np .sqrt (1.0 / np .nansum (1.0 / (white_noise [good_indices ])** 2 )))
295322
296323 tags_base = {
297- k : _get_tag (meta .det_info , k , subset [0 ]) for k in tag_keys if _has_tag (meta .det_info , k )
324+ k : _get_tag (meta .det_info , i , subset [0 ]) for k , i in tag_keys . items () if _has_tag (meta .det_info , i )
298325 }
299326 tags_base ["telescope" ] = meta .obs_info .telescope
300327 tags .append (tags_base )
301328
302329 obs_time = [meta .obs_info .timestamp ] * len (tags )
303330 return {
304- "field" : self ._influx_field ,
331+ "field" : f" { self ._influx_field } { '_' + self . _field_name if self . _field_name else '' } " ,
305332 "values" : vals ,
306333 "timestamps" : obs_time ,
307334 "tags" : tags ,
@@ -315,9 +342,11 @@ class PreprocessDetNET(PreprocessQA):
315342 The config entry supports a `process_args` block where the following
316343 options can be specified:
317344
318- tags : list
319- Keys into `metadata.det_info` to record as tags with the Influx line.
320- Added to the default list ["wafer_slot", "tel_tube", "wafer.bandpass"].
345+ tags : dict
346+ The values are keys into `metadata.det_info` to record as tags with
347+ the Influx line. The keys are addded to the default list
348+ ["wafer_slot", "tel_tube", "bandpass"] with "bandpass" being taken
349+ from "wafer.bandpass" or "det_cal.bandpass" if the former isn't found.
321350 noise_aman : str
322351 The name of the axis manager that holds the white noise array.
323352 (default 'noise')
@@ -336,22 +365,34 @@ def __init__(
336365 # bypass the PreprocessQA __init__
337366 super (PreprocessQA , self ).__init__ (* args , ** kwargs )
338367 # extract parameters
339- self ._tags = process_args .get ("tags" , [] )
368+ self ._tags = process_args .get ("tags" , {} )
340369 self ._noise_aman = process_args .get ("noise_aman" , "noise" )
341- self ._unit_factor = process_args .get ("unit_factor" , 1e6 )
370+ self ._field_name = process_args .get ("field_name" , "" )
371+ self ._unit_factor = process_args .get ("unit_factor" , 1 )
342372
343373 def _process (self , meta ):
344374
345375 # record one metric per wafer_slot per bandpass
346376 # extract these tags for the metric
347- tag_keys = ["wafer_slot" , "tel_tube" , "wafer.bandpass" ]
348- tag_keys += [t for t in self ._tags if t not in tag_keys ]
377+ tag_keys = {
378+ "wafer_slot" : "wafer_slot" ,
379+ "tel_tube" : "tel_tube" ,
380+ }
381+
382+ if _has_tag (meta .det_info , 'wafer.bandpass' ):
383+ bandpasses = meta .det_info .wafer .bandpass
384+ tag_keys ["bandpass" ] = "wafer.bandpass"
385+ else :
386+ bandpasses = meta .det_info .det_cal .bandpass
387+ tag_keys ["bandpass" ] = "det_cal.bandpass"
388+
389+ tag_keys .update (self ._tags )
349390 tags = []
350391 vals = []
351- for bp in np .unique (meta . det_info . wafer . bandpass ):
392+ for bp in np .unique (bandpasses ):
352393 for ws in np .unique (meta .det_info .wafer_slot ):
353394 subset = np .where (
354- (meta .det_info .wafer_slot == ws ) & (meta . det_info . wafer . bandpass == bp )
395+ (meta .det_info .wafer_slot == ws ) & (bandpasses == bp )
355396 )[0 ]
356397
357398 white_noise = meta .preprocess [self ._noise_aman ].white_noise [subset ] * self ._unit_factor
@@ -361,14 +402,14 @@ def _process(self, meta):
361402 vals .append (np .sqrt (1.0 / np .nansum (1.0 / (white_noise [good_indices ])** 2 )) * np .sqrt (len (good_indices )))
362403
363404 tags_base = {
364- k : _get_tag (meta .det_info , k , subset [0 ]) for k in tag_keys if _has_tag (meta .det_info , k )
405+ k : _get_tag (meta .det_info , i , subset [0 ]) for k , i in tag_keys . items () if _has_tag (meta .det_info , i )
365406 }
366407 tags_base ["telescope" ] = meta .obs_info .telescope
367408 tags .append (tags_base )
368409
369410 obs_time = [meta .obs_info .timestamp ] * len (tags )
370411 return {
371- "field" : self ._influx_field ,
412+ "field" : f" { self ._influx_field } { '_' + self . _field_name if self . _field_name else '' } " ,
372413 "values" : vals ,
373414 "timestamps" : obs_time ,
374415 "tags" : tags ,
0 commit comments