Skip to content

feat: add more flexibility when inserting default iir params #1221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions sotodlib/obs_ops/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime
from sotodlib import core
import logging
import numpy as np

logger = logging.getLogger(__name__)


def correct_iir_params(aman):
def correct_iir_params(aman, ignore_time=False, check_srate=-1):
"""
Correct missing iir_params by default values.
This corrects iir_params only when the observation is within the time_range
Expand All @@ -17,6 +18,12 @@ def correct_iir_params(aman):
----------
aman: AxisManager of observation

ignore_time: Boolean. True if we don't want to check if the observation is within
a known bad time range.

check_srate: If greater than 0 will check that the observations sample rate is within
check_srate Hz of 200 Hz. If less than 0 the check is skipped.

Returns
-------
List of field names that have no iir_params
Expand All @@ -31,11 +38,11 @@ def correct_iir_params(aman):
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]

time_range = {
time_ranges = {
'satp1': None,
'satp2': None,
'satp3': ['2023-01-01', '2024-10-24'],
'lat': None,
'satp3': [('2023-01-01', '2024-10-24')],
'lat': [(1745970733, 1746624934)],
}[aman.obs_info.telescope]

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

within_range = False
if time_range is not None:
t0 = datetime.datetime.strptime(time_range[0], '%Y-%m-%d')
t1 = datetime.datetime.strptime(time_range[1], '%Y-%m-%d')
t0 = t0.replace(tzinfo=datetime.timezone.utc).timestamp()
t1 = t1.replace(tzinfo=datetime.timezone.utc).timestamp()
within_range = aman.timestamps[0] >= t0 and aman.timestamps[-1] <= t1
if time_ranges is not None and not ignore_time:
for t0, t1 in time_ranges:
if isinstance(t0, str):
t0 = datetime.datetime.strptime(t0, '%Y-%m-%d')
t0 = t0.replace(tzinfo=datetime.timezone.utc).timestamp()
if isinstance(t1, str):
t1 = datetime.datetime.strptime(t1, '%Y-%m-%d')
t1 = t1.replace(tzinfo=datetime.timezone.utc).timestamp()
within_range = aman.timestamps[0] >= t0 and aman.timestamps[-1] <= t1
if within_range:
break

if check_srate >= 0:
srate = 1./np.mean(np.diff(aman.timestamps))
if abs(srate - 200) > check_srate:
raise ValueError(f"Sample rate is {srate}, too far from 200 Hz to use default params.")

if within_range:
if within_range or ignore_time:
for field in iir_missing:
logger.warning(f'iir_params are missing on {field}. '
'Fill default params.')
Expand Down