Make detection algorithm prototype slightly easier to implement

This commit is contained in:
jaseg 2020-01-26 22:04:20 +01:00
parent f1c53460b0
commit 38bc146d95

View file

@ -1699,7 +1699,7 @@
},
{
"cell_type": "code",
"execution_count": 101,
"execution_count": 103,
"metadata": {
"scrolled": false
},
@ -2503,7 +2503,7 @@
"for ax, capture in zip(axs.flatten(), [data_downstairs[0] + data_downstairs[1], data_upstairs]):\n",
" cap = np.array(capture)\n",
" cap -= np.mean(cap).astype(int)\n",
" lens = np.array([ len(g) for g in (list(g) for g_key, g in itertools.groupby(cap, lambda x: 1 if x >= 0 else -1)) for _x in g ])\n",
" lens = np.array([ x for g in (list(g) for g_key, g in itertools.groupby(cap, lambda x: 1 if x >= 0 else -1)) for x in range(len(g)) ])\n",
" w = 32\n",
" k = 8\n",
" lens = np.array(list(sum(xs) for xs in zip(*(lens[i::k] for i in range(w))))) / w\n",
@ -2518,10 +2518,10 @@
" for idx, data in enumerate(zip(*(both_data[i*p:] for i in range(q)))):\n",
" h_len, h_rms = zip(*data)\n",
" if all(x > 1500 for x in h_rms):\n",
" if all(1.0 < x < 1.5 for x in h_len[::2]) and \\\n",
" all(1.3 < x < 1.8 for x in h_len[1::2]):\n",
" if all(0.1 < x < 0.25 for x in h_len[::2]) and \\\n",
" all(0.25 < x < 0.4 for x in h_len[1::2]):\n",
" ax.axvspan(idx, idx + p*q, color='lightgreen')\n",
" elif all(1.4 < x < 1.8 for x in h_len):\n",
" elif all(0.25 < x < 0.4 for x in h_len):\n",
" ax.axvspan(idx, idx + p*q, color='pink')"
]
}