Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve failed calibration handling #125

Merged
merged 14 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies = [
"its_preselector @ git+https://github.com/NTIA/[email protected]",
"msgspec>=0.16.0,<1.0.0",
"numexpr>=2.8.3",
"numpy>=1.25.0",
"numpy>=1.25.0,<2",
"psutil>=5.9.4",
"python-dateutil>=2.0",
"ray>=2.10.0",
Expand Down
32 changes: 23 additions & 9 deletions scos_actions/actions/calibrate_y_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,19 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int):

# Run calibration routine
for i, p in enumerate(self.iteration_params):
cal_result = self.calibrate(p)
# Retry once if channel calibration failed
if cal_result == "FAILED":
logger.warning(f"Retrying calibration at {p[FREQUENCY]/1e6} MHz")
cal_result = self.calibrate(p)
if cal_result == "FAILED":
logger.warning(
f"Retry failed. Calibration data not updated for f={p[FREQUENCY]}"
)
if i == 0:
detail += self.calibrate(p)
detail += cal_result
else:
detail += os.linesep + self.calibrate(p)
detail += os.linesep + cal_result
return detail

def calibrate(self, params: dict):
Expand Down Expand Up @@ -346,19 +355,24 @@ def calibrate(self, params: dict):
pwr_on_watts, pwr_off_watts, enr_linear, enbw_hz, temp_k
)

# Update sensor calibration with results
self.sensor.sensor_calibration.update(
sigan_params, utils.get_datetime_str_now(), gain, noise_figure, temp_c
)

if np.isfinite(gain) and np.isfinite(noise_figure):
# Update sensor calibration with results
self.sensor.sensor_calibration.update(
sigan_params, utils.get_datetime_str_now(), gain, noise_figure, temp_c
)
else:
# At least one of {noise figure, gain} is NaN or infinite. This triggers
# a single retry for this set of params. See __call__ above.
logger.warning(f"Calibration result is NaN at {params[FREQUENCY]/1e6} MHz:")
logger.warning(f"\tNF: {noise_figure}, Gain: {gain}")
return "FAILED"
# Debugging
noise_floor_dBm = convert_watts_to_dBm(Boltzmann * temp_k * enbw_hz)
logger.debug(f"Noise floor: {noise_floor_dBm:.2f} dBm")
logger.debug(f"Noise figure: {noise_figure:.2f} dB")
logger.debug(f"Gain: {gain:.2f} dB")

# Detail results contain only FFT version of result for now
return f"Noise Figure: {noise_figure}, Gain: {gain}"
return f"Noise Figure: {noise_figure:.2f}, Gain: {gain:.2f}"

@property
def description(self):
Expand Down