Skip to content

Commit 26b2e73

Browse files
committed
feat: add more flexibility when inserting default iir params and add LAT
time range
1 parent acecffd commit 26b2e73

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

sotodlib/obs_ops/utils.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import datetime
22
from sotodlib import core
33
import logging
4+
import numpy as np
45

56
logger = logging.getLogger(__name__)
67

78

8-
def correct_iir_params(aman):
9+
def correct_iir_params(aman, ignore_time=False, check_srate=-1):
910
"""
1011
Correct missing iir_params by default values.
1112
This corrects iir_params only when the observation is within the time_range
@@ -17,6 +18,12 @@ def correct_iir_params(aman):
1718
----------
1819
aman: AxisManager of observation
1920
21+
ignore_time: Boolean. True if we don't want to check if the observation is within
22+
a known bad time range.
23+
24+
check_srate: If greater than 0 will check that the observations sample rate is within
25+
check_srate Hz of 200 Hz. If less than 0 the check is skipped.
26+
2027
Returns
2128
-------
2229
List of field names that have no iir_params
@@ -31,11 +38,11 @@ def correct_iir_params(aman):
3138
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
3239
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]
3340

34-
time_range = {
41+
time_ranges = {
3542
'satp1': None,
3643
'satp2': None,
37-
'satp3': ['2023-01-01', '2024-10-24'],
38-
'lat': None,
44+
'satp3': [('2023-01-01', '2024-10-24')],
45+
'lat': [(1745970733, 1746624934)],
3946
}[aman.obs_info.telescope]
4047

4148
iir_missing = []
@@ -46,14 +53,24 @@ def correct_iir_params(aman):
4653
iir_missing.append(_field)
4754

4855
within_range = False
49-
if time_range is not None:
50-
t0 = datetime.datetime.strptime(time_range[0], '%Y-%m-%d')
51-
t1 = datetime.datetime.strptime(time_range[1], '%Y-%m-%d')
52-
t0 = t0.replace(tzinfo=datetime.timezone.utc).timestamp()
53-
t1 = t1.replace(tzinfo=datetime.timezone.utc).timestamp()
54-
within_range = aman.timestamps[0] >= t0 and aman.timestamps[-1] <= t1
56+
if time_ranges is not None and not ignore_time:
57+
for t0, t1 in time_ranges:
58+
if isinstance(t0, str):
59+
t0 = datetime.datetime.strptime(t0, '%Y-%m-%d')
60+
t0 = t0.replace(tzinfo=datetime.timezone.utc).timestamp()
61+
if isinstance(t1, str):
62+
t1 = datetime.datetime.strptime(t1, '%Y-%m-%d')
63+
t1 = t1.replace(tzinfo=datetime.timezone.utc).timestamp()
64+
within_range = aman.timestamps[0] >= t0 and aman.timestamps[-1] <= t1
65+
if within_range:
66+
break
67+
68+
if check_srate >= 0:
69+
srate = 1./np.mean(np.diff(aman.timestamps))
70+
if abs(srate - 200) > check_srate:
71+
raise ValueError(f"Sample rate is {srate}, too far from 200 Hz to use default params.")
5572

56-
if within_range:
73+
if within_range or ignore_time:
5774
for field in iir_missing:
5875
logger.warning(f'iir_params are missing on {field}. '
5976
'Fill default params.')

0 commit comments

Comments
 (0)