tested and tuned on Veghel Lab system

This commit is contained in:
gertjan 2026-03-17 23:20:26 +01:00
parent 5d20d50822
commit 06f35acc4e
2 changed files with 15 additions and 13 deletions

View file

@ -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<Va>[\d.-]+)\s+Vp=(?P<Vp>[\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()