From 06f35acc4e8d5904306ea6540221b3f2a4005117 Mon Sep 17 00:00:00 2001 From: gertjan Date: Tue, 17 Mar 2026 23:20:26 +0100 Subject: [PATCH] tested and tuned on Veghel Lab system --- config.yaml | 8 ++++---- scanner.py | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config.yaml b/config.yaml index 6e3e2c2..5a2cb4e 100644 --- a/config.yaml +++ b/config.yaml @@ -1,9 +1,9 @@ # Configuration file for scanner service # it is automatically re-loaded between scans -start_freq: 10000.0 -stop_freq: 0.1 +start_freq: 1000 +stop_freq: 0.2 freq_step_multiply: 0.95 +allowed_noise_level: 9 +skip_scans_for_noisy_freqs: 5 ampl: 1600 -interference_freq: 0.052 -interference_bandwidth: 0.008 noise_scan: False diff --git a/scanner.py b/scanner.py index 4b2e645..f36a1a9 100644 --- a/scanner.py +++ b/scanner.py @@ -15,7 +15,7 @@ import os data_rows = [] # global 2-D list state = {} blacklist = [] -ALLOWED_NOISE_LEVEL = 100.0 +Inoise_baseline = 0.1 PATTERN = re.compile( r"Va=(?P[\d.-]+)\s+Vp=(?P[\d.-]+)\s+\|\s+" @@ -198,7 +198,7 @@ class TelnetReader: print("Interrupted by user.") print(data_rows) if state["freq"]>0.00001: # check if scan ended normally (e.g. no abort due to clipping) - if False: + if True: # XXXDB dump_into_database() else: dump_csv("measurements.csv") @@ -217,6 +217,7 @@ class TelnetReader: def process_line(self, line): global state + global Inoise_baseline # print(f"RAW: {line}") if not line.startswith("Va="): # skip lines that are not to be analyzed return @@ -239,15 +240,17 @@ class TelnetReader: # there will be a lot of lines, but they will be skipped as they do not match the pattern else: # regular loop (not initializing) extract_to_dataframe(line) # capture the measurement - if data_rows and (data_rows[-1][11]>ALLOWED_NOISE_LEVEL or data_rows[-1][12]>ALLOWED_NOISE_LEVEL): + if state["freq"]>3.0: + Inoise_baseline = 0.8*Inoise_baseline + 0.2*data_rows[-1][12] # remember last baseline around 3Hz (assuming top-down scanning) + if data_rows and (data_rows[-1][11]>state["allowed_noise_level"] or data_rows[-1][12]>state["allowed_noise_level"] or (state["freq"]<3.0 and data_rows[-1][12]>1.25*Inoise_baseline)): # Too much noise: add to blacklist print("Too much noise - adding to blacklist") - blacklist.append({"Freq": state["freq"], "NrToSkip": 10}) + blacklist.append({"Freq": state["freq"], "NrToSkip": state["skip_scans_for_noisy_freqs"]}) print(f"Blacklist: {blacklist}\r") del data_rows[-1] # remove this last entry from the list (for DB it is okay, but for CSV things will shift) -# print(f"minmax: {data_rows[7]},{data_rows[8]},{data_rows[9]},{data_rows[10] }\n") - if data_rows and (data_rows[-1][7]<5 or data_rows[-1][8]>250 or data_rows[-1][9]<5 or data_rows[-1][10]>250): # XXXDB - state["freq"] = 0 # force ending of the scan, and write no data in the database + else: + if data_rows and (data_rows[-1][7]<5 or data_rows[-1][8]>250 or data_rows[-1][9]<5 or data_rows[-1][10]>250): # XXXDB + state["freq"] = 0 # force ending of the scan, and write no data in the database # calculate next freq if state["freq"] > 1.0: freq_multiplier = state["freq_step_multiply"] # calc next freq @@ -313,11 +316,10 @@ if __name__ == "__main__": reader.read_loop() # decrement all freq's in blacklist: - print(f"Before decrementing: {blacklist}") for item in blacklist: item["NrToSkip"] -= 1 blacklist = [item for item in blacklist if item["NrToSkip"] != 0] # remove all zero items - print(f"After removing zeros: {blacklist}") + print(f"Blacklist: {blacklist}") finally: reader.disconnect()