forked from IMAP-Science-Operations-Center/imap_processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.py
More file actions
165 lines (133 loc) · 3.34 KB
/
constants.py
File metadata and controls
165 lines (133 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""Collection of constant types or values for MAG."""
from enum import Enum
import numpy as np
class DataMode(Enum):
"""
Enum for MAG data modes: burst and normal (BURST + NORM).
Attributes
----------
BURST: str
Burst data mode - higher frequency data
NORM: str
Normal data mode - lower frequency data (downsampled from burst)
"""
BURST = "BURST"
NORM = "NORM"
class Sensor(Enum):
"""
Enum for MAG sensors: raw, MAGo, and MAGi (RAW, MAGO, MAGI).
Attributes
----------
MAGO : str
MAGo sensor - for the outboard sensor. This is nominally expected to be the
primary sensor.
MAGI : str
MAGi sensor - for the inboard sensor.
RAW : str
RAW data - contains both sensors. Here, the vectors are unprocessed.
"""
MAGO = "MAGO"
MAGI = "MAGI"
RAW = "RAW"
class PrimarySensor(Enum):
"""
Enum for primary sensor: MAGo and MAGi (MAGO, MAGI).
This corresponds to the PRI_SENS field in the MAG Level 0 data.
Attributes
----------
MAGO : int
Primary sensor is MAGo.
MAGI : int
Primary sensor is MAGi.
"""
MAGO = 0
MAGI = 1
class VecSec(Enum):
"""Enum for all valid vector rates (Vectors per second)."""
ONE_VEC_PER_S = 1
TWO_VECS_PER_S = 2
FOUR_VECS_PER_S = 4
EIGHT_VECS_PER_S = 8
SIXTEEN_VECS_PER_S = 16
THIRTY_TWO_VECS_PER_S = 32
SIXTY_FOUR_VECS_PER_S = 64
ONE_TWENTY_EIGHT_VECS_PER_S = 128
# Possible sensor rates
POSSIBLE_RATES = [e.value for e in VecSec]
class ModeFlags(Enum):
"""Enum for MAG mode flags: burst and normal (BURST + NORM)."""
NORM = 0
BURST = 1
MISSING = -1
FIBONACCI_SEQUENCE = [
1,
2,
3,
5,
8,
13,
21,
34,
55,
89,
144,
233,
377,
610,
987,
1597,
2584,
4181,
6765,
10946,
17711,
28657,
46368,
75025,
121393,
196418,
317811,
514229,
832040,
1346269,
2178309,
3524578,
5702887,
9227465,
14930352,
24157817,
39088169,
63245986,
102334155,
165580141,
]
MAX_FINE_TIME = np.iinfo(np.uint16).max # maximum 16 bit unsigned int
AXIS_COUNT = 3
RANGE_BIT_WIDTH = 2
MAX_COMPRESSED_VECTOR_BITS = 60
FILLVAL = -1e31
# Relative tolerance for L1C timestamp-gap checks; allows small clock-drift
# variation around the expected cadence before a spacing is treated as a gap.
# This is 7.5% of expected_gap = 1e9 / vectors_per_second ns
# (75, 37.5, 18.75, or 9.375 ms at 1, 2, 4, or 8 Hz, respectively).
L1C_TIMESTAMP_GAP_TOLERANCE = 0.075
def vectors_per_second_from_string(vecsec_string: str) -> dict:
"""
Extract the vectors per second from a string into a dictionary.
Dictionary format: {start_time: vecsec, start_time: vecsec}.
Parameters
----------
vecsec_string : str
A string of the form "start:vecsec,start:vecsec" where start is the time in
nanoseconds and vecsec is the number of vectors per second.
Returns
-------
dict
A dictionary of the form {start_time: vecsec, start_time: vecsec}.
"""
vecsec_dict = {}
vecsec_segments = vecsec_string.split(",")
for vecsec_segment in vecsec_segments:
start_time, vecsec = vecsec_segment.split(":")
vecsec_dict[int(start_time)] = int(vecsec)
return vecsec_dict