Skip to content

Commit

Permalink
Switch to uniform temperature sampling for cal.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoppert committed Feb 1, 2017
1 parent e16d996 commit 405968b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions Tools/process_sensor_caldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def fitPlot(x, y, f_poly, name, field, config):
A temperature calibration fit plot.
"""
# pylint: disable=too-many-arguments
x = x.resample(config['plot_interval']).mean()
y = y.resample(config['plot_interval']).mean()
# x = x.resample(config['plot_interval']).mean()
# y = y.resample(config['plot_interval']).mean()
plt.plot(x, y, '.', label=field)
x_resample = np.linspace(x.min(), x.max())
plt.plot(x_resample, f_poly(x_resample), '-', label='{:s} fit'.format(field))
Expand Down Expand Up @@ -121,22 +121,22 @@ def temperature_calibration(ulog_filename, do_plot):
if topic == 'sensor_baro':
config['fields'] = ['pressure']
config['ylabel'] = 'pressure, Pa'
config['offset'] = lambda y: y.median()
config['offset'] = lambda y: np.median(y)
config['poly_deg'] = 5
elif topic == 'sensor_gyro':
config['fields'] = ['x', 'y', 'z']
config['ylabel'] = 'gyro, rad/s'
elif topic == 'sensor_accel':
config['fields'] = ['x', 'y', 'z']
config['ylabel'] = 'accel, m/s^2'
config['offset'] = lambda y: y.median()
config['offset'] = lambda y: np.median(y)
else:
continue

# get data and fill in empty (NaN) values with forward fill, followed by
# backward fill
data = r[topic][multi_id].ffill().bfill()
x = data.temperature
temp = data.temperature

try:
device_id = int(np.median(r[topic][multi_id]['device_id']))
Expand All @@ -147,17 +147,30 @@ def temperature_calibration(ulog_filename, do_plot):
# default for coefficients
coeffs[topic][multi_id] = {
'poly': {},
'T_min': config['min'](x),
'T_max': config['max'](x),
'T_ref': config['ref'](x),
'T_min': config['min'](temp),
'T_max': config['max'](temp),
'T_ref': config['ref'](temp),
'device_id': device_id
}
name = '{:s}_{:d}'.format(topic, multi_id)

plt.figure()

for i, field in enumerate(config['fields']):
y = data[field]
# temperature based resampling
x = []
y = []
temp_step = 1
y_offset = config['offset'](data[field])
for temp_start in range(temp.min(), temp.max(), temp_step):
mask = np.logical_and(data.temperature > temp_start,
data.temperature < temp_start + temp_step)
x += [np.median(temp[mask])]
y += [np.median(data[field][mask]) - y_offset]
x = np.array(x)
y = np.array(y)

# y = data[field]
y -= config['offset'](y)
f_poly = Polynomial.fit(x, y, config['poly_deg'])
coeffs[topic][multi_id]['poly'][field] = list(np.array(
Expand Down

0 comments on commit 405968b

Please sign in to comment.