summaryrefslogtreecommitdiff
path: root/lab-windows/grid_scope.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'lab-windows/grid_scope.ipynb')
-rw-r--r--lab-windows/grid_scope.ipynb236
1 files changed, 131 insertions, 105 deletions
diff --git a/lab-windows/grid_scope.ipynb b/lab-windows/grid_scope.ipynb
index f3e9176..1ddde37 100644
--- a/lab-windows/grid_scope.ipynb
+++ b/lab-windows/grid_scope.ipynb
@@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
- "db = sqlite3.connect('data/waveform-raspi.sqlite3')"
+ "db = sqlite3.connect('data/waveform-raspi-2-2.sqlite3')"
]
},
{
@@ -48,7 +48,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Run 000: 2020-01-31 19:05:24 - 2020-02-01 01:13:45 ( 6:08:21.589, 22126080sp)\n"
+ "Run 000: 2020-03-25 16:07:36 - 2020-03-26 00:15:13 ( 8:07:37.266, 29261120sp)\n"
]
}
],
@@ -100,12 +100,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "0b088957d9a24a74ab1b81d68099aa99",
+ "model_id": "582c4360e293466e9baed5bc66a47883",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
- "HBox(children=(FloatProgress(value=0.0, max=691440.0), HTML(value='')))"
+ "HBox(children=(FloatProgress(value=0.0, max=914410.0), HTML(value='')))"
]
},
"metadata": {},
@@ -133,7 +133,7 @@
" 'SELECT seq, data FROM measurements WHERE run_id = ? ORDER BY rx_ts LIMIT ? OFFSET ?',\n",
" (last_run, limit, n_records-limit))), total=n_records):\n",
" \n",
- " if last_seq is None or seq == (last_seq + 1)%0xffff:\n",
+ " if last_seq is None or seq == (last_seq + 1)%0x10000:\n",
" last_seq = seq\n",
" idx = write_index if skip_dropped_sections else i\n",
" data[idx*record_size:(idx+1)*record_size] = np.frombuffer(chunk, dtype='<H')\n",
@@ -156,7 +156,7 @@
{
"data": {
"text/plain": [
- "227.68691180713367"
+ "227.0922848236977"
]
},
"execution_count": 7,
@@ -177,7 +177,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "8a6f7e9ac8f04d1b84035c29623cfa99",
+ "model_id": "ecf3e3e261c54d87b169c1eb391a67f9",
"version_major": 2,
"version_minor": 0
},
@@ -266,7 +266,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "a3824e732a0647d4a12e8c5a567f5dc0",
+ "model_id": "cc101709475d440ea77e68bcb56ce3b7",
"version_major": 2,
"version_minor": 0
},
@@ -299,12 +299,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "342f89b5d55f435ab132deb5d051c926",
+ "model_id": "b0202d59643548cf83b6fa6fd7580d2d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
- "HBox(children=(FloatProgress(value=0.0, max=221260.0), HTML(value='')))"
+ "HBox(children=(FloatProgress(value=0.0, max=292611.0), HTML(value='')))"
]
},
"metadata": {},
@@ -364,7 +364,7 @@
" #print(coeff)\n",
" A, mu, sigma, *_ = coeff\n",
" f_mean[le_t] = mu\n",
- " except Exception:\n",
+ " except Exception as e:\n",
" f_mean[le_t] = np.nan"
]
},
@@ -376,7 +376,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "33431729d479469cb89bcf86e22508ad",
+ "model_id": "59d50a2876634433bdfb751a7a66d9ca",
"version_major": 2,
"version_minor": 0
},
@@ -420,6 +420,8 @@
"for i in np.where(np.isnan(f_mean))[0]:\n",
" ax.axvspan(f_t[i], f_t[i+1], color='lightblue')\n",
"\n",
+ "formatter = matplotlib.ticker.FuncFormatter(lambda s, x: str(datetime.timedelta(seconds=s)))\n",
+ "ax.xaxis.set_major_formatter(formatter)\n",
"ax.set_xlabel('recording time t [s]')\n",
"None"
]
@@ -432,7 +434,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "e8a4ecab028f4fcf8d9821dd66a42027",
+ "model_id": "95cfea97c3b946ed9cdf351b16c2c45e",
"version_major": 2,
"version_minor": 0
},
@@ -529,13 +531,21 @@
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": 53,
"metadata": {},
"outputs": [
{
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "<ipython-input-53-c54c3e4ac2be>:20: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
+ " fig, ax = plt.subplots(figsize=(5, 2))\n"
+ ]
+ },
+ {
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "bcf4b384d95949c38a4754cdb47ae512",
+ "model_id": "ad5454f664734681adb8640f480ce69a",
"version_major": 2,
"version_minor": 0
},
@@ -547,63 +557,54 @@
"output_type": "display_data"
},
{
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/home/user/safety-reset/lab-windows/env/lib/python3.8/site-packages/numpy/core/_asarray.py:85: ComplexWarning: Casting complex values to real discards the imaginary part\n",
- " return array(a, dtype, copy=False, order=order)\n"
- ]
- },
- {
"data": {
"text/plain": [
- "5.0"
+ "Text(20, 1, '50 Hz')"
]
},
- "execution_count": 16,
+ "execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "data = f_copy\n",
- "ys = scipy.fftpack.fft(data)\n",
- "ys = scipy.fftpack.fftshift(ys)\n",
- "#ys = 2.0/len(data) * np.abs(ys[:len(data)//2])\n",
- "#s = 3\n",
- "\n",
- "#ys = np.convolve(ys, np.ones((s,))/s, mode='valid')\n",
- "\n",
- "#xs = np.linspace(0, 5, len(data)//2)\n",
- "xs = np.linspace(-5, 5, len(data))\n",
+ "# Number of samplepoints\n",
+ "N = len(data)\n",
+ "# sample spacing\n",
+ "T = 1.0 / sampling_rate\n",
+ "x = np.linspace(0.0, N*T, N)\n",
+ "yf = scipy.fftpack.fft(data * sig.blackman(N))\n",
+ "xf = np.linspace(0.0, 1.0/(2.0*T), N//2)\n",
"\n",
- "#ys *= 2*np.pi*xs[s//2:-s//2+1]\n",
- "#ys *= xs\n",
+ "yf = 2.0/N * np.abs(yf[:N//2])\n",
"\n",
- "#xs = np.linspace(len(data)/2, 1, len(data)/2)\n",
+ "average_from = lambda val, start, average_width: np.hstack([val[:start], [ np.mean(val[i:i+average_width]) for i in range(start, len(val), average_width) ]])\n",
"\n",
- "fig, ax = plt.subplots(figsize=(9,5))\n",
- "#ax.loglog(xs[s//2:-s//2+1], ys)\n",
- "#ax.loglog(xs[s//2:-s//2+1], ys)\n",
- "#ax.loglog(xs, ys)\n",
- "#ys[len(xs)//2] = 0\n",
- "#ax.set_yscale('log')\n",
- "ax.plot(xs, ys)\n",
- "#ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, _pos: f'{1/x:.1f}'))\n",
- "ax.grid()\n",
- "#plt.show()\n",
- "xs[-1]"
+ "average_width = 6\n",
+ "average_start = 20\n",
+ "yf = average_from(yf, average_start, average_width)\n",
+ "xf = average_from(xf, average_start, average_width)\n",
+ "yf = average_from(yf, 200, average_width)\n",
+ "xf = average_from(xf, 200, average_width)"
]
},
{
"cell_type": "code",
- "execution_count": 17,
+ "execution_count": 68,
"metadata": {},
"outputs": [
{
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "<ipython-input-68-21b49a5af249>:1: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
+ " fig, ax = plt.subplots(figsize=(6, 3))\n"
+ ]
+ },
+ {
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "cbc03380a4234b4d8160d25e867ff5a9",
+ "model_id": "4a3edb0925fe47eb8751150aa7da8c22",
"version_major": 2,
"version_minor": 0
},
@@ -615,54 +616,51 @@
"output_type": "display_data"
},
{
- "data": {
- "text/plain": [
- "(1.6666666666666667e-05, 0.5)"
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.\n"
+ ]
}
],
"source": [
- "# Number of samplepoints\n",
- "N = len(data)\n",
- "# sample spacing\n",
- "T = 1.0 / 10.0\n",
- "x = np.linspace(0.0, N*T, N)\n",
- "yf = scipy.fftpack.fft(data)\n",
- "xf = np.linspace(0.0, 1.0/(2.0*T), N//2)\n",
- "\n",
- "yf = 2.0/N * np.abs(yf[:N//2])\n",
- "\n",
- "average_from = lambda val, start, average_width: np.hstack([val[:start], [ np.mean(val[i:i+average_width]) for i in range(start, len(val), average_width) ]])\n",
- "\n",
- "average_width = 6\n",
- "average_start = 20\n",
- "yf = average_from(yf, average_start, average_width)\n",
- "xf = average_from(xf, average_start, average_width)\n",
- "yf = average_from(yf, 200, average_width)\n",
- "xf = average_from(xf, 200, average_width)\n",
- "\n",
- "fig, ax = plt.subplots()\n",
+ "fig, ax = plt.subplots(figsize=(6, 3))\n",
+ "fig.tight_layout()\n",
"ax.loglog(xf, yf)\n",
- "ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, _pos: f'{1/x:.1f}'))\n",
- "ax.set_xlabel('T in s')\n",
- "ax.set_ylabel('Amplitude Δf')\n",
+ "#ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, _pos: f'{1/x:.1f}'))\n",
+ "ax.set_xlabel('f [Hz]')\n",
+ "ax.set_ylabel('Amplitude V [V]')\n",
"ax.grid()\n",
- "ax.set_xlim([1/60000, 0.5])"
+ "ax.set_xlim([0.1, 500])\n",
+ "fig.subplots_adjust(bottom=0.2)\n",
+ "\n",
+ "for le_f in (50, 150, 250, 350, 450):\n",
+ " ax.axvline(le_f, color=(1, 0.5, 0.5), zorder=-2)\n",
+ "ax.annotate('50 Hz', xy=(20, 1), xycoords='data', bbox=dict(fc='white', alpha=0.8, ec='none'))\n",
+ "font = {'family' : 'normal',\n",
+ " 'weight' : 'normal',\n",
+ " 'size' : 10}\n",
+ "matplotlib.rc('font', **font)\n",
+ "fig.savefig('fig_out/mains_voltage_spectrum.eps')"
]
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": 43,
"metadata": {},
"outputs": [
{
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "<ipython-input-43-2e31f0cb9460>:21: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n",
+ " fig, ax = plt.subplots()\n"
+ ]
+ },
+ {
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "8eb3621b74c04c4fb7dd3e919f0d1fed",
+ "model_id": "37e159955f114f36824dd42da060b9ea",
"version_major": 2,
"version_minor": 0
},
@@ -676,55 +674,83 @@
{
"data": {
"text/plain": [
- "(5e-07, 0.02)"
+ "[<matplotlib.lines.Line2D at 0x7fafc108cdc0>]"
]
},
- "execution_count": 18,
+ "execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Number of samplepoints\n",
- "N = len(data)\n",
+ "newcopy = np.copy(f_mean[1:-2])\n",
+ "N = len(newcopy)\n",
"# sample spacing\n",
- "T = 1.0 / 10.0\n",
+ "T = 1.0 / 10\n",
"x = np.linspace(0.0, N*T, N)\n",
- "yf = scipy.fftpack.fft(data)\n",
- "xf = np.linspace(0.0, 1.0/(2.0*T), N//2)\n",
+ "yf = scipy.fftpack.fft(newcopy * sig.blackman(N))\n",
+ "xf = np.linspace(0.0, 10/2, N//2)\n",
"\n",
"yf = 2.0/N * np.abs(yf[:N//2])\n",
"\n",
"average_from = lambda val, start, average_width: np.hstack([val[:start], [ np.mean(val[i:i+average_width]) for i in range(start, len(val), average_width) ]])\n",
"\n",
- "average_width = 6\n",
- "average_start = 20\n",
- "yf = average_from(yf, average_start, average_width)\n",
- "xf = average_from(xf, average_start, average_width)\n",
- "yf = average_from(yf, 70, 4)\n",
- "xf = average_from(xf, 70, 4)\n",
+ "average_width1, average_start1 = 3, 40\n",
+ "average_width2, average_start2 = 4, 100\n",
+ "yf = average_from(yf, average_start1, average_width1)\n",
+ "xf = average_from(xf, average_start1, average_width1)\n",
+ "yf = average_from(yf, average_start2, average_width2)\n",
+ "xf = average_from(xf, average_start2, average_width2)\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.loglog(xf, yf)\n",
"ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, _pos: f'{1/x:.1f}'))\n",
- "ax.set_xlabel('T in s')\n",
- "ax.set_ylabel('Amplitude Δf')\n",
+ "ax.set_xlabel('T [s]')\n",
+ "ax.set_ylabel('Amplitude Δf [Hz]')\n",
"\n",
- "for i, t in enumerate([45, 60, 600, 1200, 1800, 3600]):\n",
+ "for i, t in enumerate([60, 300, 450, 1200, 1800]):\n",
" ax.axvline(1/t, color='red', alpha=0.5)\n",
" ax.annotate(f'{t} s', xy=(1/t, 3e-5), xytext=(-15, 0), xycoords='data', textcoords='offset pixels', rotation=90)\n",
"#ax.text(1/60, 10,'60 s', ha='left')\n",
"ax.grid()\n",
- "ax.set_xlim([1/60000, 0.5])\n",
- "ax.set_ylim([5e-7, 2e-2])"
+ "#ax.set_xlim([1/60000, 0.5])\n",
+ "ax.set_ylim([5e-7, 2e-2])\n",
+ "ax.plot(xf[1:], 2e-6/xf[1:])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "671ae919bf124e72b54144310ea1602d",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "fig, ax = plt.subplots()\n",
+ "ax.plot(np.linspace(0, (len(f_mean)-3)/10, len(f_mean)-3) , f_mean[1:-2])\n",
+ "ax.grid()"
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "winlabenv",
+ "display_name": "labenv",
"language": "python",
- "name": "winlabenv"
+ "name": "labenv"
},
"language_info": {
"codemirror_mode": {
@@ -736,7 +762,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.6"
+ "version": "3.8.2"
}
},
"nbformat": 4,