spectre-core 0.0.8__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.
Files changed (109) hide show
  1. spectre_core/__init__.py +0 -3
  2. spectre_core/_file_io/__init__.py +15 -0
  3. spectre_core/_file_io/file_handlers.py +128 -0
  4. spectre_core/capture_configs/__init__.py +29 -0
  5. spectre_core/capture_configs/_capture_config.py +85 -0
  6. spectre_core/capture_configs/_capture_templates.py +222 -0
  7. spectre_core/capture_configs/_parameters.py +110 -0
  8. spectre_core/capture_configs/_pconstraints.py +82 -0
  9. spectre_core/capture_configs/_ptemplates.py +450 -0
  10. spectre_core/capture_configs/_pvalidators.py +173 -0
  11. spectre_core/chunks/__init__.py +17 -201
  12. spectre_core/chunks/{base.py → _base.py} +15 -60
  13. spectre_core/chunks/_chunks.py +200 -0
  14. spectre_core/chunks/{factory.py → _factory.py} +6 -7
  15. spectre_core/chunks/library/{callisto/chunk.py → _callisto.py} +4 -7
  16. spectre_core/chunks/library/{fixed/chunk.py → _fixed_center_frequency.py} +7 -64
  17. spectre_core/chunks/library/_swept_center_frequency.py +103 -0
  18. spectre_core/config/__init__.py +20 -0
  19. spectre_core/config/_paths.py +77 -0
  20. spectre_core/config/_time_formats.py +15 -0
  21. spectre_core/exceptions.py +4 -5
  22. spectre_core/logging/__init__.py +11 -0
  23. spectre_core/logging/_configure.py +35 -0
  24. spectre_core/logging/_decorators.py +19 -0
  25. spectre_core/{logging.py → logging/_log_handlers.py} +13 -58
  26. spectre_core/plotting/__init__.py +7 -1
  27. spectre_core/plotting/{base.py → _base.py} +40 -20
  28. spectre_core/plotting/_format.py +18 -0
  29. spectre_core/plotting/{panel_stack.py → _panel_stack.py} +50 -48
  30. spectre_core/plotting/_panels.py +234 -0
  31. spectre_core/post_processing/__init__.py +14 -0
  32. spectre_core/post_processing/_base.py +119 -0
  33. spectre_core/post_processing/_factory.py +23 -0
  34. spectre_core/post_processing/_post_processor.py +40 -0
  35. spectre_core/post_processing/library/_fixed_center_frequency.py +115 -0
  36. spectre_core/post_processing/library/_swept_center_frequency.py +382 -0
  37. spectre_core/receivers/__init__.py +12 -2
  38. spectre_core/receivers/_base.py +352 -0
  39. spectre_core/receivers/{factory.py → _factory.py} +2 -2
  40. spectre_core/receivers/_spec_names.py +20 -0
  41. spectre_core/receivers/gr/__init__.py +3 -0
  42. spectre_core/receivers/gr/_base.py +33 -0
  43. spectre_core/receivers/gr/_rsp1a.py +158 -0
  44. spectre_core/receivers/gr/_test.py +123 -0
  45. spectre_core/receivers/library/_rsp1a.py +61 -0
  46. spectre_core/receivers/library/_test.py +221 -0
  47. spectre_core/spectrograms/__init__.py +18 -0
  48. spectre_core/spectrograms/{analytical.py → _analytical.py} +29 -27
  49. spectre_core/spectrograms/{array_operations.py → _array_operations.py} +47 -1
  50. spectre_core/spectrograms/{spectrogram.py → _spectrogram.py} +62 -35
  51. spectre_core/spectrograms/{transform.py → _transform.py} +76 -89
  52. spectre_core/{receivers/library → wgetting}/__init__.py +4 -2
  53. spectre_core/wgetting/_callisto.py +155 -0
  54. {spectre_core-0.0.8.dist-info → spectre_core-0.0.10.dist-info}/METADATA +1 -1
  55. spectre_core-0.0.10.dist-info/RECORD +63 -0
  56. spectre_core/cfg.py +0 -116
  57. spectre_core/chunks/library/__init__.py +0 -8
  58. spectre_core/chunks/library/sweep/__init__.py +0 -0
  59. spectre_core/chunks/library/sweep/chunk.py +0 -400
  60. spectre_core/dynamic_imports.py +0 -22
  61. spectre_core/file_handlers/base.py +0 -68
  62. spectre_core/file_handlers/configs.py +0 -271
  63. spectre_core/file_handlers/json.py +0 -40
  64. spectre_core/file_handlers/text.py +0 -21
  65. spectre_core/plotting/factory.py +0 -26
  66. spectre_core/plotting/format.py +0 -19
  67. spectre_core/plotting/library/__init__.py +0 -7
  68. spectre_core/plotting/library/frequency_cuts/panel.py +0 -74
  69. spectre_core/plotting/library/integral_over_frequency/panel.py +0 -34
  70. spectre_core/plotting/library/spectrogram/panel.py +0 -92
  71. spectre_core/plotting/library/time_cuts/panel.py +0 -77
  72. spectre_core/plotting/panel_register.py +0 -13
  73. spectre_core/receivers/base.py +0 -415
  74. spectre_core/receivers/library/rsp1a/__init__.py +0 -0
  75. spectre_core/receivers/library/rsp1a/gr/__init__.py +0 -0
  76. spectre_core/receivers/library/rsp1a/gr/fixed.py +0 -104
  77. spectre_core/receivers/library/rsp1a/gr/sweep.py +0 -129
  78. spectre_core/receivers/library/rsp1a/receiver.py +0 -68
  79. spectre_core/receivers/library/rspduo/__init__.py +0 -0
  80. spectre_core/receivers/library/rspduo/gr/__init__.py +0 -0
  81. spectre_core/receivers/library/rspduo/gr/tuner_1_fixed.py +0 -114
  82. spectre_core/receivers/library/rspduo/gr/tuner_1_sweep.py +0 -131
  83. spectre_core/receivers/library/rspduo/gr/tuner_2_fixed.py +0 -120
  84. spectre_core/receivers/library/rspduo/gr/tuner_2_sweep.py +0 -119
  85. spectre_core/receivers/library/rspduo/receiver.py +0 -97
  86. spectre_core/receivers/library/test/__init__.py +0 -0
  87. spectre_core/receivers/library/test/gr/__init__.py +0 -0
  88. spectre_core/receivers/library/test/gr/cosine_signal_1.py +0 -83
  89. spectre_core/receivers/library/test/gr/tagged_staircase.py +0 -93
  90. spectre_core/receivers/library/test/receiver.py +0 -178
  91. spectre_core/receivers/validators.py +0 -193
  92. spectre_core/watchdog/__init__.py +0 -6
  93. spectre_core/watchdog/base.py +0 -105
  94. spectre_core/watchdog/factory.py +0 -22
  95. spectre_core/watchdog/library/__init__.py +0 -10
  96. spectre_core/watchdog/library/fixed/__init__.py +0 -0
  97. spectre_core/watchdog/library/fixed/event_handler.py +0 -41
  98. spectre_core/watchdog/library/sweep/event_handler.py +0 -55
  99. spectre_core/watchdog/post_processor.py +0 -50
  100. spectre_core/web_fetch/callisto.py +0 -101
  101. spectre_core-0.0.8.dist-info/RECORD +0 -74
  102. /spectre_core/chunks/{chunk_register.py → _register.py} +0 -0
  103. /spectre_core/{watchdog/event_handler_register.py → post_processing/_register.py} +0 -0
  104. /spectre_core/receivers/{receiver_register.py → _register.py} +0 -0
  105. /spectre_core/{chunks/library/callisto/__init__.py → receivers/gr/_rspduo.py} +0 -0
  106. /spectre_core/{chunks/library/fixed/__init__.py → receivers/library/_rspduo.py} +0 -0
  107. {spectre_core-0.0.8.dist-info → spectre_core-0.0.10.dist-info}/LICENSE +0 -0
  108. {spectre_core-0.0.8.dist-info → spectre_core-0.0.10.dist-info}/WHEEL +0 -0
  109. {spectre_core-0.0.8.dist-info → spectre_core-0.0.10.dist-info}/top_level.txt +0 -0
