reflections successfully parsed
This commit is contained in:
parent
c6537b51ae
commit
cde40ce1d9
BIN
requirements.txt
Normal file
BIN
requirements.txt
Normal file
Binary file not shown.
17
scripts/helper.py
Normal file
17
scripts/helper.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# {'TIME': [data], 'CH1': [data], 'CH2': [data]}
|
||||||
|
def cut_time(data : dict, start : float, end : float) -> dict:
|
||||||
|
idx_start = 0
|
||||||
|
idx_end = 0
|
||||||
|
|
||||||
|
for idx, t in enumerate(data['TIME']):
|
||||||
|
if t > start and idx_start == 0:
|
||||||
|
idx_start = idx
|
||||||
|
if t > end and idx_end == 0:
|
||||||
|
idx_end = idx
|
||||||
|
if idx_end != 0 and idx_start != 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
if idx_end != 0 and idx_start != 0:
|
||||||
|
return {key: value[idx_start:idx_end] for key, value in data.items()}
|
||||||
|
else:
|
||||||
|
return None
|
@ -4,14 +4,13 @@ class Reader():
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def readFile(self, filename) -> dict:
|
def read_file(self, filename) -> dict:
|
||||||
with open(filename, 'r') as file:
|
with open(filename, 'r') as file:
|
||||||
data = list(csv.reader(file, delimiter=','))
|
data = list(csv.reader(file, delimiter=','))
|
||||||
|
|
||||||
# Delete metadata for now
|
# Delete metadata for now
|
||||||
print("Removing metadata")
|
|
||||||
for i in range(15):
|
for i in range(15):
|
||||||
print(data.pop(0))
|
data.pop(0)
|
||||||
|
|
||||||
# {'TIME': [data], 'CH1': [data], 'CH2': [data]}
|
# {'TIME': [data], 'CH1': [data], 'CH2': [data]}
|
||||||
channels = []
|
channels = []
|
||||||
@ -31,5 +30,6 @@ class Reader():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
reader = Reader()
|
reader = Reader()
|
||||||
data = reader.readFile(r".\data\T0007ALL.csv")
|
data = reader.read_file(r".\data\T0007ALL.csv")
|
||||||
print(data)
|
print(data)
|
||||||
|
|
@ -1,10 +1,45 @@
|
|||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
|
from scipy import signal
|
||||||
|
import numpy as np
|
||||||
import reader
|
import reader
|
||||||
|
import helper
|
||||||
|
|
||||||
|
# load data
|
||||||
data_reader = reader.Reader()
|
data_reader = reader.Reader()
|
||||||
data = data_reader.readFile(r".\data\T0001CH1.csv")
|
data = data_reader.read_file(r".\data\T0004CH1.csv")
|
||||||
|
|
||||||
|
# slice empty space, start and end time is in seconds
|
||||||
|
data = helper.cut_time(data, -1e-7, 5e-7)
|
||||||
|
|
||||||
|
# find peaks, use max to find the highest, or a threshold
|
||||||
|
# adjust width to find the middle of a peak (width is in indices)
|
||||||
|
# peaks, _ = signal.find_peaks(data['CH1'], max(data['CH1']))
|
||||||
|
peaks, _ = signal.find_peaks(data['CH1'], 2, width=10)
|
||||||
|
|
||||||
|
# find throughs, comment away it finds too many throughs
|
||||||
|
# invert = [-x for x in data['CH1']]
|
||||||
|
# throughs, _ = signal.find_peaks(invert, max(invert))
|
||||||
|
# peaks = np.concatenate([peaks, throughs])
|
||||||
|
|
||||||
|
# store time step
|
||||||
|
step = data['TIME'][1] - data['TIME'][0]
|
||||||
|
|
||||||
|
# do some calcs
|
||||||
|
idx_diff = peaks[-1] - peaks[0]
|
||||||
|
tim_diff = idx_diff*step
|
||||||
|
print(f"Time between peaks: {tim_diff*1e9:.1f} ns")
|
||||||
|
c = 299792458
|
||||||
|
k = 0.66
|
||||||
|
c_coax = c * k
|
||||||
|
print(f"Measured distance: {(tim_diff/2)*c_coax:.2f} m")
|
||||||
|
|
||||||
|
# Plot data
|
||||||
plt.plot(data['TIME'], data['CH1'])
|
plt.plot(data['TIME'], data['CH1'])
|
||||||
|
if len(peaks) > 0:
|
||||||
|
for peak in peaks:
|
||||||
|
plt.vlines(
|
||||||
|
peak*step+data['TIME'][0],
|
||||||
|
min(data['CH1']),
|
||||||
|
max(data['CH1']), 'red', 'dashed')
|
||||||
|
plt.grid()
|
||||||
plt.show()
|
plt.show()
|
Loading…
Reference in New Issue
Block a user