frequency avoidance - work in progress
This commit is contained in:
parent
1bfefa94bb
commit
877915ae38
1 changed files with 20 additions and 16 deletions
36
scanner.py
36
scanner.py
|
|
@ -27,6 +27,8 @@ PATTERN = re.compile(
|
||||||
r"(?P<adc_vmax>[0-9a-fA-F]+)\s+" # Second hex
|
r"(?P<adc_vmax>[0-9a-fA-F]+)\s+" # Second hex
|
||||||
r"(?P<adc_imin>[0-9a-fA-F]+)-" # Third hex
|
r"(?P<adc_imin>[0-9a-fA-F]+)-" # Third hex
|
||||||
r"(?P<adc_imax>[0-9a-fA-F]+)" # Fourth hex
|
r"(?P<adc_imax>[0-9a-fA-F]+)" # Fourth hex
|
||||||
|
r"nv=(?P<nv>-?\d+\.?\d*)\s+" # voltage noise/interference
|
||||||
|
r"ni=(?P<ni>-?\d+\.?\d*)\s+" # current noise/interference
|
||||||
)
|
)
|
||||||
|
|
||||||
config_path = '/home/bart/python-scanner/config.yaml'
|
config_path = '/home/bart/python-scanner/config.yaml'
|
||||||
|
|
@ -63,12 +65,12 @@ def dump_into_database():
|
||||||
if state["noise_scan"]==False:
|
if state["noise_scan"]==False:
|
||||||
# regular scan data
|
# regular scan data
|
||||||
formatted_rows = [
|
formatted_rows = [
|
||||||
[sweep_insert_time, r[0], r[5], r[6], r[1], r[2], r[3], r[4]]
|
[sweep_insert_time, r[0], r[5], r[6], r[1], r[2], r[3], r[4], r[11], r[12]]
|
||||||
for r in data_rows
|
for r in data_rows
|
||||||
]
|
]
|
||||||
sql = """
|
sql = """
|
||||||
INSERT INTO SequenceValues (StartTimeOfSweep, Freq, ZR, ZX, Vampl, Vphase, Iampl, Iphase)
|
INSERT INTO SequenceValues (StartTimeOfSweep, Freq, ZR, ZX, Vampl, Vphase, Iampl, Iphase, Vnoise, Inoise)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?) \
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) \
|
||||||
"""
|
"""
|
||||||
else:
|
else:
|
||||||
# noise scan data
|
# noise scan data
|
||||||
|
|
@ -97,7 +99,7 @@ def dump_into_database():
|
||||||
def dump_csv(filename="data.csv"):
|
def dump_csv(filename="data.csv"):
|
||||||
df = pd.DataFrame(
|
df = pd.DataFrame(
|
||||||
data_rows,
|
data_rows,
|
||||||
columns=["Freq", "Va", "Vp", "Ia", "Ip", "ZR", "ZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax"]
|
columns=["Freq", "Va", "Vp", "Ia", "Ip", "ZR", "ZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax", "nv", "ni"]
|
||||||
)
|
)
|
||||||
df.to_csv(filename, index=False)
|
df.to_csv(filename, index=False)
|
||||||
|
|
||||||
|
|
@ -134,17 +136,19 @@ def extract_to_dataframe(line):
|
||||||
if not match:
|
if not match:
|
||||||
return # silently ignore malformed lines
|
return # silently ignore malformed lines
|
||||||
row = [
|
row = [
|
||||||
float(state["freq"]),
|
float(state["freq"]), # row 0
|
||||||
float(match.group("Va")),
|
float(match.group("Va")), # row 1
|
||||||
float(match.group("Vp")),
|
float(match.group("Vp")), # row 2
|
||||||
float(match.group("Ia")),
|
float(match.group("Ia")), # row 3
|
||||||
float(match.group("Ip")),
|
float(match.group("Ip")), # row 4
|
||||||
float(match.group("ZR")),
|
float(match.group("ZR")), # row 5
|
||||||
float(match.group("ZX")),
|
float(match.group("ZX")), # row 6
|
||||||
int(match.group("adc_vmin"), 16),
|
int(match.group("adc_vmin"), 16), # row 7
|
||||||
int(match.group("adc_vmax"), 16),
|
int(match.group("adc_vmax"), 16), # row 8
|
||||||
int(match.group("adc_imin"), 16),
|
int(match.group("adc_imin"), 16), # row 9
|
||||||
int(match.group("adc_imax"), 16),
|
int(match.group("adc_imax"), 16), # row 10
|
||||||
|
float(match.group("nv")), # row 11
|
||||||
|
float(match.group("ni")), # row 12
|
||||||
]
|
]
|
||||||
row[1] = row[1]/(2*3.14159*row[0]*0.00005 + 1) # compensate Va for pole at 20kHz
|
row[1] = row[1]/(2*3.14159*row[0]*0.00005 + 1) # compensate Va for pole at 20kHz
|
||||||
row[5] = row[1]/row[3] * math.cos(0.01745*(row[2]-row[4]))
|
row[5] = row[1]/row[3] * math.cos(0.01745*(row[2]-row[4]))
|
||||||
|
|
@ -160,7 +164,7 @@ def process_line(line):
|
||||||
def get_dataframe():
|
def get_dataframe():
|
||||||
return pd.DataFrame(
|
return pd.DataFrame(
|
||||||
data_rows,
|
data_rows,
|
||||||
columns=["Va", "Vp", "Ia", "Ip", "ZR", "ZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax"]
|
columns=["Va", "Vp", "Ia", "Ip", "ZR", "ZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax", "nv", "ni"]
|
||||||
)
|
)
|
||||||
|
|
||||||
class TelnetReader:
|
class TelnetReader:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue