Skip to content

Commit 9e97eb9

Browse files
committed
Merge branch 'master' into c1f_and_common_mode
2 parents 37f3e1e + 5f6b31e commit 9e97eb9

File tree

3 files changed

+112
-47
lines changed

3 files changed

+112
-47
lines changed

sotodlib/preprocess/pcore.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def gen_metric(
553553
proc_aman,
554554
flags_key=None,
555555
percentiles=[0, 50, 75, 90, 95, 100],
556-
tags=[],
556+
tags={},
557557
):
558558
""" Generate a QA metric from the output of this process.
559559
@@ -569,9 +569,11 @@ def gen_metric(
569569
process name.
570570
percentiles : list
571571
Percentiles to compute across detectors
572-
tags : list
573-
Keys into `metadata.det_info` to record as tags with the Influx line.
574-
Added to the default list ["wafer_slot", "tel_tube", "wafer.bandpass"].
572+
tags : dict
573+
The values are keys into `metadata.det_info` to record as tags with
574+
the Influx line. The keys are addded to the default list
575+
["wafer_slot", "tel_tube", "bandpass"] with "bandpass" being taken
576+
from "wafer.bandpass" or "det_cal.bandpass" if the former isn't found.
575577
576578
Returns
577579
-------
@@ -592,17 +594,28 @@ def gen_metric(
592594
raise ValueError(f"Could not parse flags_key {flags_key}")
593595

594596
# add specified tags
595-
tag_keys = ["wafer_slot", "tel_tube", "wafer.bandpass"]
596-
tag_keys += [t for t in tags if t not in tag_keys]
597+
from ..qa.metrics import _get_tag, _has_tag
598+
tag_keys = {
599+
"wafer_slot": "wafer_slot",
600+
"tel_tube": "tel_tube",
601+
}
602+
603+
if _has_tag(meta.det_info, 'wafer.bandpass'):
604+
bandpasses = meta.det_info.wafer.bandpass
605+
tag_keys["bandpass"] = "wafer.bandpass"
606+
else:
607+
bandpasses = meta.det_info.det_cal.bandpass
608+
tag_keys["bandpass"] = "det_cal.bandpass"
609+
610+
tag_keys.update(tags)
597611

598612
tags = []
599613
vals = []
600-
from ..qa.metrics import _get_tag, _has_tag
601614
# record one metric per wafer slot, per bandpass
602-
for bp in np.unique(meta.det_info.wafer.bandpass):
615+
for bp in np.unique(bandpasses):
603616
for ws in np.unique(meta.det_info.wafer_slot):
604617
subset = np.where(
605-
(meta.det_info.wafer_slot == ws) & (meta.det_info.wafer.bandpass == bp)
618+
(meta.det_info.wafer_slot == ws) & (bandpasses == bp)
606619
)[0]
607620

608621
# Compute the number of samples that were flagged
@@ -623,7 +636,7 @@ def gen_metric(
623636

624637
# get the tags for this wafer (all detectors in this subset share these)
625638
tags_base = {
626-
k: _get_tag(meta.det_info, k, subset[0]) for k in tag_keys if _has_tag(meta.det_info, k)
639+
k: _get_tag(meta.det_info, i, subset[0]) for k, i in tag_keys.items() if _has_tag(meta.det_info, i)
627640
}
628641
tags_base["telescope"] = meta.obs_info.telescope
629642

sotodlib/preprocess/processes.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -832,16 +832,27 @@ def gen_metric(cls, meta, proc_aman):
832832
`site_pipeline.monitor.Monitor.record`
833833
"""
834834
# record one metric per wafer_slot per bandpass
835-
# extract these tags for the metric
836-
tag_keys = ["wafer_slot", "tel_tube", "wafer.bandpass"]
835+
# add specified tags
836+
from ..qa.metrics import _get_tag, _has_tag
837+
tag_keys = {
838+
"wafer_slot": "wafer_slot",
839+
"tel_tube": "tel_tube",
840+
}
841+
842+
if _has_tag(meta.det_info, 'wafer.bandpass'):
843+
bandpasses = meta.det_info.wafer.bandpass
844+
tag_keys["bandpass"] = "wafer.bandpass"
845+
else:
846+
bandpasses = meta.det_info.det_cal.bandpass
847+
tag_keys["bandpass"] = "det_cal.bandpass"
848+
837849
tags = []
838850
vals = []
839-
from ..qa.metrics import _get_tag, _has_tag
840851
import re
841-
for bp in np.unique(meta.det_info.wafer.bandpass):
852+
for bp in np.unique(bandpasses):
842853
for ws in np.unique(meta.det_info.wafer_slot):
843854
subset = np.where(
844-
(meta.det_info.wafer_slot == ws) & (meta.det_info.wafer.bandpass == bp)
855+
(meta.det_info.wafer_slot == ws) & (bandpasses == bp)
845856
)[0]
846857

847858
if len(subset) > 0:
@@ -867,7 +878,7 @@ def gen_metric(cls, meta, proc_aman):
867878
mean = coeff_amp[nonzero].mean(axis=0)
868879

869880
tags_base = {
870-
k: _get_tag(meta.det_info, k, subset[0]) for k in tag_keys if _has_tag(meta.det_info, k)
881+
k: _get_tag(meta.det_info, i, subset[0]) for k, i in tag_keys.items() if _has_tag(meta.det_info, i)
871882
}
872883
tags_base["telescope"] = meta.obs_info.telescope
873884

sotodlib/qa/metrics.py

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)