Skip to content

Commit

Permalink
jupyter: added neccessary changes to work with Bokeh 3.x (#278)
Browse files Browse the repository at this point in the history
And fixed minor errors due to import paths in scipy

---------

Co-authored-by: Tariq Baig-Meininghaus <[email protected]>
  • Loading branch information
tarbaig and Tariq Baig-Meininghaus authored May 29, 2024
1 parent e971ff7 commit 619f27e
Showing 1 changed file with 34 additions and 61 deletions.
95 changes: 34 additions & 61 deletions app/testing_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -97,9 +88,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# plot raw acceleration sensor data\n",
Expand All @@ -113,9 +102,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# a more complex plot with multiple datasets\n",
Expand All @@ -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",
Expand All @@ -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)"
Expand All @@ -169,9 +152,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
},
Expand All @@ -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)"
]
},
Expand All @@ -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)"
]
},
Expand All @@ -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)"
]
Expand All @@ -268,9 +249,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"window = 'hann'\n",
Expand Down Expand Up @@ -305,17 +284,15 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def plot_spec(t, f, psd, legend):\n",
" color_mapper = LinearColorMapper(palette=viridis(256),low=-80, high=0)\n",
"\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",
Expand All @@ -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'))"
Expand All @@ -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"
},
Expand All @@ -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
}

0 comments on commit 619f27e

Please sign in to comment.