Skip to content

Commit 18cdb49

Browse files
mmccrackanMichael McCrackan
and
Michael McCrackan
authored
Make noise backwards compatible (#1240)
* make noise backwards compatible * fix typo * adjust test * fix another typo * fix docstring * add no fit case to docstring * add subscan to docstring again --------- Co-authored-by: Michael McCrackan <[email protected]>
1 parent 414d68a commit 18cdb49

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

sotodlib/preprocess/processes.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,19 @@ class Noise(_Preprocess):
486486
Can run data selection of a "max_noise" value.
487487
488488
When ``fit: True``, the parameter ``wn_est`` can be a float or the name of an
489-
axis manager containing an array named ``white_noise``. If not specified and
490-
white noise is fixed, the white noise is calculated with ``calc_wn()`` and used
491-
for ``wn_est``. The calculated white noise is not stored.
489+
axis manager containing an array named ``white_noise``. If not specified
490+
the white noise is calculated with ``calc_wn()`` and used
491+
for ``wn_est``. The calculated white noise will be stored in the noise fit
492+
axis manager.
492493
493-
Example config block::
494+
Example config block for fitting PSD::
494495
495-
- name: "noise
496+
- name: "noise"
496497
fit: False
497498
subscan: False
498499
calc:
499-
wn_f_low: 5
500-
wn_f_high: 10
500+
fwhite: (5, 10)
501+
lowf: 1
501502
f_max: 25
502503
mask: True
503504
wn_est: noise
@@ -507,6 +508,19 @@ class Noise(_Preprocess):
507508
select:
508509
max_noise: 2000
509510
511+
Example config block for calculating white noise only::
512+
513+
- name: "noise"
514+
fit: False
515+
subscan: False
516+
calc:
517+
low_f: 5
518+
high_f: 20
519+
save: True
520+
select:
521+
min_noise: 18e-6
522+
max_noise: 80e-6
523+
510524
If ``fit: True`` this operation will run
511525
:func:`sotodlib.tod_ops.fft_ops.fit_noise_model`, else it will run
512526
:func:`sotodlib.tod_ops.fft_ops.calc_wn`.
@@ -542,15 +556,14 @@ def calc_and_save(self, aman, proc_aman):
542556
else:
543557
calc_wn = True
544558
if calc_wn or wn_est is None:
545-
wn_f_low = self.calc_cfgs.get("wn_f_low", 5)
546-
wn_f_high = self.calc_cfgs.get("wn_f_high", 10)
559+
wn_f_low, wn_f_high = self.calc_cfgs.get('fwhite', (5, 10))
547560
self.calc_cfgs['wn_est'] = tod_ops.fft_ops.calc_wn(aman, pxx=pxx,
548561
freqs=psd.freqs,
549562
low_f=wn_f_low,
550563
high_f=wn_f_high)
551-
552564
if self.calc_cfgs.get('subscan') is None:
553565
self.calc_cfgs['subscan'] = self.subscan
566+
self.calc_cfgs.pop('fwhite', None)
554567
calc_aman = tod_ops.fft_ops.fit_noise_model(aman, pxx=pxx,
555568
f=psd.freqs,
556569
merge_fit=True,
@@ -561,8 +574,8 @@ def calc_and_save(self, aman, proc_aman):
561574
else:
562575
calc_aman.wrap("white_noise", self.calc_cfgs['wn_est'], [(0,"dets"), (1,"subscans")])
563576
else:
564-
wn_f_low = self.calc_cfgs.get("wn_f_low", 5)
565-
wn_f_high = self.calc_cfgs.get("wn_f_high", 10)
577+
wn_f_low = self.calc_cfgs.get("low_f", 5)
578+
wn_f_high = self.calc_cfgs.get("high_f", 10)
566579
wn = tod_ops.fft_ops.calc_wn(aman, pxx=pxx,
567580
freqs=psd.freqs,
568581
low_f=wn_f_low,

sotodlib/tod_ops/fft_ops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def fit_noise_model(
613613
wn_est=4E-5,
614614
alpha_est=3.4,
615615
merge_fit=False,
616-
f_min=None,
616+
lowf=None,
617617
f_max=100,
618618
merge_name="noise_fit_stats",
619619
merge_psd=True,
@@ -656,9 +656,9 @@ def fit_noise_model(
656656
initial values are applied for each detector.
657657
merge_fit : bool
658658
Merges fit and fit statistics into input axis manager.
659-
f_min : float
659+
lowf : float
660660
Minimum frequency to include in the fitting.
661-
Default is None which selects f_min as the second index of f.
661+
Default is None which selects lowf as the second index of f.
662662
f_max : float
663663
Maximum frequency to include in the fitting. This is particularly
664664
important for lowpass filtered data such as that post demodulation
@@ -723,18 +723,18 @@ def fit_noise_model(
723723

724724
if subscan:
725725
fit_noise_model_kwargs = {"fknee_est": fknee_est, "wn_est": wn_est, "alpha_est": alpha_est,
726-
"f_min": f_min, "f_max": f_max, "fixed_param": fixed_param,
726+
"lowf": lowf, "f_max": f_max, "fixed_param": fixed_param,
727727
"binning": binning, "unbinned_mode": unbinned_mode, "base": base,
728728
"freq_spacing": freq_spacing}
729729
fitout, covout = _fit_noise_model_subscan(aman, signal, f, pxx, fit_noise_model_kwargs)
730730
axis_map_fit = [(0, "dets"), (1, "noise_model_coeffs"), (2, aman.subscans)]
731731
axis_map_cov = [(0, "dets"), (1, "noise_model_coeffs"), (2, "noise_model_coeffs"), (3, aman.subscans)]
732732
else:
733733
eix = np.argmin(np.abs(f - f_max))
734-
if f_min is None:
734+
if lowf is None:
735735
six = 1
736736
else:
737-
six = np.argmin(np.abs(f - f_min))
737+
six = np.argmin(np.abs(f - lowf))
738738
f = f[six:eix]
739739
pxx = pxx[:, six:eix]
740740
bin_size = 1

tests/test_tod_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_psd(self):
352352

353353
tod_ops.detrend_tod(aman)
354354
freqs_output, Pxx_output = tod_ops.fft_ops.calc_psd(aman, nperseg=200*100)
355-
fit_result = tod_ops.fft_ops.fit_noise_model(aman, wn_est=50, fknee_est=1.0, alpha_est=3.3, f_min=0.05, f_max=5,
355+
fit_result = tod_ops.fft_ops.fit_noise_model(aman, wn_est=50, fknee_est=1.0, alpha_est=3.3, lowf=0.05, f_max=5,
356356
binning=True, psdargs={'nperseg':200*1000})
357357
wnl_fit = fit_result.fit[:, 0]
358358
fk_fit = fit_result.fit[:, 1]

0 commit comments

Comments
 (0)