Merge pull request 'viewfix' (#17) from viewfix into main
All checks were successful
Build Sphinx Docs Set / Build Docs (push) Successful in 10s
Build Project / Build Project (3.10) (push) Successful in 32s
Build Project / Build Project (3.11) (push) Successful in 31s
Build Project / Build Project (3.12) (push) Successful in 30s
Test with tox / Test with tox (3.11) (push) Successful in 22s
Test with tox / Test with tox (3.10) (push) Successful in 28s
Test with tox / Test with tox (3.12) (push) Successful in 23s

Reviewed-on: #17
Reviewed-by: madrigal <madrigal@qoherent.ai>
This commit is contained in:
G gillian 2026-02-02 11:02:59 -05:00
commit b1e3ebf74f
19 changed files with 51 additions and 93 deletions

View File

@ -956,10 +956,8 @@ def get_result_sizes( # noqa: C901 # TODO: Simplify function
# Check that each class that will be augmented does not already suffice target_size # Check that each class that will be augmented does not already suffice target_size
for cls_name, target_size_value in zip(classes_to_augment, target_size): for cls_name, target_size_value in zip(classes_to_augment, target_size):
if class_sizes[cls_name] >= target_size_value: if class_sizes[cls_name] >= target_size_value:
raise ValueError( raise ValueError(f"""target_size of {target_size_value} is already sufficed for current size of
f"""target_size of {target_size_value} is already sufficed for current size of {class_sizes[cls_name]} for class: {cls_name}""")
{class_sizes[cls_name]} for class: {cls_name}"""
)
for index, class_name in enumerate(classes_to_augment): for index, class_name in enumerate(classes_to_augment):
result_sizes[class_name] = target_size[index] result_sizes[class_name] = target_size[index]

View File

@ -474,10 +474,8 @@ class Blade(SDR):
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets \
"When gain_mode = 'relative', gain must be < 0. This sets \ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
else: else:
abs_gain = rx_gain_max + gain abs_gain = rx_gain_max + gain
else: else:
@ -550,10 +548,8 @@ class Blade(SDR):
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets\
"When gain_mode = 'relative', gain must be < 0. This sets\ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
else: else:
abs_gain = tx_gain_max + gain abs_gain = tx_gain_max + gain
else: else:

View File

@ -172,10 +172,8 @@ class HackRF(SDR):
tx_gain_max = 47 tx_gain_max = 47
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This \
"When gain_mode = 'relative', gain must be < 0. This \ sets the gain relative to the maximum possible gain.")
sets the gain relative to the maximum possible gain."
)
else: else:
abs_gain = tx_gain_max + gain abs_gain = tx_gain_max + gain
else: else:

View File

@ -274,20 +274,16 @@ class Pluto(SDR):
data = [self._convert_tx_samples(samples), self._convert_tx_samples(samples)] data = [self._convert_tx_samples(samples), self._convert_tx_samples(samples)]
else: else:
if len(recording) > 2: if len(recording) > 2:
warnings.warn( warnings.warn("More recordings were provided than channels in the Pluto. \
"More recordings were provided than channels in the Pluto. \ Only the first two recordings will be used")
Only the first two recordings will be used"
)
sample0 = self._convert_tx_samples(recording.data[0]) sample0 = self._convert_tx_samples(recording.data[0])
sample1 = self._convert_tx_samples(recording.data[1]) sample1 = self._convert_tx_samples(recording.data[1])
data = [sample0, sample1] data = [sample0, sample1]
elif isinstance(recording, list): elif isinstance(recording, list):
if len(recording) > 2: if len(recording) > 2:
warnings.warn( warnings.warn("More recordings were provided than channels in the Pluto. \
"More recordings were provided than channels in the Pluto. \ Only the first two recordings will be used")
Only the first two recordings will be used"
)
if isinstance(recording[0], np.ndarray): if isinstance(recording[0], np.ndarray):
data = [self._convert_tx_samples(recording[0]), self._convert_tx_samples(recording[1])] data = [self._convert_tx_samples(recording[0]), self._convert_tx_samples(recording[1])]
@ -427,10 +423,8 @@ class Pluto(SDR):
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets \
"When gain_mode = 'relative', gain must be < 0. This sets \ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
else: else:
abs_gain = rx_gain_max + gain abs_gain = rx_gain_max + gain
else: else:
@ -540,10 +534,8 @@ class Pluto(SDR):
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets\
"When gain_mode = 'relative', gain must be < 0. This sets\ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
else: else:
abs_gain = tx_gain_max + gain abs_gain = tx_gain_max + gain
else: else:

View File

@ -131,19 +131,15 @@ class RTLSDR(SDR):
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets\
"When gain_mode = 'relative', gain must be < 0. This sets\ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
target_gain = max_gain + gain target_gain = max_gain + gain
else: else:
target_gain = gain target_gain = gain
if target_gain < min_gain or target_gain > max_gain: if target_gain < min_gain or target_gain > max_gain:
print( print(f"Requested gain {target_gain} dB out of range;\
f"Requested gain {target_gain} dB out of range;\ clamping to valid span {min_gain}-{max_gain} dB.")
clamping to valid span {min_gain}-{max_gain} dB."
)
target_gain = min(max(target_gain, min_gain), max_gain) target_gain = min(max(target_gain, min_gain), max_gain)
target_gain = min(available_gains, key=lambda g: abs(g - target_gain)) target_gain = min(available_gains, key=lambda g: abs(g - target_gain))

View File

@ -392,10 +392,8 @@ class ThinkRF(SDR):
actual_sample_rate = self.BASE_SAMPLE_RATE / decimation actual_sample_rate = self.BASE_SAMPLE_RATE / decimation
if abs(actual_sample_rate - requested_sample_rate) > 1e3: # More than 1 kHz difference if abs(actual_sample_rate - requested_sample_rate) > 1e3: # More than 1 kHz difference
print( print(f"ThinkRF: Requested {requested_sample_rate/1e6:.2f} MS/s → \
f"ThinkRF: Requested {requested_sample_rate/1e6:.2f} MS/s → \ Using decimation={decimation} ({actual_sample_rate/1e6:.2f} MS/s)")
Using decimation={decimation} ({actual_sample_rate/1e6:.2f} MS/s)"
)
return decimation, actual_sample_rate return decimation, actual_sample_rate

View File

@ -148,10 +148,8 @@ class USRP(SDR):
gain_range = self.usrp.get_rx_gain_range() gain_range = self.usrp.get_rx_gain_range()
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets\
"When gain_mode = 'relative', gain must be < 0. This sets\ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
else: else:
# set gain relative to max # set gain relative to max
abs_gain = gain_range.stop() + gain abs_gain = gain_range.stop() + gain
@ -356,10 +354,8 @@ class USRP(SDR):
gain_range = self.usrp.get_tx_gain_range() gain_range = self.usrp.get_tx_gain_range()
if gain_mode == "relative": if gain_mode == "relative":
if gain > 0: if gain > 0:
raise SDRParameterError( raise SDRParameterError("When gain_mode = 'relative', gain must be < 0. This sets\
"When gain_mode = 'relative', gain must be < 0. This sets\ the gain relative to the maximum possible gain.")
the gain relative to the maximum possible gain."
)
else: else:
# set gain relative to max # set gain relative to max
abs_gain = gain_range.stop() + gain abs_gain = gain_range.stop() + gain

View File

@ -24,12 +24,7 @@ For detailed examples and API reference, see the documentation.
""" """
from .basic import Add, FrequencyShift, MultiplyConstant, PhaseShift from .basic import Add, FrequencyShift, MultiplyConstant, PhaseShift
from .generators import ( from .generators import PAMGenerator, PSKGenerator, QAMGenerator, SignalGenerator
PAMGenerator,
PSKGenerator,
QAMGenerator,
SignalGenerator,
)
from .mapping import Mapper, SymbolDemapper from .mapping import Mapper, SymbolDemapper
from .process_block import ProcessBlock from .process_block import ProcessBlock
from .pulse_shaping import ( from .pulse_shaping import (

View File

@ -37,10 +37,8 @@ class Add(RecordableBlock, ProcessBlock):
samples = block.get_samples(num_samples) samples = block.get_samples(num_samples)
if len(samples) != num_samples: if len(samples) != num_samples:
raise ValueError( raise ValueError(f"Block {self.__class__.__name__} requested {num_samples} \
f"Block {self.__class__.__name__} requested {num_samples} \ from block {block.__class__.__name__} but got {len(samples)}.")
from block {block.__class__.__name__} but got {len(samples)}."
)
return samples return samples

View File

@ -23,11 +23,9 @@ class ProcessBlock(Block, ABC):
) )
elif not all(isinstance(item, Block) for item in input): elif not all(isinstance(item, Block) for item in input):
raise ValueError( raise ValueError(f"Invalid input to block '{self.__class__.__name__}'. \
f"Invalid input to block '{self.__class__.__name__}'. \
Expected a list of Block objects but got \ Expected a list of Block objects but got \
{'[' + ',' .join(f'{item.__class__.__name__}({repr(item)})' for item in input) + ']'}" {'[' + ',' .join(f'{item.__class__.__name__}({repr(item)})' for item in input) + ']'}")
)
elif len(input) != len(self.input_type): elif len(input) != len(self.input_type):
raise ValueError( raise ValueError(

View File

@ -20,10 +20,8 @@ class RecordableBlock(Block, Recordable):
:raises ValueError: If the number of samples is incorrect.""" :raises ValueError: If the number of samples is incorrect."""
samples = self.get_samples(num_samples) samples = self.get_samples(num_samples)
if len(samples) != num_samples: if len(samples) != num_samples:
raise ValueError( raise ValueError(f"Error in block {self.__class__.__name__} record(). \
f"Error in block {self.__class__.__name__} record(). \ Requested {num_samples} samples but got {len(samples)}")
Requested {num_samples} samples but got {len(samples)}"
)
metadata = self._get_metadata() metadata = self._get_metadata()
return Recording(data=samples, metadata=metadata) return Recording(data=samples, metadata=metadata)

View File

@ -39,9 +39,7 @@ class RecordingSource(SourceBlock, RecordableBlock):
:raises ValueError: If num_samples is greater than the recording length. :raises ValueError: If num_samples is greater than the recording length.
""" """
if num_samples - 1 >= self.recording.data.shape[1]: if num_samples - 1 >= self.recording.data.shape[1]:
raise ValueError( raise ValueError(f"{num_samples} samples requested from recording source with \
f"{num_samples} samples requested from recording source with \ {self.recording.data.shape[1]} samples available.")
{self.recording.data.shape[1]} samples available."
)
return self.recording.data[0, 0:num_samples] return self.recording.data[0, 0:num_samples]

View File

@ -610,10 +610,8 @@ def cut_out( # noqa: C901 # TODO: Simplify function
raise ValueError("signal must be CxN complex.") raise ValueError("signal must be CxN complex.")
if fill_type not in {"zeros", "ones", "low-snr", "avg-snr", "high-snr"}: if fill_type not in {"zeros", "ones", "low-snr", "avg-snr", "high-snr"}:
raise UserWarning( raise UserWarning("""fill_type must be "zeros", "ones", "low-snr", "avg-snr", or "high-snr",
"""fill_type must be "zeros", "ones", "low-snr", "avg-snr", or "high-snr", "ones" has been selected by default""")
"ones" has been selected by default"""
)
if max_section_size < 1 or max_section_size >= n: if max_section_size < 1 or max_section_size >= n:
raise ValueError("max_section_size must be at least 1 and must be less than the length of signal.") raise ValueError("max_section_size must be at least 1 and must be less than the length of signal.")

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -114,8 +114,8 @@ def view_sig(
logo: Optional[bool] = True, logo: Optional[bool] = True,
dark: Optional[bool] = True, dark: Optional[bool] = True,
spines: Optional[bool] = False, spines: Optional[bool] = False,
title_fontsize: Optional[int] = 40, title_fontsize: Optional[int] = 35,
subtitle_fontsize: Optional[int] = 20, subtitle_fontsize: Optional[int] = 15,
) -> None: ) -> None:
""" """
Create a plot of various signal visualizations as a png or svg image. Create a plot of various signal visualizations as a png or svg image.
@ -173,7 +173,7 @@ def view_sig(
plot_length = len(recording.data[0]) plot_length = len(recording.data[0])
# Plot preparation # Plot preparation
fig = plt.figure(figsize=(14, 12)) fig = plt.figure(figsize=(16, 14))
fig.suptitle(title, fontsize=title_fontsize) fig.suptitle(title, fontsize=title_fontsize)
gs = gridspec.GridSpec(subplot_height, subplot_width) gs = gridspec.GridSpec(subplot_height, subplot_width)
@ -209,7 +209,7 @@ def view_sig(
) )
set_spines(spec_ax, spines) set_spines(spec_ax, spines)
spec_ax.set_title("Spectrogram", loc="center", fontsize=subtitle_fontsize) spec_ax.set_title("Spectrogram", fontsize=subtitle_fontsize)
spec_ax.set_ylabel("Frequency (Hz)") spec_ax.set_ylabel("Frequency (Hz)")
spec_ax.set_xlabel("Time (s)") spec_ax.set_xlabel("Time (s)")
@ -295,8 +295,7 @@ def view_sig(
set_spines(meta_ax, spines) set_spines(meta_ax, spines)
if logo and os.path.isfile(logo_path): if logo and os.path.isfile(logo_path):
logo_ax = plt.subplot(gs[plot_y_indx:, 2]) logo_ax = plt.subplot(gs[plot_y_indx + 2 :, 2])
plot_x_indx = plot_x_indx + 1
logo_ax.axis("off") logo_ax.axis("off")
try: try:

View File

@ -246,18 +246,20 @@ def view_simple_sig(
ax2.set_xlabel("Time (s)") ax2.set_xlabel("Time (s)")
ax1.set_ylabel("Amplitude") ax1.set_ylabel("Amplitude")
ax1.set_title(f"Time Series - {sdr} SDR") ax1.set_title(f"Time Series - {sdr} SDR", loc="left", pad=10)
ax1.legend(loc="upper right") ax1.legend(loc="upper right")
ax2.set_ylabel("Frequency (Hz)") ax2.set_ylabel("Frequency (Hz)")
ax2.set_title(f"Spectrogram - {center_freq_hz / 1e6:.1f} MHz ± {sample_rate_hz / 2e6:.1f} MHz") ax2.set_title(
f"Spectrogram - {center_freq_hz / 1e6:.1f} MHz ± {sample_rate_hz / 2e6:.1f} MHz", loc="left", pad=10
)
yticks = ax2.get_yticks() yticks = ax2.get_yticks()
ax2.set_yticklabels([f"{y / 1e6:.1f}" for y in yticks]) ax2.set_yticklabels([f"{y / 1e6:.1f}" for y in yticks])
elif not compact_mode: elif not compact_mode:
ax1.set_title("Time Series") ax1.set_title("Time Series", loc="left", pad=10)
ax1.legend(loc="upper right", fontsize=8) ax1.legend(loc="upper right", fontsize=8)
ax2.set_title("Spectrogram") ax2.set_title("Spectrogram", loc="left", pad=10)
if ax_constellation is not None: if ax_constellation is not None:
constellation_samples = _get_plot_samples(signal=signal, fast_mode=fast_mode, slow_max=50_000, fast_max=20_000) constellation_samples = _get_plot_samples(signal=signal, fast_mode=fast_mode, slow_max=50_000, fast_max=20_000)
@ -308,7 +310,7 @@ def view_simple_sig(
else: else:
plt.tight_layout() plt.tight_layout()
if show_title: if show_title:
plt.subplots_adjust(top=0.92) plt.subplots_adjust(top=0.90)
if saveplot: if saveplot:
output_path, extension = set_path(output_path=output_path) output_path, extension = set_path(output_path=output_path)

View File

@ -299,7 +299,7 @@ def capture(
\b \b
Examples: Examples:
ria capture -d hackrf -s 2e6 -f 2.44e6 -b 2e6 ria capture -d hackrf -s 2e6 -f 2.44e6 -b 2e6 -n 50
ria capture -d pluto -s 1e6 -f 2e9 -b 2e6 -n 50 ria capture -d pluto -s 1e6 -f 2e9 -b 2e6 -n 50
""" """

View File

@ -39,9 +39,7 @@ from ria_toolkit_oss.signal.block_generator.symbol_modulation import (
OOKModulator, OOKModulator,
OQPSKModulator, OQPSKModulator,
) )
from ria_toolkit_oss.transforms.iq_impairments import ( from ria_toolkit_oss.transforms.iq_impairments import iq_imbalance
iq_imbalance,
)
from ria_toolkit_oss_cli.ria_toolkit_oss.common import ( from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
echo_progress, echo_progress,
echo_verbose, echo_verbose,