@@ -1,97 +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.base import SDRPlayReceiver
6
- from spectre_core.receivers.receiver_register import register_receiver
7
- from spectre_core.receivers.library.rspduo.gr import (
8
- tuner_1_fixed,
9
- tuner_1_sweep,
10
- tuner_2_fixed,
11
- tuner_2_sweep
12
- )
13
- from spectre_core.file_handlers.configs import CaptureConfig
14
-
15
-
16
- @register_receiver("rspduo")
17
- class Receiver(SDRPlayReceiver):
18
- def __init__(self, *args, **kwargs):
19
- super().__init__(*args, **kwargs)
20
-
21
-
22
- def _set_capture_methods(self) -> None:
23
- self._capture_methods = {
24
- "tuner-1-fixed": self.__tuner_1_fixed,
25
- "tuner-1-sweep": self.__tuner_1_sweep,
26
- "tuner-2-fixed": self.__tuner_2_fixed,
27
- "tuner-2-sweep": self.__tuner_2_sweep
28
- }
29
-
30
-
31
- def _set_validators(self) -> None:
32
- self._validators = {
33
- "tuner-1-fixed": self.__tuner_1_fixed_validator,
34
- "tuner-1-sweep": self.__tuner_1_sweep_validator,
35
- "tuner-2-fixed": self.__tuner_2_fixed_validator,
36
- "tuner-2-sweep": self.__tuner_2_sweep_validator,
37
- }
38
- return
39
-
40
-
41
- def _set_type_templates(self) -> None:
42
- self._type_templates = {
43
- "tuner-1-fixed": self._get_default_type_template("fixed"),
44
- "tuner-1-sweep": self._get_default_type_template("sweep"),
45
- "tuner-2-fixed": self._get_default_type_template("fixed"),
46
- "tuner-2-sweep": self._get_default_type_template("sweep"),
47
- }
48
-
49
- def _set_specifications(self) -> None:
50
- self._specifications = {
51
- "center_freq_lower_bound": 1e3, # [Hz]
52
- "center_freq_upper_bound": 2e9, # [Hz]
53
- "samp_rate_lower_bound": 200e3, # [Hz]
54
- "samp_rate_upper_bound": 10e6, # [Hz]
55
- "bandwidth_lower_bound": 200e3, # [Hz]
56
- "bandwidth_upper_bound": 8e6, # [Hz]
57
- "IF_gain_upper_bound": -20, # [dB]
58
- "RF_gain_upper_bound": 0, # [dB]
59
- "api_latency": 50 * 1e-3 # [s]
60
- }
61
-
62
-
63
- def __tuner_1_fixed(self, capture_config: CaptureConfig) -> None:
64
- tuner_1_fixed.main(capture_config)
65
-
66
-
67
- def __tuner_1_sweep(self, capture_config: CaptureConfig) -> None:
68
- tuner_1_sweep.main(capture_config)
69
-
70
-
71
- def __tuner_2_fixed(self, capture_config: CaptureConfig) -> None:
72
- tuner_2_fixed.main(capture_config)
73
-
74
-
75
- def __tuner_2_sweep(self, capture_config: CaptureConfig) -> None:
76
- tuner_2_sweep.main(capture_config)
77
-
78
-
79
- def __tuner_1_fixed_validator(self, capture_config: CaptureConfig) -> None:
80
- self._default_fixed_validator(capture_config)
81
- self._sdrplay_validator(capture_config)
82
-
83
-
84
- def __tuner_1_sweep_validator(self, capture_config: CaptureConfig) -> None:
85
- self._default_sweep_validator(capture_config)
86
- self._sdrplay_validator(capture_config)
87
-
88
-
89
- def __tuner_2_fixed_validator(self, capture_config: CaptureConfig) -> None:
90
- self._default_fixed_validator(capture_config)
91
- self._sdrplay_validator(capture_config)
92
-
93
-
94
- def __tuner_2_sweep_validator(self, capture_config: CaptureConfig) -> None:
95
- self._default_sweep_validator(capture_config)
96
- self._sdrplay_validator(capture_config)
97
-
File without changes
File without changes
@@ -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,178 +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
- },
50
- "tagged-staircase": {
51
- "samp_rate": int, # [Hz]
52
- "min_samples_per_step": int, # [samples]
53
- "max_samples_per_step": int, # [samples]
54
- "freq_step": float, # [Hz]
55
- "step_increment": int, # [samples]
56
- "chunk_size": int, # [s]
57
- "joining_time": int, # [s]
58
- "time_resolution": float, # [s]
59
- "frequency_resolution": float, # [Hz]
60
- "window_type": str, # the window type for the STFFT
61
- "window_kwargs": dict, # keyword arguments for scipy get window function. Must be in order as in scipy documentation.
62
- "window_size": int, # number of samples for the window
63
- "hop": int, # keyword arguments for scipy STFFT class
64
- "chunk_key": str, # maps to the corresponding chunk class
65
- "event_handler_key": str, # maps to the event handler used in post processing
66
- }
67
- }
68
-
69
- def _set_specifications(self) -> None:
70
- self._specifications = {
71
- "samp_rate_lower_bound": 64000
72
- }
73
-
74
-
75
- def __cosine_signal_1(self, capture_config: CaptureConfig) -> None:
76
- cosine_signal_1.main(capture_config)
77
-
78
-
79
- def __tagged_staircase(self, capture_config: CaptureConfig) -> None:
80
- tagged_staircase.main(capture_config)
81
-
82
-
83
- def __cosine_signal_1_validator(self, capture_config: CaptureConfig) -> None:
84
- # unpack the capture config
85
- samp_rate = capture_config["samp_rate"]
86
- frequency = capture_config["frequency"]
87
- amplitude = capture_config["amplitude"]
88
- chunk_size = capture_config["chunk_size"]
89
- window_type = capture_config["window_type"]
90
- window_size = capture_config["window_size"]
91
- hop = capture_config["hop"]
92
- chunk_key = capture_config["chunk_key"]
93
- event_handler_key = capture_config["event_handler_key"]
94
- time_resolution = capture_config["time_resolution"]
95
- frequency_resolution = capture_config["frequency_resolution"]
96
-
97
- validators.samp_rate_strictly_positive(samp_rate)
98
- validators.chunk_size_strictly_positive(chunk_size)
99
- validators.time_resolution(time_resolution, chunk_size)
100
- validators.window(window_type,
101
- {},
102
- window_size,
103
- chunk_size,
104
- samp_rate)
105
- validators.hop(hop)
106
- validators.chunk_key(chunk_key, "fixed")
107
- validators.event_handler_key(event_handler_key, "fixed")
108
-
109
- if samp_rate < self.specifications.get("samp_rate_lower_bound"):
110
- raise ValueError(f"Sample rate must be greater than or equal to {self.specifications.get('samp_rate_lower_bound')}")
111
-
112
- if time_resolution != 0:
113
- raise ValueError(f"Time resolution must be zero. Received: {time_resolution}")
114
-
115
- if frequency_resolution != 0:
116
- raise ValueError(f"Frequency resolution must be zero. Received {frequency_resolution}")
117
-
118
- # check that the sample rate is an integer multiple of the underlying signal frequency
119
- if samp_rate % frequency != 0:
120
- raise ValueError("The sampling rate must be some integer multiple of frequency")
121
-
122
- a = samp_rate/frequency
123
- if a < 2:
124
- raise ValueError(f"The ratio of sampling rate over frequency must be a natural number greater than two. Received: {a}")
125
-
126
- # ensuring the window type is rectangular
127
- if window_type != "boxcar":
128
- raise ValueError(f"The window type must be \"boxcar\". Received: {window_type}")
129
-
130
- # analytical requirement
131
- # if p is the number of sampled cycles, we can find that p = window_size / a
132
- # the number of sampled cycles must be a positive natural number.
133
- p = window_size / a
134
- if window_size % a != 0:
135
- raise ValueError(f"The number of sampled cycles must be a positive natural number. Computed that p={p}")
136
-
137
-
138
- if amplitude <= 0:
139
- raise ValueError(f"The amplitude must be strictly positive. Received: {amplitude}")
140
-
141
-
142
- def __tagged_staircase_validator(self, capture_config: CaptureConfig) -> None:
143
- samp_rate = capture_config["samp_rate"]
144
- min_samples_per_step = capture_config["min_samples_per_step"]
145
- max_samples_per_step = capture_config["max_samples_per_step"]
146
- freq_step = capture_config["freq_step"]
147
- step_increment = capture_config["step_increment"]
148
- chunk_size = capture_config["chunk_size"]
149
- window_type = capture_config["window_type"]
150
- window_kwargs = capture_config["window_kwargs"]
151
- window_size = capture_config["window_size"]
152
- hop = capture_config["hop"]
153
- chunk_key = capture_config["chunk_key"]
154
- event_handler_key = capture_config["event_handler_key"]
155
- time_resolution = capture_config["time_resolution"]
156
-
157
- validators.samp_rate_strictly_positive(samp_rate)
158
- validators.chunk_size_strictly_positive(chunk_size)
159
- validators.time_resolution(time_resolution, chunk_size)
160
- validators.window(window_type, window_kwargs, window_size, chunk_size, samp_rate)
161
- validators.hop(hop)
162
- validators.chunk_key(chunk_key, "sweep")
163
- validators.event_handler_key(event_handler_key, "sweep")
164
-
165
- if freq_step != samp_rate:
166
- raise ValueError(f"The frequency step must be equal to the sampling rate")
167
-
168
- if min_samples_per_step <= 0:
169
- raise ValueError(f"Minimum samples per step must be strictly positive. Received: {min_samples_per_step}")
170
-
171
- if max_samples_per_step <= 0:
172
- raise ValueError(f"Maximum samples per step must be strictly positive. Received: {max_samples_per_step}")
173
-
174
- if step_increment <= 0:
175
- raise ValueError(f"Step increment must be strictly positive. Received: {step_increment}")
176
-
177
- if min_samples_per_step > max_samples_per_step:
178
- raise ValueError(f"Minimum samples per step cannot be greater than the maximum samples per step. Received: {min_samples_per_step} > {max_samples_per_step}")
@@ -1,193 +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 strictly less than or equal to {RF_gain_upper_bound} [dB]. Got {RF_gain} [dB]")
18
-
19
-
20
- def closed_upper_bound_IF_gain(IF_gain: float,
21
- IF_gain_upper_bound: float) -> None:
22
- if not (IF_gain <= IF_gain_upper_bound):
23
- raise ValueError(f"IF gain must be strictly less than or equal to {IF_gain_upper_bound} [dB]. Got {IF_gain} [dB]")
24
-
25
-
26
- def closed_confine_center_freq(center_freq: float,
27
- center_freq_lower_bound: float,
28
- center_freq_upper_bound: float) -> None:
29
- if not (center_freq_lower_bound <= center_freq <= center_freq_upper_bound):
30
- raise ValueError(f"Center frequency must be between {center_freq_lower_bound*1e-3} [kHz] and {center_freq_upper_bound*1e-9} [GHz]. Received {center_freq*1e-6} [MHz]")
31
-
32
-
33
- def closed_confine_samp_rate(samp_rate: int,
34
- samp_rate_lower_bound: int,
35
- samp_rate_upper_bound: int) -> None:
36
- if not (samp_rate_lower_bound <= samp_rate <= samp_rate_upper_bound):
37
- raise ValueError(f"Sampling rate must be between {samp_rate_lower_bound*1e-6} [MHz] and {samp_rate_upper_bound*1e-6} [MHz]. Received {samp_rate*1e-6} [MHz]")
38
-
39
-
40
- def closed_confine_bandwidth(bandwidth: float,
41
- bandwidth_lower_bound: float,
42
- bandwidth_upper_bound: float) -> None:
43
- if not (bandwidth_lower_bound <= bandwidth <= bandwidth_upper_bound):
44
- raise ValueError(f"Bandwidth must be between {bandwidth_lower_bound*1e-3} [kHz] and {bandwidth_upper_bound*1e-6} [MHz]. Received {bandwidth*1e-6} [MHz]")
45
-
46
-
47
- def is_power_of_two(n):
48
- return (n != 0) and (n & (n-1) == 0)
49
-
50
-
51
- def window(window_type: str,
52
- window_kwargs: dict,
53
- window_size: int,
54
- chunk_size: int,
55
- samp_rate: float) -> None:
56
-
57
- if not is_power_of_two(window_size):
58
- raise ValueError(f"Window size must be some power of two. Received: {window_size}")
59
-
60
-
61
- if window_size*(1/samp_rate) > chunk_size:
62
- raise ValueError("Windowing interval must be strictly less than the chunk size")
63
-
64
- try:
65
- window_params = (window_type,
66
- *window_kwargs.values())
67
- _ = get_window(window_params, window_size)
68
- except Exception as e:
69
- raise Exception(f"An error has occurred while validating the window. Received: {str(e)}")
70
-
71
-
72
- def hop(hop: int):
73
- if hop < 0:
74
- raise ValueError(f"\"hop\" must be strictly positive. Received: {hop_value}")
75
-
76
-
77
- def center_freq_strictly_positive(center_freq: float):
78
- if center_freq <= 0:
79
- raise ValueError(f"Center frequency must be strictly positive. Received: {center_freq*1e-6} [MHz]")
80
-
81
-
82
- def bandwidth_strictly_positive(bandwidth: float) -> None:
83
- if bandwidth < 0:
84
- raise ValueError(f"Bandwidth must be non-negative. Received: {bandwidth*1e-6} [MHz]")
85
-
86
-
87
- def nyquist_criterion(samp_rate: int,
88
- bandwidth: float) -> None:
89
- if samp_rate < bandwidth:
90
- raise ValueError("Sample rate must be greater than or equal to the bandwidth")
91
-
92
-
93
- def samp_rate_strictly_positive(samp_rate: int) -> None:
94
- if samp_rate < 0:
95
- raise ValueError(f"Sample rate must be strictly positive. Received: {samp_rate} [Hz]")
96
-
97
-
98
- def chunk_size_strictly_positive(chunk_size: int) -> None:
99
- if chunk_size <= 0:
100
- raise ValueError(f"Chunk size must be strictly positive. Received: {chunk_size} [s]")
101
-
102
-
103
- def time_resolution(time_resolution: float,
104
- chunk_size: int) -> None:
105
- if time_resolution < 0:
106
- raise ValueError(f"Time resolution must be non-negative. Received: {time_resolution} [s]")
107
-
108
- if time_resolution > chunk_size:
109
- raise ValueError("Time resolution must be less than or equal to chunk size")
110
-
111
-
112
- def frequency_resolution(frequency_resolution: float,
113
- bandwidth: float = None) -> None:
114
- if frequency_resolution < 0:
115
- raise ValueError(f"Frequency resolution must be non-negative. Received {frequency_resolution} [Hz]")
116
-
117
- if bandwidth is not None and frequency_resolution >= bandwidth:
118
- raise ValueError(f"Frequency resolution must be less than the bandwidth. Received frequency resolution to be {frequency_resolution} [Hz], with bandwidth {bandwidth} [Hz]")
119
-
120
-
121
- def chunk_key(chunk_key: str,
122
- expected_chunk_key: str) -> None:
123
- if chunk_key != expected_chunk_key:
124
- raise ValueError(f"Expected \"{expected_chunk_key}\" for the chunk_key, received: {chunk_key}")
125
-
126
-
127
- def event_handler_key(event_handler_key: str,
128
- expected_event_handler_key: str) -> None:
129
- if event_handler_key != expected_event_handler_key:
130
- raise ValueError(f"Expected \"{expected_event_handler_key}\" for the event_handler_key, received: {event_handler_key}")
131
-
132
-
133
- def gain_is_negative(gain: float) -> None:
134
- if gain > 0:
135
- raise ValueError(f"Gain must be non-positive. Received {gain} [dB]")
136
-
137
-
138
- def _compute_num_steps_per_sweep(min_freq: float,
139
- max_freq: float,
140
- samp_rate: int,
141
- freq_step: float) -> int:
142
- return floor((max_freq - min_freq + samp_rate/2) / freq_step)
143
-
144
-
145
- def num_steps_per_sweep(min_freq: float,
146
- max_freq: float,
147
- samp_rate: int,
148
- freq_step: float) -> None:
149
- num_steps_per_sweep = _compute_num_steps_per_sweep(min_freq,
150
- max_freq,
151
- samp_rate,
152
- freq_step)
153
- if num_steps_per_sweep <= 1:
154
- raise ValueError(f"We need strictly greater than one sample per step. Computed: {num_steps_per_sweep}")
155
-
156
-
157
- def sweep_interval(min_freq: float,
158
- max_freq: float,
159
- samp_rate: int,
160
- freq_step: float,
161
- samples_per_step: int,
162
- chunk_size: float) -> None:
163
- num_steps_per_sweep = _compute_num_steps_per_sweep(min_freq,
164
- max_freq,
165
- samp_rate,
166
- freq_step)
167
- num_samples_per_sweep = num_steps_per_sweep * samples_per_step
168
- sweep_interval = num_samples_per_sweep * 1/samp_rate
169
- if sweep_interval > chunk_size:
170
- raise ValueError(f"Sweep interval must be less than the chunk size. Computed sweep interval: {sweep_interval} [s] is greater than the given chunk size {chunk_size} [s]")
171
-
172
-
173
- def num_samples_per_step(samples_per_step: int,
174
- window_size: int) -> None:
175
- if window_size >= samples_per_step:
176
- raise ValueError(f"Window size must be strictly less than the number of samples per step. Received window size {window_size} [samples], which is more than or equal to the number of samples per step {samples_per_step}")
177
-
178
-
179
- def non_overlapping_steps(freq_step: float,
180
- samp_rate: int) -> None:
181
- if freq_step < samp_rate:
182
- raise NotImplementedError(f"SPECTRE does not yet support spectral steps overlapping in frequency. Received frequency step {freq_step/1e6} [MHz] which is less than the sample rate {samp_rate/1e6} [MHz]")
183
-
184
-
185
- def step_interval(samples_per_step: int,
186
- samp_rate: int,
187
- api_latency: float) -> None:
188
- step_interval = samples_per_step * 1/samp_rate # [s]
189
- if step_interval < api_latency:
190
- warning_message = f"The computed step interval of {step_interval} [s] is of the order of empirically derived api latency {api_latency} [s]; you may experience undefined behaviour!"
191
- warnings.warn(warning_message)
192
- _LOGGER.warning(warning_message)
193
-
@@ -1,6 +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
- # dynamically import all event handlers
6
- import spectre_core.watchdog.library