1
1
import datetime
2
2
from sotodlib import core
3
3
import logging
4
+ import numpy as np
4
5
5
6
logger = logging .getLogger (__name__ )
6
7
7
8
8
- def correct_iir_params (aman ):
9
+ def correct_iir_params (aman , ignore_time = False , check_srate = - 1 ):
9
10
"""
10
11
Correct missing iir_params by default values.
11
12
This corrects iir_params only when the observation is within the time_range
@@ -17,6 +18,12 @@ def correct_iir_params(aman):
17
18
----------
18
19
aman: AxisManager of observation
19
20
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
+
20
27
Returns
21
28
-------
22
29
List of field names that have no iir_params
@@ -31,11 +38,11 @@ def correct_iir_params(aman):
31
38
0.00000000e+00 , 0.00000000e+00 , 0.00000000e+00 , 0.00000000e+00 ,
32
39
0.00000000e+00 , 0.00000000e+00 , 0.00000000e+00 , 0.00000000e+00 ]
33
40
34
- time_range = {
41
+ time_ranges = {
35
42
'satp1' : None ,
36
43
'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 )] ,
39
46
}[aman .obs_info .telescope ]
40
47
41
48
iir_missing = []
@@ -46,14 +53,24 @@ def correct_iir_params(aman):
46
53
iir_missing .append (_field )
47
54
48
55
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." )
55
72
56
- if within_range :
73
+ if within_range or ignore_time :
57
74
for field in iir_missing :
58
75
logger .warning (f'iir_params are missing on { field } . '
59
76
'Fill default params.' )
0 commit comments