From 619f27e8be85cac8948f5552c2f6e3218fcf9693 Mon Sep 17 00:00:00 2001 From: tarbaig <22072152+tarbaig@users.noreply.github.com> Date: Wed, 29 May 2024 11:32:59 +0200 Subject: [PATCH] jupyter: added neccessary changes to work with Bokeh 3.x (#278) And fixed minor errors due to import paths in scipy --------- Co-authored-by: Tariq Baig-Meininghaus --- app/testing_notebook.ipynb | 95 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 61 deletions(-) diff --git a/app/testing_notebook.ipynb b/app/testing_notebook.ipynb index 82ae1cdb6..0911814f1 100644 --- a/app/testing_notebook.ipynb +++ b/app/testing_notebook.ipynb @@ -6,7 +6,6 @@ "metadata": {}, "outputs": [], "source": [ - "# setup\n", "from bokeh.plotting import figure, show, output_notebook\n", "from bokeh.models import (\n", " ColumnDataSource, Range1d, DataRange1d, DatetimeAxis,\n", @@ -51,18 +50,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "use_downsample = True # you may want to activate this for large logs (But you will not see all samples when zooming in)" @@ -71,9 +66,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# load a dataset to inspect the field names and types\n", @@ -85,9 +78,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "plot = plot_map(ulog, plot_config) # gps map\n", @@ -97,9 +88,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# plot raw acceleration sensor data\n", @@ -113,9 +102,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# a more complex plot with multiple datasets\n", @@ -135,18 +122,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# plot low-pass filtered raw acceleration sensor data\n", @@ -160,7 +143,7 @@ "B, A = butter(order, cutoff / (fs / 2), btype='low') # Butterworth low-pass\n", "filtered_signal = lfilter(B, A, cur_data['accelerometer_m_s2[0]'])\n", "\n", - "p = figure(plot_width = 800, active_scroll='wheel_zoom')\n", + "p = figure(width = 800, active_scroll='wheel_zoom')\n", "p.line(t, cur_data['accelerometer_m_s2[0]'], color='red', alpha = 0.5)\n", "p.line(t, filtered_signal, color='blue', alpha = 0.8)\n", "show(p)" @@ -169,9 +152,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] }, @@ -196,10 +177,10 @@ "outputs": [], "source": [ "# and plot it\n", - "p = figure(plot_width = 800, active_scroll='wheel_zoom')\n", - "p.line(t, ax, color='red', alpha = 0.8, legend=\"accel x\")\n", - "p.line(t, ay, color='green', alpha = 0.8, legend=\"accel y\")\n", - "p.line(t, az, color='blue', alpha = 0.8, legend=\"accel z\")\n", + "p = figure(width = 800, active_scroll='wheel_zoom')\n", + "p.line(t, ax, color='red', alpha = 0.8, legend_label=\"accel x\")\n", + "p.line(t, ay, color='green', alpha = 0.8, legend_label=\"accel y\")\n", + "p.line(t, az, color='blue', alpha = 0.8, legend_label=\"accel z\")\n", "show(p)" ] }, @@ -226,10 +207,10 @@ "outputs": [], "source": [ "# and plot it\n", - "p = figure(plot_width = 800, active_scroll='wheel_zoom')\n", - "p.line(tw, axw, color='red', alpha = 0.8, legend=\"accel x\")\n", - "p.line(tw, ayw, color='green', alpha = 0.8, legend=\"accel y\")\n", - "p.line(tw, azw, color='blue', alpha = 0.8, legend=\"accel z\")\n", + "p = figure(width = 800, active_scroll='wheel_zoom')\n", + "p.line(tw, axw, color='red', alpha = 0.8, legend_label=\"accel x\")\n", + "p.line(tw, ayw, color='green', alpha = 0.8, legend_label=\"accel y\")\n", + "p.line(tw, azw, color='blue', alpha = 0.8, legend_label=\"accel z\")\n", "show(p)" ] }, @@ -242,18 +223,18 @@ "# FFT frequency plot\n", "import scipy\n", "import scipy.fftpack\n", - "from scipy import pi\n", + "from math import pi\n", "\n", - "FFT_x = abs(scipy.fft(axw))\n", - "FFT_y = abs(scipy.fft(ayw))\n", - "FFT_z = abs(scipy.fft(azw))\n", + "FFT_x = abs(scipy.fft.fft(axw))\n", + "FFT_y = abs(scipy.fft.fft(ayw))\n", + "FFT_z = abs(scipy.fft.fft(azw))\n", "\n", "freqs = scipy.fftpack.fftfreq(len(axw), dt)\n", "\n", - "p = figure(plot_width = 800, active_scroll='wheel_zoom')\n", - "p.line(freqs,20*scipy.log10(FFT_x), color='red', alpha = 0.8, legend=\"x\")\n", - "p.line(freqs,20*scipy.log10(FFT_y), color='green', alpha = 0.8, legend=\"y\")\n", - "p.line(freqs,20*scipy.log10(FFT_z), color='blue', alpha = 0.8, legend=\"z\")\n", + "p = figure(width = 800, active_scroll='wheel_zoom')\n", + "p.line(freqs,20*np.log10(FFT_x), color='red', alpha = 0.8, legend_label=\"x\")\n", + "p.line(freqs,20*np.log10(FFT_y), color='green', alpha = 0.8, legend_label=\"y\")\n", + "p.line(freqs,20*np.log10(FFT_z), color='blue', alpha = 0.8, legend_label=\"z\")\n", "p.legend.click_policy=\"hide\"\n", "show(p)" ] @@ -268,9 +249,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "window = 'hann'\n", @@ -305,9 +284,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def plot_spec(t, f, psd, legend):\n", @@ -315,7 +292,7 @@ "\n", " im = [10 * np.log10(psd)]\n", " p = figure(title='Acceleration Power Spectral Density ' + legend + ' [dB]',\n", - " plot_width=800,x_range=(t[0], t[-1]),y_range=(f[0], f[-1]),\n", + " width=800,x_range=(t[0], t[-1]),y_range=(f[0], f[-1]),\n", " x_axis_label='Time',y_axis_label='[Hz]',toolbar_location='above')\n", " p.image(image=im, x=t[0], y=f[0],dw=(t[-1]-t[0]), dh=(f[-1]-f[0]),color_mapper=color_mapper)\n", " color_bar = ColorBar(color_mapper=color_mapper,\n", @@ -331,9 +308,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "show(plot_spec(t,f,sum_psd,'X Y Z'))" @@ -342,16 +317,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -365,9 +338,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.10.12" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 }