Skip to content

Commit 6e118cd

Browse files
committed
constrained-hmm: Start on data loading of CNC dataset
1 parent 314d2c0 commit 6e118cd

File tree

1 file changed

+354
-0
lines changed

1 file changed

+354
-0
lines changed
Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 4,
6+
"id": "1af236bd-4f3c-4aef-81f6-1232772f5586",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pandas\n",
11+
"\n",
12+
"import os.path\n"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 5,
18+
"id": "775c0672-a0c5-4e0d-90f9-061564c9ec72",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"dataset_path = './data/cnc-mill-toolwear'"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 10,
28+
"id": "140539bb-172d-40b5-b5bf-69baa3eb7f1e",
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/html": [
34+
"<div>\n",
35+
"<style scoped>\n",
36+
" .dataframe tbody tr th:only-of-type {\n",
37+
" vertical-align: middle;\n",
38+
" }\n",
39+
"\n",
40+
" .dataframe tbody tr th {\n",
41+
" vertical-align: top;\n",
42+
" }\n",
43+
"\n",
44+
" .dataframe thead th {\n",
45+
" text-align: right;\n",
46+
" }\n",
47+
"</style>\n",
48+
"<table border=\"1\" class=\"dataframe\">\n",
49+
" <thead>\n",
50+
" <tr style=\"text-align: right;\">\n",
51+
" <th></th>\n",
52+
" <th>feedrate</th>\n",
53+
" <th>clamp_pressure</th>\n",
54+
" <th>tool_condition</th>\n",
55+
" <th>machining_finalized</th>\n",
56+
" <th>passed_visual_inspection</th>\n",
57+
" </tr>\n",
58+
" <tr>\n",
59+
" <th>experiment</th>\n",
60+
" <th></th>\n",
61+
" <th></th>\n",
62+
" <th></th>\n",
63+
" <th></th>\n",
64+
" <th></th>\n",
65+
" </tr>\n",
66+
" </thead>\n",
67+
" <tbody>\n",
68+
" <tr>\n",
69+
" <th>1</th>\n",
70+
" <td>6</td>\n",
71+
" <td>4.0</td>\n",
72+
" <td>unworn</td>\n",
73+
" <td>yes</td>\n",
74+
" <td>yes</td>\n",
75+
" </tr>\n",
76+
" <tr>\n",
77+
" <th>2</th>\n",
78+
" <td>20</td>\n",
79+
" <td>4.0</td>\n",
80+
" <td>unworn</td>\n",
81+
" <td>yes</td>\n",
82+
" <td>yes</td>\n",
83+
" </tr>\n",
84+
" <tr>\n",
85+
" <th>3</th>\n",
86+
" <td>6</td>\n",
87+
" <td>3.0</td>\n",
88+
" <td>unworn</td>\n",
89+
" <td>yes</td>\n",
90+
" <td>yes</td>\n",
91+
" </tr>\n",
92+
" <tr>\n",
93+
" <th>4</th>\n",
94+
" <td>6</td>\n",
95+
" <td>2.5</td>\n",
96+
" <td>unworn</td>\n",
97+
" <td>no</td>\n",
98+
" <td>NaN</td>\n",
99+
" </tr>\n",
100+
" <tr>\n",
101+
" <th>5</th>\n",
102+
" <td>20</td>\n",
103+
" <td>3.0</td>\n",
104+
" <td>unworn</td>\n",
105+
" <td>no</td>\n",
106+
" <td>NaN</td>\n",
107+
" </tr>\n",
108+
" <tr>\n",
109+
" <th>6</th>\n",
110+
" <td>6</td>\n",
111+
" <td>4.0</td>\n",
112+
" <td>worn</td>\n",
113+
" <td>yes</td>\n",
114+
" <td>no</td>\n",
115+
" </tr>\n",
116+
" <tr>\n",
117+
" <th>7</th>\n",
118+
" <td>20</td>\n",
119+
" <td>4.0</td>\n",
120+
" <td>worn</td>\n",
121+
" <td>no</td>\n",
122+
" <td>NaN</td>\n",
123+
" </tr>\n",
124+
" <tr>\n",
125+
" <th>8</th>\n",
126+
" <td>20</td>\n",
127+
" <td>4.0</td>\n",
128+
" <td>worn</td>\n",
129+
" <td>yes</td>\n",
130+
" <td>no</td>\n",
131+
" </tr>\n",
132+
" <tr>\n",
133+
" <th>9</th>\n",
134+
" <td>15</td>\n",
135+
" <td>4.0</td>\n",
136+
" <td>worn</td>\n",
137+
" <td>yes</td>\n",
138+
" <td>no</td>\n",
139+
" </tr>\n",
140+
" <tr>\n",
141+
" <th>10</th>\n",
142+
" <td>12</td>\n",
143+
" <td>4.0</td>\n",
144+
" <td>worn</td>\n",
145+
" <td>yes</td>\n",
146+
" <td>no</td>\n",
147+
" </tr>\n",
148+
" <tr>\n",
149+
" <th>11</th>\n",
150+
" <td>3</td>\n",
151+
" <td>4.0</td>\n",
152+
" <td>unworn</td>\n",
153+
" <td>yes</td>\n",
154+
" <td>yes</td>\n",
155+
" </tr>\n",
156+
" <tr>\n",
157+
" <th>12</th>\n",
158+
" <td>3</td>\n",
159+
" <td>3.0</td>\n",
160+
" <td>unworn</td>\n",
161+
" <td>yes</td>\n",
162+
" <td>yes</td>\n",
163+
" </tr>\n",
164+
" <tr>\n",
165+
" <th>13</th>\n",
166+
" <td>3</td>\n",
167+
" <td>4.0</td>\n",
168+
" <td>worn</td>\n",
169+
" <td>yes</td>\n",
170+
" <td>yes</td>\n",
171+
" </tr>\n",
172+
" <tr>\n",
173+
" <th>14</th>\n",
174+
" <td>3</td>\n",
175+
" <td>3.0</td>\n",
176+
" <td>worn</td>\n",
177+
" <td>yes</td>\n",
178+
" <td>yes</td>\n",
179+
" </tr>\n",
180+
" <tr>\n",
181+
" <th>15</th>\n",
182+
" <td>6</td>\n",
183+
" <td>3.0</td>\n",
184+
" <td>worn</td>\n",
185+
" <td>yes</td>\n",
186+
" <td>yes</td>\n",
187+
" </tr>\n",
188+
" <tr>\n",
189+
" <th>16</th>\n",
190+
" <td>20</td>\n",
191+
" <td>3.0</td>\n",
192+
" <td>worn</td>\n",
193+
" <td>no</td>\n",
194+
" <td>NaN</td>\n",
195+
" </tr>\n",
196+
" <tr>\n",
197+
" <th>17</th>\n",
198+
" <td>3</td>\n",
199+
" <td>2.5</td>\n",
200+
" <td>unworn</td>\n",
201+
" <td>yes</td>\n",
202+
" <td>yes</td>\n",
203+
" </tr>\n",
204+
" <tr>\n",
205+
" <th>18</th>\n",
206+
" <td>3</td>\n",
207+
" <td>2.5</td>\n",
208+
" <td>worn</td>\n",
209+
" <td>yes</td>\n",
210+
" <td>yes</td>\n",
211+
" </tr>\n",
212+
" </tbody>\n",
213+
"</table>\n",
214+
"</div>"
215+
],
216+
"text/plain": [
217+
" feedrate clamp_pressure tool_condition machining_finalized \\\n",
218+
"experiment \n",
219+
"1 6 4.0 unworn yes \n",
220+
"2 20 4.0 unworn yes \n",
221+
"3 6 3.0 unworn yes \n",
222+
"4 6 2.5 unworn no \n",
223+
"5 20 3.0 unworn no \n",
224+
"6 6 4.0 worn yes \n",
225+
"7 20 4.0 worn no \n",
226+
"8 20 4.0 worn yes \n",
227+
"9 15 4.0 worn yes \n",
228+
"10 12 4.0 worn yes \n",
229+
"11 3 4.0 unworn yes \n",
230+
"12 3 3.0 unworn yes \n",
231+
"13 3 4.0 worn yes \n",
232+
"14 3 3.0 worn yes \n",
233+
"15 6 3.0 worn yes \n",
234+
"16 20 3.0 worn no \n",
235+
"17 3 2.5 unworn yes \n",
236+
"18 3 2.5 worn yes \n",
237+
"\n",
238+
" passed_visual_inspection \n",
239+
"experiment \n",
240+
"1 yes \n",
241+
"2 yes \n",
242+
"3 yes \n",
243+
"4 NaN \n",
244+
"5 NaN \n",
245+
"6 no \n",
246+
"7 NaN \n",
247+
"8 no \n",
248+
"9 no \n",
249+
"10 no \n",
250+
"11 yes \n",
251+
"12 yes \n",
252+
"13 yes \n",
253+
"14 yes \n",
254+
"15 yes \n",
255+
"16 NaN \n",
256+
"17 yes \n",
257+
"18 yes "
258+
]
259+
},
260+
"execution_count": 10,
261+
"metadata": {},
262+
"output_type": "execute_result"
263+
}
264+
],
265+
"source": [
266+
"\n",
267+
"def load_experiments(dataset_path):\n",
268+
"\n",
269+
" metadata_path = os.path.join(dataset_path, 'train.csv')\n",
270+
" df = pandas.read_csv(metadata_path)\n",
271+
"\n",
272+
" df = df.drop(columns='material') # only \"wax\", not so useful\n",
273+
" df = df.rename(columns={'No': 'experiment'})\n",
274+
" df = df.set_index('experiment')\n",
275+
" categorical_columns = ['tool_condition', 'machining_finalized', 'passed_visual_inspection']\n",
276+
" for c in categorical_columns:\n",
277+
" df[c] = df[c].astype('category')\n",
278+
"\n",
279+
" return df\n",
280+
"\n",
281+
" \n",
282+
"experiments = load_experiments(dataset_path)\n",
283+
"experiments"
284+
]
285+
},
286+
{
287+
"cell_type": "code",
288+
"execution_count": null,
289+
"id": "486aa2b0-0e36-49d4-b025-e821d43b9cf6",
290+
"metadata": {},
291+
"outputs": [],
292+
"source": [
293+
"\n",
294+
"def load_timeseries(dataset_path):\n",
295+
"\n",
296+
" \"\"\"\n",
297+
" \n",
298+
" From the dataset README.txt -- \n",
299+
" Note: Some variables will not accurately reflect the operation of the CNC machine.\n",
300+
" This can usually be detected by\n",
301+
" when M1_CURRENT_FEEDRATE reads 50,\n",
302+
" when X1 ActualPosition reads 198,\n",
303+
" or when M1_CURRENT_PROGRAM_NUMBER does not read 0.\n",
304+
" The source of these errors has not been identified.\n",
305+
" \"\"\"\n",
306+
"\n",
307+
" \n",
308+
"\n"
309+
]
310+
},
311+
{
312+
"cell_type": "code",
313+
"execution_count": 11,
314+
"id": "7e7a6c95-176b-4291-97d6-de19880b72d8",
315+
"metadata": {},
316+
"outputs": [],
317+
"source": [
318+
"# TODO: plot time-series\n",
319+
"\n",
320+
"# TODO: plot each run in X-Y\n",
321+
"# maybe support overlay a variable, like spindle power?"
322+
]
323+
},
324+
{
325+
"cell_type": "code",
326+
"execution_count": null,
327+
"id": "d524d75e-6d18-4837-92e3-3d439cb42f62",
328+
"metadata": {},
329+
"outputs": [],
330+
"source": []
331+
}
332+
],
333+
"metadata": {
334+
"kernelspec": {
335+
"display_name": "constrained-hmm",
336+
"language": "python",
337+
"name": "constrained-hmm"
338+
},
339+
"language_info": {
340+
"codemirror_mode": {
341+
"name": "ipython",
342+
"version": 3
343+
},
344+
"file_extension": ".py",
345+
"mimetype": "text/x-python",
346+
"name": "python",
347+
"nbconvert_exporter": "python",
348+
"pygments_lexer": "ipython3",
349+
"version": "3.13.3"
350+
}
351+
},
352+
"nbformat": 4,
353+
"nbformat_minor": 5
354+
}

0 commit comments

Comments
 (0)