better CSV file filtering
This commit is contained in:
@@ -457,8 +457,8 @@ def belts_calibration(lognames, klipperdir='~/klipper', max_freq=200.0, st_versi
|
|||||||
global shaper_calibrate
|
global shaper_calibrate
|
||||||
shaper_calibrate = setup_klipper_import(klipperdir)
|
shaper_calibrate = setup_klipper_import(klipperdir)
|
||||||
|
|
||||||
# Parse data
|
# Parse data from the log files while ignoring CSV in the wrong format
|
||||||
datas = [parse_log(fn) for fn in lognames]
|
datas = [data for data in (parse_log(fn) for fn in lognames) if data is not None]
|
||||||
if len(datas) > 2:
|
if len(datas) > 2:
|
||||||
raise ValueError('Incorrect number of .csv files used (this function needs exactly two files to compare them)!')
|
raise ValueError('Incorrect number of .csv files used (this function needs exactly two files to compare them)!')
|
||||||
|
|
||||||
|
|||||||
@@ -299,8 +299,8 @@ def shaper_calibration(lognames, klipperdir='~/klipper', max_smoothing=None, scv
|
|||||||
global shaper_calibrate
|
global shaper_calibrate
|
||||||
shaper_calibrate = setup_klipper_import(klipperdir)
|
shaper_calibrate = setup_klipper_import(klipperdir)
|
||||||
|
|
||||||
# Parse data
|
# Parse data from the log files while ignoring CSV in the wrong format
|
||||||
datas = [parse_log(fn) for fn in lognames]
|
datas = [data for data in (parse_log(fn) for fn in lognames) if data is not None]
|
||||||
if len(datas) > 1:
|
if len(datas) > 1:
|
||||||
print_with_c_locale('Warning: incorrect number of .csv files detected. Only the first one will be used!')
|
print_with_c_locale('Warning: incorrect number of .csv files detected. Only the first one will be used!')
|
||||||
|
|
||||||
|
|||||||
@@ -651,6 +651,8 @@ def vibrations_profile(
|
|||||||
|
|
||||||
for logname in lognames:
|
for logname in lognames:
|
||||||
data = parse_log(logname)
|
data = parse_log(logname)
|
||||||
|
if data is None:
|
||||||
|
continue # File is not in the expected format, skip it
|
||||||
angle, speed = extract_angle_and_speed(logname)
|
angle, speed = extract_angle_and_speed(logname)
|
||||||
freq_response = calc_freq_response(data)
|
freq_response = calc_freq_response(data)
|
||||||
first_freqs = freq_response.freq_bins
|
first_freqs = freq_response.freq_bins
|
||||||
|
|||||||
@@ -15,19 +15,47 @@ from scipy.signal import spectrogram
|
|||||||
|
|
||||||
|
|
||||||
def parse_log(logname):
|
def parse_log(logname):
|
||||||
|
try:
|
||||||
with open(logname) as f:
|
with open(logname) as f:
|
||||||
for header in f:
|
header = None
|
||||||
if not header.startswith('#'):
|
for line in f:
|
||||||
break
|
cleaned_line = line.strip()
|
||||||
if not header.startswith('freq,psd_x,psd_y,psd_z,psd_xyz'):
|
|
||||||
# Raw accelerometer data
|
# Check for a PSD file generated by Klipper and raise a warning
|
||||||
return np.loadtxt(logname, comments='#', delimiter=',')
|
if cleaned_line.startswith('#freq,psd_x,psd_y,psd_z,psd_xyz'):
|
||||||
# Power spectral density data or shaper calibration data
|
print(
|
||||||
raise ValueError(
|
'Warning: %s does not contain raw accelerometer data. '
|
||||||
'File %s does not contain raw accelerometer data and therefore '
|
'Please use the official Klipper script to process it instead. '
|
||||||
'is not supported by Shake&Tune. Please use the official Klipper '
|
'It will be ignored by Shake&Tune!' % (logname,)
|
||||||
'script to process it instead.' % (logname,)
|
|
||||||
)
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Check for the expected header for Shake&Tune (raw accelerometer data from Klipper)
|
||||||
|
elif cleaned_line.startswith('#time,accel_x,accel_y,accel_z'):
|
||||||
|
header = cleaned_line
|
||||||
|
break
|
||||||
|
|
||||||
|
if not header:
|
||||||
|
print(
|
||||||
|
'Warning: file %s has an incorrect header and will be ignored by Shake&Tune!\n'
|
||||||
|
"Expected '#time,accel_x,accel_y,accel_z', but got '%s'." % (logname, header.strip())
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If we have the correct raw data header, proceed to load the data
|
||||||
|
data = np.loadtxt(logname, comments='#', delimiter=',', skiprows=1)
|
||||||
|
if data.ndim == 1 or data.shape[1] != 4:
|
||||||
|
print(
|
||||||
|
'Warning: %s does not have the correct data format; expected 4 columns. '
|
||||||
|
'It will be ignored by Shake&Tune!' % (logname,)
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
except Exception as err:
|
||||||
|
print(f'Error while reading {logname}: {err}. It will be ignored by Shake&Tune!')
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def setup_klipper_import(kdir):
|
def setup_klipper_import(kdir):
|
||||||
|
|||||||
Reference in New Issue
Block a user