In [11]:
import platform
import datetime as datetime
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from utils import query, mask_print_session, load_cached_json

if not platform.python_version().startswith('3'):
    raise Exception('Please execute with Python 3.x')

%pylab inline


Populating the interactive namespace from numpy and matplotlib

Collecting Data

Data is queried from OpenTSDB, which is hosed on http://il075:9999 (only reachable within the SRFG network).
Documentation about the REST query can be found on http://opentsdb.net/docs/build/html/api_http/query/index.html.

Measurements

SensorID Unit Description
fila.distance mm mength of filament
file.skidrate 1/m skids per meter
fila.skidcount 1 absolute number of skids
temp temperature of sorounding
temp.bed.current temperature of bottom plateau
temp.nozzle.currentC° temperature of nozzle
airquality VOC quality of air http://www.velux.de/produkte/lueftungsloesungen-belueftung/raumluftfuehler
head.pos.z mm z-coordinate of printerhead
extrusion mm3 volume of used filament

In [12]:
# df = query(host='http://il075:9999/api/query',
#            start=datetime.date(year=2016, month=12, day=23),
#            end=datetime.date(year=2016, month=12, day=24),
#            metric=['avg:fila.distance',
#                    'avg:fila.skidrate',
#                    'avg:fila.skidcount',
#                    'avg:temp',
#                    'avg:temp.bed.current',
#                    'avg:temp.nozzle.current',
#                    'avg:airquality',
#                    'avg:head.pos.z',
#                    'avg:extrusion'])

df = load_cached_json()

df.head()


Out[12]:
fila.distance fila.skidrate fila.skidcount temp temp.bed.current temp.nozzle.current airquality head.pos.z extrusion
2016-12-23 09:55:34 3.2 NaN NaN 27.346001 NaN NaN NaN NaN NaN
2016-12-23 09:55:35 8.0 NaN NaN NaN NaN NaN NaN NaN NaN
2016-12-23 09:55:36 12.8 10.0 NaN NaN NaN NaN NaN NaN NaN
2016-12-23 09:55:37 16.0 NaN NaN NaN NaN NaN NaN NaN NaN
2016-12-23 09:55:38 17.6 NaN NaN NaN NaN NaN 666.0 NaN NaN

In [13]:
ax = df.plot(figsize=(12, 8))
ax.set_xlabel("23 December 2016")
ax.set_ylabel("*")
plt.show()



In [14]:
from pandas.tools.plotting import scatter_matrix

ax = scatter_matrix(df, alpha=0.2, figsize=(24, 24), diagonal='kde')
plt.savefig('./scatter_plot.png')
plt.show()


Mask Sessions

In the following mask for each print are being generated.


In [15]:
# create session mask and ids
fila_distance = df['fila.distance']
fila_run_id = mask_print_session(fila_distance)

# plot print sessions ids
diff_data = fila_distance.to_frame()
diff_data['fila.run.id'] = fila_run_id * 100 # make it visible in plot
ax = diff_data.plot(figsize=(12, 8), ylim=[-10, 1200], style=['o','rx'], markersize=1,
#                xlim=[datetime.datetime(year=2016, month=12, day=23, hour=9, minute=55), 
#                      datetime.datetime(year=2016, month=12, day=23, hour=10, minute=55)]
              )
ax.set_xlabel("23 December 2016")
ax.set_ylabel("Distance in mm")
plt.title('Masked Printing Session')
plt.show()

# add to main dataframe
df['fila.run.id'] = fila_run_id


Compute Mean Temperature

The mean temperature of the nozzle is computed for each print and added to the main dataframe.


In [16]:
temp_mean = np.nan * np.ones(shape=len(fila_distance))
num_prints = int(df['fila.run.id'].max())
for session_id in range(1, num_prints+1):
    temp = df['temp.nozzle.current']
    ixs = np.array(df['fila.run.id'] == session_id, dtype=bool)
    temp_mean[ixs] = temp[ixs].mean()
    print('Mean temp for print {} is {:.2f} C°'.format(session_id, temp[ixs].mean()))
    
temp_mean = pd.Series(index=fila_distance.index, data=temp_mean)

df['temp.nozzle.current'].plot(style='x', figsize=(12, 8))
ax = temp_mean.plot(style='r', figsize=(12, 8))
ax.set_xlabel("23 December 2016")
ax.set_ylabel("Temperature in C°")
plt.title('Mean Temperature for each Print')
plt.show()

# add to main dataframe
df['temp.nozzle.mean'] = temp_mean


Mean temp for print 1 is 204.94 C°
Mean temp for print 2 is 199.94 C°
Mean temp for print 3 is 205.02 C°
Mean temp for print 4 is 224.96 C°
Mean temp for print 5 is 200.01 C°
Mean temp for print 6 is 214.97 C°
Mean temp for print 7 is 210.00 C°

In [17]:
# store as csv
df.to_csv('printer_data_23_12_2016.csv', date_format='%s')