spectre-core 0.0.9__py3-none-any.whl → 0.0.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spectre_core/__init__.py +0 -3
- spectre_core/_file_io/__init__.py +15 -0
- spectre_core/_file_io/file_handlers.py +128 -0
- spectre_core/capture_configs/__init__.py +29 -0
- spectre_core/capture_configs/_capture_config.py +85 -0
- spectre_core/capture_configs/_capture_templates.py +222 -0
- spectre_core/capture_configs/_parameters.py +110 -0
- spectre_core/capture_configs/_pconstraints.py +82 -0
- spectre_core/capture_configs/_ptemplates.py +450 -0
- spectre_core/capture_configs/_pvalidators.py +173 -0
- spectre_core/chunks/__init__.py +17 -201
- spectre_core/chunks/{base.py → _base.py} +15 -60
- spectre_core/chunks/_chunks.py +200 -0
- spectre_core/chunks/{factory.py → _factory.py} +6 -7
- spectre_core/chunks/library/{callisto/chunk.py → _callisto.py} +4 -7
- spectre_core/chunks/library/{fixed/chunk.py → _fixed_center_frequency.py} +7 -64
- spectre_core/chunks/library/_swept_center_frequency.py +103 -0
- spectre_core/config/__init__.py +20 -0
- spectre_core/config/_paths.py +77 -0
- spectre_core/config/_time_formats.py +15 -0
- spectre_core/exceptions.py +4 -5
- spectre_core/logging/__init__.py +11 -0
- spectre_core/logging/_configure.py +35 -0
- spectre_core/logging/_decorators.py +19 -0
- spectre_core/{logging.py → logging/_log_handlers.py} +13 -58
- spectre_core/plotting/__init__.py +7 -1
- spectre_core/plotting/{base.py → _base.py} +40 -20
- spectre_core/plotting/_format.py +18 -0
- spectre_core/plotting/{panel_stack.py → _panel_stack.py} +48 -48
- spectre_core/plotting/_panels.py +234 -0
- spectre_core/post_processing/__init__.py +10 -2
- spectre_core/post_processing/_base.py +119 -0
- spectre_core/post_processing/{factory.py → _factory.py} +7 -6
- spectre_core/post_processing/{post_processor.py → _post_processor.py} +3 -3
- spectre_core/post_processing/library/_fixed_center_frequency.py +115 -0
- spectre_core/post_processing/library/_swept_center_frequency.py +382 -0
- spectre_core/receivers/__init__.py +12 -2
- spectre_core/receivers/_base.py +352 -0
- spectre_core/receivers/{factory.py → _factory.py} +2 -2
- spectre_core/receivers/_spec_names.py +20 -0
- spectre_core/receivers/gr/__init__.py +3 -0
- spectre_core/receivers/gr/_base.py +33 -0
- spectre_core/receivers/gr/_rsp1a.py +158 -0
- spectre_core/receivers/gr/_test.py +123 -0
- spectre_core/receivers/library/_rsp1a.py +61 -0
- spectre_core/receivers/library/_test.py +221 -0
- spectre_core/spectrograms/__init__.py +18 -0
- spectre_core/spectrograms/{analytical.py → _analytical.py} +29 -27
- spectre_core/spectrograms/{array_operations.py → _array_operations.py} +47 -1
- spectre_core/spectrograms/{spectrogram.py → _spectrogram.py} +62 -35
- spectre_core/spectrograms/{transform.py → _transform.py} +76 -89
- spectre_core/{post_processing/library → wgetting}/__init__.py +4 -5
- spectre_core/wgetting/_callisto.py +155 -0
- {spectre_core-0.0.9.dist-info → spectre_core-0.0.10.dist-info}/METADATA +1 -1
- spectre_core-0.0.10.dist-info/RECORD +63 -0
- spectre_core/cfg.py +0 -116
- spectre_core/chunks/library/__init__.py +0 -8
- spectre_core/chunks/library/sweep/__init__.py +0 -0
- spectre_core/chunks/library/sweep/chunk.py +0 -400
- spectre_core/dynamic_imports.py +0 -22
- spectre_core/file_handlers/base.py +0 -68
- spectre_core/file_handlers/configs.py +0 -271
- spectre_core/file_handlers/json.py +0 -40
- spectre_core/file_handlers/text.py +0 -21
- spectre_core/plotting/factory.py +0 -26
- spectre_core/plotting/format.py +0 -19
- spectre_core/plotting/library/__init__.py +0 -7
- spectre_core/plotting/library/frequency_cuts/panel.py +0 -74
- spectre_core/plotting/library/integral_over_frequency/panel.py +0 -34
- spectre_core/plotting/library/spectrogram/panel.py +0 -92
- spectre_core/plotting/library/time_cuts/panel.py +0 -77
- spectre_core/plotting/panel_register.py +0 -13
- spectre_core/post_processing/base.py +0 -132
- spectre_core/post_processing/library/fixed/__init__.py +0 -0
- spectre_core/post_processing/library/fixed/event_handler.py +0 -40
- spectre_core/post_processing/library/sweep/event_handler.py +0 -54
- spectre_core/receivers/base.py +0 -422
- spectre_core/receivers/library/__init__.py +0 -7
- spectre_core/receivers/library/rsp1a/__init__.py +0 -0
- spectre_core/receivers/library/rsp1a/gr/__init__.py +0 -0
- spectre_core/receivers/library/rsp1a/gr/fixed.py +0 -104
- spectre_core/receivers/library/rsp1a/gr/sweep.py +0 -129
- spectre_core/receivers/library/rsp1a/receiver.py +0 -68
- spectre_core/receivers/library/rspduo/__init__.py +0 -0
- spectre_core/receivers/library/rspduo/gr/__init__.py +0 -0
- spectre_core/receivers/library/rspduo/gr/tuner_1_fixed.py +0 -114
- spectre_core/receivers/library/rspduo/gr/tuner_1_sweep.py +0 -131
- spectre_core/receivers/library/rspduo/gr/tuner_2_fixed.py +0 -120
- spectre_core/receivers/library/rspduo/gr/tuner_2_sweep.py +0 -119
- spectre_core/receivers/library/rspduo/receiver.py +0 -97
- spectre_core/receivers/library/test/__init__.py +0 -0
- spectre_core/receivers/library/test/gr/__init__.py +0 -0
- spectre_core/receivers/library/test/gr/cosine_signal_1.py +0 -83
- spectre_core/receivers/library/test/gr/tagged_staircase.py +0 -93
- spectre_core/receivers/library/test/receiver.py +0 -203
- spectre_core/receivers/validators.py +0 -231
- spectre_core/web_fetch/callisto.py +0 -101
- spectre_core-0.0.9.dist-info/RECORD +0 -74
- /spectre_core/chunks/{chunk_register.py → _register.py} +0 -0
- /spectre_core/post_processing/{event_handler_register.py → _register.py} +0 -0
- /spectre_core/receivers/{receiver_register.py → _register.py} +0 -0
- /spectre_core/{chunks/library/callisto/__init__.py → receivers/gr/_rspduo.py} +0 -0
- /spectre_core/{chunks/library/fixed/__init__.py → receivers/library/_rspduo.py} +0 -0
- {spectre_core-0.0.9.dist-info → spectre_core-0.0.10.dist-info}/LICENSE +0 -0
- {spectre_core-0.0.9.dist-info → spectre_core-0.0.10.dist-info}/WHEEL +0 -0
- {spectre_core-0.0.9.dist-info → spectre_core-0.0.10.dist-info}/top_level.txt +0 -0
@@ -1,83 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: GPL-3.0
|
6
|
-
#
|
7
|
-
# GNU Radio Python Flow Graph
|
8
|
-
# Title: Not titled yet
|
9
|
-
# GNU Radio version: 3.10.1.1
|
10
|
-
|
11
|
-
# SPDX-FileCopyrightText: © 2024 Jimmy Fitzpatrick <jcfitzpatrick12@gmail.com>
|
12
|
-
# This file is part of SPECTRE
|
13
|
-
# SPDX-License-Identifier: GPL-3.0-or-later
|
14
|
-
|
15
|
-
import sys
|
16
|
-
import signal
|
17
|
-
from typing import Any
|
18
|
-
|
19
|
-
from gnuradio import analog
|
20
|
-
from gnuradio import blocks
|
21
|
-
from gnuradio import gr
|
22
|
-
from gnuradio.filter import firdes
|
23
|
-
from gnuradio.fft import window
|
24
|
-
from gnuradio.eng_arg import eng_float, intx
|
25
|
-
from gnuradio import eng_notation
|
26
|
-
from gnuradio import spectre
|
27
|
-
|
28
|
-
from spectre_core.cfg import CHUNKS_DIR_PATH
|
29
|
-
from spectre_core.file_handlers.configs import CaptureConfig
|
30
|
-
|
31
|
-
class cosine_signal_1(gr.top_block):
|
32
|
-
|
33
|
-
def __init__(self,
|
34
|
-
capture_config: CaptureConfig):
|
35
|
-
gr.top_block.__init__(self, "cosine-signal-1", catch_exceptions=True)
|
36
|
-
|
37
|
-
##################################################
|
38
|
-
# Unpack capture config
|
39
|
-
##################################################
|
40
|
-
samp_rate = capture_config['samp_rate']
|
41
|
-
tag = capture_config['tag']
|
42
|
-
chunk_size = capture_config['chunk_size']
|
43
|
-
frequency = capture_config['frequency']
|
44
|
-
amplitude = capture_config['amplitude']
|
45
|
-
|
46
|
-
##################################################
|
47
|
-
# Blocks
|
48
|
-
##################################################
|
49
|
-
self.spectre_batched_file_sink_0 = spectre.batched_file_sink(CHUNKS_DIR_PATH, tag, chunk_size, samp_rate)
|
50
|
-
self.blocks_throttle_0_1 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
|
51
|
-
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
|
52
|
-
self.blocks_null_source_1 = blocks.null_source(gr.sizeof_float*1)
|
53
|
-
self.blocks_float_to_complex_1 = blocks.float_to_complex(1)
|
54
|
-
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, frequency, amplitude, 0, 0)
|
55
|
-
|
56
|
-
|
57
|
-
##################################################
|
58
|
-
# Connections
|
59
|
-
##################################################
|
60
|
-
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
|
61
|
-
self.connect((self.blocks_float_to_complex_1, 0), (self.spectre_batched_file_sink_0, 0))
|
62
|
-
self.connect((self.blocks_null_source_1, 0), (self.blocks_throttle_0_1, 0))
|
63
|
-
self.connect((self.blocks_throttle_0, 0), (self.blocks_float_to_complex_1, 0))
|
64
|
-
self.connect((self.blocks_throttle_0_1, 0), (self.blocks_float_to_complex_1, 1))
|
65
|
-
|
66
|
-
|
67
|
-
def main(capture_config: CaptureConfig,
|
68
|
-
top_block_cls=cosine_signal_1,
|
69
|
-
options=None):
|
70
|
-
tb = top_block_cls(capture_config)
|
71
|
-
|
72
|
-
def sig_handler(sig=None, frame=None):
|
73
|
-
tb.stop()
|
74
|
-
tb.wait()
|
75
|
-
|
76
|
-
sys.exit(0)
|
77
|
-
|
78
|
-
signal.signal(signal.SIGINT, sig_handler)
|
79
|
-
signal.signal(signal.SIGTERM, sig_handler)
|
80
|
-
|
81
|
-
tb.start()
|
82
|
-
|
83
|
-
tb.wait()
|
@@ -1,93 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: GPL-3.0
|
6
|
-
#
|
7
|
-
# GNU Radio Python Flow Graph
|
8
|
-
# Title: Not titled yet
|
9
|
-
# GNU Radio version: 3.10.1.1
|
10
|
-
|
11
|
-
# SPDX-FileCopyrightText: © 2024 Jimmy Fitzpatrick <jcfitzpatrick12@gmail.com>
|
12
|
-
# This file is part of SPECTRE
|
13
|
-
# SPDX-License-Identifier: GPL-3.0-or-later
|
14
|
-
|
15
|
-
import sys
|
16
|
-
import signal
|
17
|
-
from argparse import ArgumentParser
|
18
|
-
from typing import Any
|
19
|
-
|
20
|
-
from gnuradio import blocks
|
21
|
-
from gnuradio import gr
|
22
|
-
from gnuradio.filter import firdes
|
23
|
-
from gnuradio.fft import window
|
24
|
-
from gnuradio.eng_arg import eng_float, intx
|
25
|
-
from gnuradio import eng_notation
|
26
|
-
from gnuradio import spectre
|
27
|
-
|
28
|
-
from spectre_core.cfg import CHUNKS_DIR_PATH
|
29
|
-
from spectre_core.file_handlers.configs import CaptureConfig
|
30
|
-
|
31
|
-
class tagged_staircase(gr.top_block):
|
32
|
-
|
33
|
-
def __init__(self,
|
34
|
-
capture_config: CaptureConfig):
|
35
|
-
gr.top_block.__init__(self, "tagged-staircase", catch_exceptions=True)
|
36
|
-
|
37
|
-
##################################################
|
38
|
-
# Unpack capture config
|
39
|
-
##################################################
|
40
|
-
tag = capture_config['tag']
|
41
|
-
step_increment = capture_config['step_increment']
|
42
|
-
samp_rate = capture_config['samp_rate']
|
43
|
-
min_samples_per_step = capture_config['min_samples_per_step']
|
44
|
-
max_samples_per_step = capture_config['max_samples_per_step']
|
45
|
-
freq_step = capture_config['freq_step']
|
46
|
-
chunk_size = capture_config['chunk_size']
|
47
|
-
is_sweeping = True
|
48
|
-
|
49
|
-
##################################################
|
50
|
-
# Blocks
|
51
|
-
##################################################
|
52
|
-
self.spectre_tagged_staircase_0 = spectre.tagged_staircase(min_samples_per_step,
|
53
|
-
max_samples_per_step,
|
54
|
-
freq_step,
|
55
|
-
step_increment,
|
56
|
-
samp_rate)
|
57
|
-
self.spectre_batched_file_sink_0 = spectre.batched_file_sink(CHUNKS_DIR_PATH,
|
58
|
-
tag,
|
59
|
-
chunk_size,
|
60
|
-
samp_rate,
|
61
|
-
is_sweeping,
|
62
|
-
'rx_freq',
|
63
|
-
0
|
64
|
-
)
|
65
|
-
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate, True)
|
66
|
-
|
67
|
-
|
68
|
-
##################################################
|
69
|
-
# Connections
|
70
|
-
##################################################
|
71
|
-
self.connect((self.blocks_throttle_0, 0), (self.spectre_batched_file_sink_0, 0))
|
72
|
-
self.connect((self.spectre_tagged_staircase_0, 0), (self.blocks_throttle_0, 0))
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def main(capture_config: CaptureConfig,
|
78
|
-
top_block_cls=tagged_staircase,
|
79
|
-
options=None):
|
80
|
-
tb = top_block_cls(capture_config)
|
81
|
-
|
82
|
-
def sig_handler(sig=None, frame=None):
|
83
|
-
tb.stop()
|
84
|
-
tb.wait()
|
85
|
-
|
86
|
-
sys.exit(0)
|
87
|
-
|
88
|
-
signal.signal(signal.SIGINT, sig_handler)
|
89
|
-
signal.signal(signal.SIGTERM, sig_handler)
|
90
|
-
|
91
|
-
tb.start()
|
92
|
-
|
93
|
-
tb.wait()
|
@@ -1,203 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: © 2024 Jimmy Fitzpatrick <jcfitzpatrick12@gmail.com>
|
2
|
-
# This file is part of SPECTRE
|
3
|
-
# SPDX-License-Identifier: GPL-3.0-or-later
|
4
|
-
|
5
|
-
from spectre_core.receivers import validators
|
6
|
-
from spectre_core.receivers.base import SPECTREReceiver
|
7
|
-
from spectre_core.receivers.receiver_register import register_receiver
|
8
|
-
from spectre_core.receivers.library.test.gr import cosine_signal_1
|
9
|
-
from spectre_core.receivers.library.test.gr import tagged_staircase
|
10
|
-
from spectre_core.file_handlers.configs import CaptureConfig
|
11
|
-
|
12
|
-
|
13
|
-
@register_receiver("test")
|
14
|
-
class Receiver(SPECTREReceiver):
|
15
|
-
def __init__(self, *args, **kwargs):
|
16
|
-
super().__init__(*args, **kwargs)
|
17
|
-
|
18
|
-
|
19
|
-
def _set_capture_methods(self) -> None:
|
20
|
-
self._capture_methods = {
|
21
|
-
"cosine-signal-1": self.__cosine_signal_1,
|
22
|
-
"tagged-staircase": self.__tagged_staircase
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
def _set_validators(self) -> None:
|
27
|
-
self._validators = {
|
28
|
-
"cosine-signal-1": self.__cosine_signal_1_validator,
|
29
|
-
"tagged-staircase": self.__tagged_staircase_validator
|
30
|
-
}
|
31
|
-
|
32
|
-
|
33
|
-
def _set_type_templates(self) -> None:
|
34
|
-
self._type_templates = {
|
35
|
-
"cosine-signal-1": {
|
36
|
-
"samp_rate": int, # [Hz]
|
37
|
-
"frequency": float, # [Hz]
|
38
|
-
"amplitude": float, # unitless
|
39
|
-
"chunk_size": int, # [s]
|
40
|
-
"joining_time": int, # [s]
|
41
|
-
"time_resolution": float, # [s]
|
42
|
-
"frequency_resolution": float, # [Hz]
|
43
|
-
"window_type": str, # the window type for the STFFT
|
44
|
-
"window_kwargs": dict, # keyword arguments for scipy get window function. Must be in order as in scipy documentation.
|
45
|
-
"window_size": int, # number of samples for the window
|
46
|
-
"hop": int, # STFFT hop shifts window by so many samples
|
47
|
-
"chunk_key": str, # maps to the corresponding chunk class
|
48
|
-
"event_handler_key": str, # maps to the event handler used in post processing
|
49
|
-
"watch_extension": str # event handlers watch for files with this extension
|
50
|
-
},
|
51
|
-
"tagged-staircase": {
|
52
|
-
"samp_rate": int, # [Hz]
|
53
|
-
"min_samples_per_step": int, # [samples]
|
54
|
-
"max_samples_per_step": int, # [samples]
|
55
|
-
"freq_step": float, # [Hz]
|
56
|
-
"step_increment": int, # [samples]
|
57
|
-
"chunk_size": int, # [s]
|
58
|
-
"joining_time": int, # [s]
|
59
|
-
"time_resolution": float, # [s]
|
60
|
-
"frequency_resolution": float, # [Hz]
|
61
|
-
"window_type": str, # the window type for the STFFT
|
62
|
-
"window_kwargs": dict, # keyword arguments for scipy get window function. Must be in order as in scipy documentation.
|
63
|
-
"window_size": int, # number of samples for the window
|
64
|
-
"hop": int, # keyword arguments for scipy STFFT class
|
65
|
-
"chunk_key": str, # maps to the corresponding chunk class
|
66
|
-
"event_handler_key": str, # maps to the event handler used in post processing
|
67
|
-
"watch_extension": str # event handlers watch for files with this extension
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
def _set_specifications(self) -> None:
|
72
|
-
self._specifications = {
|
73
|
-
"samp_rate_lower_bound": 64000
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
def __cosine_signal_1(self, capture_config: CaptureConfig) -> None:
|
78
|
-
cosine_signal_1.main(capture_config)
|
79
|
-
|
80
|
-
|
81
|
-
def __tagged_staircase(self, capture_config: CaptureConfig) -> None:
|
82
|
-
tagged_staircase.main(capture_config)
|
83
|
-
|
84
|
-
|
85
|
-
def __cosine_signal_1_validator(self, capture_config: CaptureConfig) -> None:
|
86
|
-
# unpack the capture config
|
87
|
-
samp_rate = capture_config["samp_rate"]
|
88
|
-
frequency = capture_config["frequency"]
|
89
|
-
amplitude = capture_config["amplitude"]
|
90
|
-
chunk_size = capture_config["chunk_size"]
|
91
|
-
window_type = capture_config["window_type"]
|
92
|
-
window_size = capture_config["window_size"]
|
93
|
-
hop = capture_config["hop"]
|
94
|
-
chunk_key = capture_config["chunk_key"]
|
95
|
-
event_handler_key = capture_config["event_handler_key"]
|
96
|
-
time_resolution = capture_config["time_resolution"]
|
97
|
-
frequency_resolution = capture_config["frequency_resolution"]
|
98
|
-
watch_extension = capture_config["watch_extension"]
|
99
|
-
|
100
|
-
validators.samp_rate_strictly_positive(samp_rate)
|
101
|
-
validators.chunk_size_strictly_positive(chunk_size)
|
102
|
-
validators.time_resolution(time_resolution, chunk_size)
|
103
|
-
validators.window(window_type,
|
104
|
-
{},
|
105
|
-
window_size,
|
106
|
-
chunk_size,
|
107
|
-
samp_rate)
|
108
|
-
validators.hop(hop)
|
109
|
-
validators.chunk_key(chunk_key,
|
110
|
-
"fixed")
|
111
|
-
validators.event_handler_key(event_handler_key,
|
112
|
-
"fixed")
|
113
|
-
validators.watch_extension(watch_extension,
|
114
|
-
"bin")
|
115
|
-
|
116
|
-
if samp_rate < self.specifications.get("samp_rate_lower_bound"):
|
117
|
-
raise ValueError((f"Sample rate must be greater than or equal to "
|
118
|
-
f"{self.specifications.get('samp_rate_lower_bound')}"))
|
119
|
-
|
120
|
-
if time_resolution != 0:
|
121
|
-
raise ValueError(f"Time resolution must be zero. "
|
122
|
-
f"Got {time_resolution} [s]")
|
123
|
-
|
124
|
-
if frequency_resolution != 0:
|
125
|
-
raise ValueError((f"Frequency resolution must be zero. "
|
126
|
-
f"Got {frequency_resolution}"))
|
127
|
-
|
128
|
-
# check that the sample rate is an integer multiple of the underlying signal frequency
|
129
|
-
if samp_rate % frequency != 0:
|
130
|
-
raise ValueError("The sampling rate must be some integer multiple of frequency")
|
131
|
-
|
132
|
-
a = samp_rate/frequency
|
133
|
-
if a < 2:
|
134
|
-
raise ValueError((f"The ratio of sampling rate over frequency must be a natural number greater than two. "
|
135
|
-
f"Got {a}"))
|
136
|
-
|
137
|
-
# ensuring the window type is rectangular
|
138
|
-
if window_type != "boxcar":
|
139
|
-
raise ValueError((f"The window type must be 'boxcar'. "
|
140
|
-
f"Got {window_type}"))
|
141
|
-
|
142
|
-
# analytical requirement
|
143
|
-
# if p is the number of sampled cycles, we can find that p = window_size / a
|
144
|
-
# the number of sampled cycles must be a positive natural number.
|
145
|
-
p = window_size / a
|
146
|
-
if window_size % a != 0:
|
147
|
-
raise ValueError((f"The number of sampled cycles must be a positive natural number. "
|
148
|
-
f"Computed that p={p}"))
|
149
|
-
|
150
|
-
|
151
|
-
if amplitude <= 0:
|
152
|
-
raise ValueError((f"The amplitude must be strictly positive. "
|
153
|
-
f"Got {amplitude}"))
|
154
|
-
|
155
|
-
|
156
|
-
def __tagged_staircase_validator(self, capture_config: CaptureConfig) -> None:
|
157
|
-
samp_rate = capture_config["samp_rate"]
|
158
|
-
min_samples_per_step = capture_config["min_samples_per_step"]
|
159
|
-
max_samples_per_step = capture_config["max_samples_per_step"]
|
160
|
-
freq_step = capture_config["freq_step"]
|
161
|
-
step_increment = capture_config["step_increment"]
|
162
|
-
chunk_size = capture_config["chunk_size"]
|
163
|
-
window_type = capture_config["window_type"]
|
164
|
-
window_kwargs = capture_config["window_kwargs"]
|
165
|
-
window_size = capture_config["window_size"]
|
166
|
-
hop = capture_config["hop"]
|
167
|
-
chunk_key = capture_config["chunk_key"]
|
168
|
-
event_handler_key = capture_config["event_handler_key"]
|
169
|
-
time_resolution = capture_config["time_resolution"]
|
170
|
-
watch_extension = capture_config["watch_extension"]
|
171
|
-
|
172
|
-
validators.samp_rate_strictly_positive(samp_rate)
|
173
|
-
validators.chunk_size_strictly_positive(chunk_size)
|
174
|
-
validators.time_resolution(time_resolution, chunk_size)
|
175
|
-
validators.window(window_type,
|
176
|
-
window_kwargs,
|
177
|
-
window_size,
|
178
|
-
chunk_size,
|
179
|
-
samp_rate)
|
180
|
-
validators.hop(hop)
|
181
|
-
validators.chunk_key(chunk_key, "sweep")
|
182
|
-
validators.event_handler_key(event_handler_key, "sweep")
|
183
|
-
validators.watch_extension(watch_extension,
|
184
|
-
"bin")
|
185
|
-
|
186
|
-
if freq_step != samp_rate:
|
187
|
-
raise ValueError(f"The frequency step must be equal to the sampling rate")
|
188
|
-
|
189
|
-
if min_samples_per_step <= 0:
|
190
|
-
raise ValueError((f"Minimum samples per step must be strictly positive. "
|
191
|
-
f"Got {min_samples_per_step}"))
|
192
|
-
|
193
|
-
if max_samples_per_step <= 0:
|
194
|
-
raise ValueError((f"Maximum samples per step must be strictly positive. "
|
195
|
-
f"Got {max_samples_per_step}"))
|
196
|
-
|
197
|
-
if step_increment <= 0:
|
198
|
-
raise ValueError((f"Step increment must be strictly positive. "
|
199
|
-
f"Got {step_increment}"))
|
200
|
-
|
201
|
-
if min_samples_per_step > max_samples_per_step:
|
202
|
-
raise ValueError((f"Minimum samples per step cannot be greater than the maximum samples per step. "
|
203
|
-
f"Got {min_samples_per_step}, which is greater than {max_samples_per_step}"))
|
@@ -1,231 +0,0 @@
|
|
1
|
-
# SPDX-FileCopyrightText: © 2024 Jimmy Fitzpatrick <jcfitzpatrick12@gmail.com>
|
2
|
-
# This file is part of SPECTRE
|
3
|
-
# SPDX-License-Identifier: GPL-3.0-or-later
|
4
|
-
|
5
|
-
from logging import getLogger
|
6
|
-
_LOGGER = getLogger(__name__)
|
7
|
-
|
8
|
-
from math import floor
|
9
|
-
import warnings
|
10
|
-
|
11
|
-
from scipy.signal import get_window
|
12
|
-
|
13
|
-
|
14
|
-
def closed_upper_bound_RF_gain(RF_gain: float,
|
15
|
-
RF_gain_upper_bound: float) -> None:
|
16
|
-
if not (RF_gain <= RF_gain_upper_bound):
|
17
|
-
raise ValueError((f"RF gain must be less than or equal to {RF_gain_upper_bound} [dB]. "
|
18
|
-
f"Got {RF_gain} [dB]"))
|
19
|
-
|
20
|
-
|
21
|
-
def closed_upper_bound_IF_gain(IF_gain: float,
|
22
|
-
IF_gain_upper_bound: float) -> None:
|
23
|
-
if not (IF_gain <= IF_gain_upper_bound):
|
24
|
-
raise ValueError((f"IF gain must be less than or equal to {IF_gain_upper_bound} [dB]. "
|
25
|
-
f"Got {IF_gain} [dB]"))
|
26
|
-
|
27
|
-
|
28
|
-
def closed_confine_center_freq(center_freq: float,
|
29
|
-
center_freq_lower_bound: float,
|
30
|
-
center_freq_upper_bound: float) -> None:
|
31
|
-
if not (center_freq_lower_bound <= center_freq <= center_freq_upper_bound):
|
32
|
-
raise ValueError((f"Center frequency must be between {center_freq_lower_bound*1e-3} [kHz] and {center_freq_upper_bound*1e-9} [GHz]. "
|
33
|
-
f"Got {center_freq*1e-6} [MHz]"))
|
34
|
-
|
35
|
-
|
36
|
-
def closed_confine_samp_rate(samp_rate: int,
|
37
|
-
samp_rate_lower_bound: int,
|
38
|
-
samp_rate_upper_bound: int) -> None:
|
39
|
-
if not (samp_rate_lower_bound <= samp_rate <= samp_rate_upper_bound):
|
40
|
-
raise ValueError((f"Sampling rate must be between {samp_rate_lower_bound*1e-6} [MHz] and {samp_rate_upper_bound*1e-6} [MHz]. "
|
41
|
-
f"Got {samp_rate*1e-6} [MHz]"))
|
42
|
-
|
43
|
-
|
44
|
-
def closed_confine_bandwidth(bandwidth: float,
|
45
|
-
bandwidth_lower_bound: float,
|
46
|
-
bandwidth_upper_bound: float) -> None:
|
47
|
-
if not (bandwidth_lower_bound <= bandwidth <= bandwidth_upper_bound):
|
48
|
-
raise ValueError((f"Bandwidth must be between {bandwidth_lower_bound*1e-3} [kHz] and {bandwidth_upper_bound*1e-6} [MHz]. "
|
49
|
-
f"Got {bandwidth*1e-6} [MHz]"))
|
50
|
-
|
51
|
-
|
52
|
-
def is_power_of_two(n):
|
53
|
-
return (n != 0) and (n & (n-1) == 0)
|
54
|
-
|
55
|
-
|
56
|
-
def window(window_type: str,
|
57
|
-
window_kwargs: dict,
|
58
|
-
window_size: int,
|
59
|
-
chunk_size: int,
|
60
|
-
samp_rate: float) -> None:
|
61
|
-
|
62
|
-
if not is_power_of_two(window_size):
|
63
|
-
raise ValueError((f"Window size must be some power of two. "
|
64
|
-
f"Got {window_size} [samples]"))
|
65
|
-
|
66
|
-
window_interval = window_size*(1/samp_rate)
|
67
|
-
if window_interval > chunk_size:
|
68
|
-
raise ValueError((f"The windowing interval must be strictly less than the chunk size. "
|
69
|
-
f"Computed the windowing interval to be {window_interval} [s], "
|
70
|
-
f"but the chunk size is {chunk_size} [s]"))
|
71
|
-
|
72
|
-
try:
|
73
|
-
window_params = (window_type,
|
74
|
-
*window_kwargs.values())
|
75
|
-
_ = get_window(window_params, window_size)
|
76
|
-
except Exception as e:
|
77
|
-
raise Exception((f"An error has occurred while validating the window. "
|
78
|
-
f"Got {str(e)}"))
|
79
|
-
|
80
|
-
|
81
|
-
def hop(hop: int):
|
82
|
-
if hop < 0:
|
83
|
-
raise ValueError((f"Window hop must be strictly positive. "
|
84
|
-
f"Got {hop} [samples]"))
|
85
|
-
|
86
|
-
|
87
|
-
def center_freq_strictly_positive(center_freq: float):
|
88
|
-
if center_freq <= 0:
|
89
|
-
raise ValueError((f"Center frequency must be strictly positive. "
|
90
|
-
f"Got {center_freq*1e-6} [MHz]"))
|
91
|
-
|
92
|
-
|
93
|
-
def bandwidth_strictly_positive(bandwidth: float) -> None:
|
94
|
-
if bandwidth < 0:
|
95
|
-
raise ValueError((f"Bandwidth must be non-negative. "
|
96
|
-
f"Got {bandwidth*1e-6} [MHz]"))
|
97
|
-
|
98
|
-
|
99
|
-
def nyquist_criterion(samp_rate: int,
|
100
|
-
bandwidth: float) -> None:
|
101
|
-
if samp_rate < bandwidth:
|
102
|
-
raise ValueError((f"Sample rate must be greater than or equal to the bandwidth. "
|
103
|
-
f"Got sample rate {samp_rate} [Hz], and bandwidth {bandwidth} [Hz]"))
|
104
|
-
|
105
|
-
|
106
|
-
def samp_rate_strictly_positive(samp_rate: int) -> None:
|
107
|
-
if samp_rate <= 0:
|
108
|
-
raise ValueError((f"Sample rate must be strictly positive. "
|
109
|
-
f"Got {samp_rate} [Hz]"))
|
110
|
-
|
111
|
-
|
112
|
-
def chunk_size_strictly_positive(chunk_size: int) -> None:
|
113
|
-
if chunk_size <= 0:
|
114
|
-
raise ValueError((f"Chunk size must be strictly positive. "
|
115
|
-
f"Got {chunk_size} [s]"))
|
116
|
-
|
117
|
-
|
118
|
-
def time_resolution(time_resolution: float,
|
119
|
-
chunk_size: int) -> None:
|
120
|
-
if time_resolution < 0:
|
121
|
-
raise ValueError((f"Time resolution must be non-negative. "
|
122
|
-
f"Got {time_resolution} [s]"))
|
123
|
-
|
124
|
-
if time_resolution > chunk_size:
|
125
|
-
raise ValueError(f"Time resolution must be less than or equal to chunk size. "
|
126
|
-
f"Got time resolution {time_resolution} [s], "
|
127
|
-
f"and chunk size {chunk_size} [s]")
|
128
|
-
|
129
|
-
|
130
|
-
def frequency_resolution(frequency_resolution: float,
|
131
|
-
bandwidth: float = None) -> None:
|
132
|
-
if frequency_resolution < 0:
|
133
|
-
raise ValueError((f"Frequency resolution must be non-negative. "
|
134
|
-
f"Got {frequency_resolution} [Hz]"))
|
135
|
-
|
136
|
-
if bandwidth is not None and frequency_resolution >= bandwidth:
|
137
|
-
raise ValueError((f"Frequency resolution must be less than the bandwidth. "
|
138
|
-
f"Got frequency resolution to be {frequency_resolution} [Hz], "
|
139
|
-
f"with bandwidth {bandwidth} [Hz]"))
|
140
|
-
|
141
|
-
|
142
|
-
def chunk_key(chunk_key: str,
|
143
|
-
expected_chunk_key: str) -> None:
|
144
|
-
if chunk_key != expected_chunk_key:
|
145
|
-
raise ValueError((f"Expected {expected_chunk_key} for the chunk key. "
|
146
|
-
f"Got {chunk_key}"))
|
147
|
-
|
148
|
-
|
149
|
-
def event_handler_key(event_handler_key: str,
|
150
|
-
expected_event_handler_key: str) -> None:
|
151
|
-
if event_handler_key != expected_event_handler_key:
|
152
|
-
raise ValueError((f"Expected {expected_event_handler_key} for the event handler key. "
|
153
|
-
f"Got {event_handler_key}"))
|
154
|
-
|
155
|
-
|
156
|
-
def gain_is_negative(gain: float) -> None:
|
157
|
-
if gain > 0:
|
158
|
-
raise ValueError(f"Gain must be non-positive. "
|
159
|
-
f"Got {gain} [dB]")
|
160
|
-
|
161
|
-
|
162
|
-
def _compute_num_steps_per_sweep(min_freq: float,
|
163
|
-
max_freq: float,
|
164
|
-
samp_rate: int,
|
165
|
-
freq_step: float) -> int:
|
166
|
-
return floor((max_freq - min_freq + samp_rate/2) / freq_step)
|
167
|
-
|
168
|
-
|
169
|
-
def num_steps_per_sweep(min_freq: float,
|
170
|
-
max_freq: float,
|
171
|
-
samp_rate: int,
|
172
|
-
freq_step: float) -> None:
|
173
|
-
num_steps_per_sweep = _compute_num_steps_per_sweep(min_freq,
|
174
|
-
max_freq,
|
175
|
-
samp_rate,
|
176
|
-
freq_step)
|
177
|
-
if num_steps_per_sweep <= 1:
|
178
|
-
raise ValueError((f"We need strictly greater than one step per sweep. "
|
179
|
-
f"Computed {num_steps_per_sweep} step per sweep"))
|
180
|
-
|
181
|
-
|
182
|
-
def sweep_interval(min_freq: float,
|
183
|
-
max_freq: float,
|
184
|
-
samp_rate: int,
|
185
|
-
freq_step: float,
|
186
|
-
samples_per_step: int,
|
187
|
-
chunk_size: float) -> None:
|
188
|
-
num_steps_per_sweep = _compute_num_steps_per_sweep(min_freq,
|
189
|
-
max_freq,
|
190
|
-
samp_rate,
|
191
|
-
freq_step)
|
192
|
-
num_samples_per_sweep = num_steps_per_sweep * samples_per_step
|
193
|
-
sweep_interval = num_samples_per_sweep * 1/samp_rate
|
194
|
-
if sweep_interval > chunk_size:
|
195
|
-
raise ValueError((f"Sweep interval must be less than the chunk size. "
|
196
|
-
f"The computed sweep interval is {sweep_interval} [s], "
|
197
|
-
f"but the given chunk size is {chunk_size} [s]"))
|
198
|
-
|
199
|
-
|
200
|
-
def num_samples_per_step(samples_per_step: int,
|
201
|
-
window_size: int) -> None:
|
202
|
-
if window_size >= samples_per_step:
|
203
|
-
raise ValueError((f"Window size must be strictly less than the number of samples per step. "
|
204
|
-
f"Got window size {window_size} [samples], which is more than or equal "
|
205
|
-
f"to the number of samples per step {samples_per_step}"))
|
206
|
-
|
207
|
-
|
208
|
-
def non_overlapping_steps(freq_step: float,
|
209
|
-
samp_rate: int) -> None:
|
210
|
-
if freq_step < samp_rate:
|
211
|
-
raise NotImplementedError(f"SPECTRE does not yet support spectral steps overlapping in frequency. "
|
212
|
-
f"Got frequency step {freq_step/1e6} [MHz] which is less than the sample "
|
213
|
-
f"rate {samp_rate/1e6} [MHz]")
|
214
|
-
|
215
|
-
|
216
|
-
def step_interval(samples_per_step: int,
|
217
|
-
samp_rate: int,
|
218
|
-
api_latency: float) -> None:
|
219
|
-
step_interval = samples_per_step * 1/samp_rate # [s]
|
220
|
-
if step_interval < api_latency:
|
221
|
-
warning_message = (f"The computed step interval of {step_interval} [s] is of the order of empirically "
|
222
|
-
f"derived api latency {api_latency} [s]; you may experience undefined behaviour!")
|
223
|
-
warnings.warn(warning_message)
|
224
|
-
_LOGGER.warning(warning_message)
|
225
|
-
|
226
|
-
|
227
|
-
def watch_extension(watch_extension: str,
|
228
|
-
target_extension: str) -> None:
|
229
|
-
if watch_extension != target_extension:
|
230
|
-
raise ValueError((f"Expected {target_extension} for the watch extension. "
|
231
|
-
f"Got {watch_extension}"))
|