Skip to content

Commit

Permalink
Merge pull request #2 from NTIA/fix-calibration-defaulting
Browse files Browse the repository at this point in the history
Fix calibration defaulting
  • Loading branch information
jhazentia committed Jun 30, 2020
2 parents db2f0eb + ebcae53 commit 4cb7ef0
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 79 deletions.
44 changes: 29 additions & 15 deletions scos_usrp/hardware/tests/resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def is_close(a, b, tolerance):
return abs(a - b) <= tolerance


def create_dummy_calibration():
def create_dummy_calibration(empty_cal=False):
"""Create a dummy calibration object"""

# Define the calibration file steps
Expand All @@ -38,22 +38,36 @@ def create_dummy_calibration():
# Create the frequency divisions
calibration_frequency_divisions = []

# Create the actual data
# Create the actual data if not an empty cal file
calibration_data = {}
for sr in sample_rates:
for f in frequencies:
for g in gains:
# Make sure the dicts are feshed out
if sr not in calibration_data.keys():
calibration_data[sr] = {}
if f not in calibration_data[sr].keys():
calibration_data[sr][f] = {}
calibration_data[sr][f][g] = {
"gain_sigan": easy_gain(sr, f, g),
"gain_preselector": -10,
"gain_sensor": easy_gain(sr, f, g) - 10,
"1db_compression_sensor": 1,
if not empty_cal:
for sr in sample_rates:
for f in frequencies:
for g in gains:
# Make sure the dicts are feshed out
if sr not in calibration_data.keys():
calibration_data[sr] = {}
if f not in calibration_data[sr].keys():
calibration_data[sr][f] = {}
calibration_data[sr][f][g] = {
"gain_sigan": easy_gain(sr, f, g),
"gain_preselector": -10,
"gain_sensor": easy_gain(sr, f, g) - 10,
"1db_compression_sensor": 1,
}
else: # Create an empty calibration file
calibration_data = { # Empty calibration file data
10e6: {
1e9: {
40: {},
60: {}
},
2e9: {
40: {},
60: {}
}
}
}

return Calibration(
calibration_datetime,
Expand Down
167 changes: 107 additions & 60 deletions scos_usrp/hardware/tests/test_usrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from scos_usrp.hardware import radio
from scos_usrp.hardware.tests.resources.utils import easy_gain, is_close
from scos_usrp.hardware.tests.resources.utils import easy_gain, is_close, create_dummy_calibration


class TestUSRP:
Expand Down Expand Up @@ -146,66 +146,113 @@ def test_defaulted_calibration_values(self):
self.rx.sigan_calibration = None
self.rx.sensor_calibration = None

# Create a dummy setup
sample_rate = 10e6
gain_setting = 40
frequency = 100e6

# Setup the rx
self.rx.sample_rate = sample_rate
self.rx.gain = gain_setting
self.rx.frequency = frequency

# Recompute the calibration parameters
self.rx.recompute_calibration_data()

# Check the defaulted calibration parameters
self.check_defaulted_calibration_parameter(
"gain_sigan", gain_setting, self.rx.sigan_calibration_data["gain_sigan"]
)
self.check_defaulted_calibration_parameter(
"enbw_sigan", sample_rate, self.rx.sigan_calibration_data["enbw_sigan"]
)
self.check_defaulted_calibration_parameter(
"noise_figure_sigan",
0,
self.rx.sigan_calibration_data["noise_figure_sigan"],
)
self.check_defaulted_calibration_parameter(
"1db_compression_sigan",
100,
self.rx.sigan_calibration_data["1db_compression_sigan"],
)
self.check_defaulted_calibration_parameter(
"gain_sensor", gain_setting, self.rx.sensor_calibration_data["gain_sensor"]
)
self.check_defaulted_calibration_parameter(
"enbw_sensor", sample_rate, self.rx.sensor_calibration_data["enbw_sensor"]
)
self.check_defaulted_calibration_parameter(
"noise_figure_sensor",
0,
self.rx.sensor_calibration_data["noise_figure_sensor"],
)
self.check_defaulted_calibration_parameter(
"1db_compression_sensor",
100,
self.rx.sensor_calibration_data["1db_compression_sensor"],
)
self.check_defaulted_calibration_parameter(
"gain_preselector", 0, self.rx.sensor_calibration_data["gain_preselector"]
)
self.check_defaulted_calibration_parameter(
"noise_figure_preselector",
0,
self.rx.sensor_calibration_data["noise_figure_preselector"],
)
self.check_defaulted_calibration_parameter(
"1db_compression_preselector",
100,
self.rx.sensor_calibration_data["1db_compression_preselector"],
)
# Create some dummy setups to ensure calibration updates
sample_rates = [10e6, 40e6, 1e6, 56e6 ]
gain_settings = [40, 60, 0, 60 ]
frequencies = [1000e6, 2000e6, 10e6, 1500e6]

# Run each set
for i in range(len(sample_rates)):
# Get the parameters for this run
sample_rate = sample_rates[i]
gain_setting = gain_settings[i]
frequency = frequencies[i]

# Setup the rx
self.rx.sample_rate = sample_rate
self.rx.gain = gain_setting
self.rx.frequency = frequency

# Recompute the calibration parameters
self.rx.recompute_calibration_data()

# Check the defaulted calibration parameters
self.check_defaulted_calibration_parameter(
"gain_sigan", gain_setting, self.rx.sigan_calibration_data["gain_sigan"]
)
self.check_defaulted_calibration_parameter(
"enbw_sigan", sample_rate, self.rx.sigan_calibration_data["enbw_sigan"]
)
self.check_defaulted_calibration_parameter(
"noise_figure_sigan",
0,
self.rx.sigan_calibration_data["noise_figure_sigan"],
)
self.check_defaulted_calibration_parameter(
"1db_compression_sigan",
100,
self.rx.sigan_calibration_data["1db_compression_sigan"],
)
self.check_defaulted_calibration_parameter(
"gain_sensor",
gain_setting,
self.rx.sensor_calibration_data["gain_sensor"],
)
self.check_defaulted_calibration_parameter(
"enbw_sensor",
sample_rate,
self.rx.sensor_calibration_data["enbw_sensor"],
)
self.check_defaulted_calibration_parameter(
"noise_figure_sensor",
0,
self.rx.sensor_calibration_data["noise_figure_sensor"],
)
self.check_defaulted_calibration_parameter(
"1db_compression_sensor",
100,
self.rx.sensor_calibration_data["1db_compression_sensor"],
)
self.check_defaulted_calibration_parameter(
"gain_preselector",
0,
self.rx.sensor_calibration_data["gain_preselector"],
)
self.check_defaulted_calibration_parameter(
"noise_figure_preselector",
0,
self.rx.sensor_calibration_data["noise_figure_preselector"],
)
self.check_defaulted_calibration_parameter(
"1db_compression_preselector",
100,
self.rx.sensor_calibration_data["1db_compression_preselector"],
)

# Reload the calibrations in case they're used elsewhere
self.rx.sigan_calibration = sigan_calibration
self.rx.sensor_calibration = sensor_calibration

def test_sigan_only_defaulting(self):
"""Ensure that sensor calibration values default to sigan"""

# Load an empty sensor calibration
self.rx.sensor_calibration = create_dummy_calibration(empty_cal=True)

# Create some dummy setups to ensure calibration updates
sample_rates = [10e6, 40e6, 1e6, 56e6 ]
gain_settings = [40, 60, 0, 60 ]
frequencies = [1000e6, 2000e6, 10e6, 1500e6]

# Run each set
for i in range(len(sample_rates)):
# Get the parameters for this run
sample_rate = sample_rates[i]
gain_setting = gain_settings[i]
frequency = frequencies[i]

# Setup the rx
self.rx.sample_rate = sample_rate
self.rx.gain = gain_setting
self.rx.frequency = frequency

# Recompute the calibration parameters
self.rx.recompute_calibration_data()

# Check the defaulted calibration parameters
self.check_defaulted_calibration_parameter(
"gain_sensor", self.rx.sigan_calibration_data["gain_sigan"], self.rx.sensor_calibration_data["gain_sensor"]
)

# Reload the dummy sensor calibration in case they're used elsewhere
self.rx.sensor_calibration = create_dummy_calibration()
6 changes: 2 additions & 4 deletions scos_usrp/hardware/usrp_radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def recompute_calibration_data(self):
"""Set the calibration data based on the currently tuning"""

# Try and get the sensor calibration data
self.sensor_calibration_data = DEFAULT_SENSOR_CALIBRATION.copy()
if self.sensor_calibration is not None:
self.sensor_calibration_data.update(
self.sensor_calibration.get_calibration_dict(
Expand All @@ -252,10 +253,9 @@ def recompute_calibration_data(self):
gain=self.gain,
)
)
else:
self.sensor_calibration_data = DEFAULT_SENSOR_CALIBRATION.copy()

# Try and get the sigan calibration data
self.sigan_calibration_data = DEFAULT_SIGAN_CALIBRATION.copy()
if self.sigan_calibration is not None:
self.sigan_calibration_data.update(
self.sigan_calibration.get_calibration_dict(
Expand All @@ -264,8 +264,6 @@ def recompute_calibration_data(self):
gain=self.gain,
)
)
else:
self.sigan_calibration_data = DEFAULT_SIGAN_CALIBRATION.copy()

# Catch any defaulting calibration values for the sigan
if self.sigan_calibration_data["gain_sigan"] is None:
Expand Down

0 comments on commit 4cb7ef0

Please sign in to comment.