diff --git a/applications/data_visualisation/bokeh/bokeh-server-example.py b/applications/data_visualisation/bokeh/bokeh-server-example.py index 2116ee4de7a7ca33372cd7af626cbb2d5008e513..b92deb7ab9581b780416aa0ddfa501c20c192d33 100644 --- a/applications/data_visualisation/bokeh/bokeh-server-example.py +++ b/applications/data_visualisation/bokeh/bokeh-server-example.py @@ -33,10 +33,10 @@ def callback(): out = run(f'bet {fname} {bet_name}'.split()) print(out) - d = nb.load(bet_name).get_fdata() - d0 = d[:, :, d.shape[2] // 2].squeeze() + dbet = nb.load(bet_name).get_fdata() + d0bet = dbet[:, :, dbet.shape[2] // 2].squeeze() - p.image(image=[d0.T], x=0, y=0, dw=100, dh=100, palette="Greys256", level="image") + p.image(image=[d0bet.T], x=0, y=0, dw=100, dh=100, palette="Greys256", level="image") # add a button widget and configure with the call back diff --git a/applications/data_visualisation/bokeh/bokeh.ipynb b/applications/data_visualisation/bokeh/bokeh.ipynb index b691661a0be77c4d7e4978db010cdbbd5dce6e88..8b371e5d54711de158e492deccc5c7dd962a98ee 100644 --- a/applications/data_visualisation/bokeh/bokeh.ipynb +++ b/applications/data_visualisation/bokeh/bokeh.ipynb @@ -14,11 +14,7 @@ "\n", "## Install `bokeh`\n", "\n", - "`bokeh` is not installed in the `fslpython` environment so you will need to install it to run this notebook. In a terminal run the following command (you will need admin privileges):\n", - "\n", - "```\n", - "sudo $FSLDIR/fslpython/bin/conda install -c conda-forge -n fslpython bokeh\n", - "```\n", + "`bokeh` is not installed in the `fslpython` environment so you will need to install it to run this notebook (e.g. `pip install bokeh`)\n", "\n", "Setup bokeh to work in this notebook:" ] @@ -467,11 +463,18 @@ "\n", "show(layout)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -485,7 +488,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.8.11" } }, "nbformat": 4, diff --git a/applications/data_visualisation/fsleyes_render.md b/applications/data_visualisation/fsleyes_render.md index 6a8ce5362d2813308cdc91d6d094c32b522254d6..e8787558c1aed3f44fd1a9ca9ad04806dbf7d007 100644 --- a/applications/data_visualisation/fsleyes_render.md +++ b/applications/data_visualisation/fsleyes_render.md @@ -76,7 +76,7 @@ fsleyes --scene ortho --hideLabels --layout horizontal --hidex --hidey --hideCur ### Rendering -Instead of opening FSLeyes, wee want to create an image (a PNG for example) to use in a presentation. This can be done very simply by using the above command and adding a render flag to fsleyes: +Instead of opening FSLeyes, we want to create an image (a PNG for example) to use in a presentation. This can be done very simply by using the above command and adding a render flag to fsleyes: ``` fsleyes render -outputfile my_image.png <rest of the command> @@ -93,7 +93,7 @@ Here we will create a movie of the MNI brain scrolling through z-slices. We'll a <img src="data/snapshot3.gif" alt="snapshot3" style="width:400px;"/> -First, make sure that you have ImageMagick installed. To do that, go to your terminal and run thee command `convert`. If you get a long help for the convert command you are good to go. Otherwise install ImageMagick from [here](https://imagemagick.org/script/download.php). +First, make sure that you have ImageMagick installed. To do that, go to your terminal and run the command `convert`. If you get a long help for the convert command you are good to go. Otherwise install ImageMagick from [here](https://imagemagick.org/script/download.php). We will re-use the previous render command. Start by copying that into a text editor. You can use the code below: @@ -166,7 +166,7 @@ convert -delay 5 my_folder/image_annot_???.png -loop 0 my_annotated_movie.gif ### Rotating head through the GUI -You can of course also create an animateed GIF directly through the GUI without the FOR look in bash and ImageMagick. Here is an example of how to create a rotating head: +You can of course also create an animated GIF directly through the GUI without the FOR loop in bash and ImageMagick. Here is an example of how to create a rotating head: Open FSLeyes with a standard brain in 3D mode: @@ -196,7 +196,7 @@ Open a new session of FSLeyes with a 2mm standard brain, this time directly in 3 fsleyes -std --scene 3d & ``` -Ok I now that looks a little scary. Let's make the following changes. Open the overlay display panel (Settings->3D View 1->Overlay display panel) and: +Ok I know that looks a little scary. Let's make the following changes. Open the overlay display panel (Settings->3D View 1->Overlay display panel) and: - Change the colourmap to Yellow - Change the display range to min=1000, max=5000 @@ -205,7 +205,7 @@ Ok I now that looks a little scary. Let's make the following changes. Open the o Copy the command line that creates this scene as we have done before (Settings->3D View 1->Show command line for scence). -Now we are going to create a FOR loop where we will change the angles of the clipping planes and save each angle in a separate PNG files. We will then combine them into a single GIF. In the code below, you can find the FOR loop, all that is missing is the command line fsleyes that you have copied to the clipboard: +Now we are going to create a FOR loop where we will change the angles of the clipping planes and save each angle in a separate PNG file. We will then combine them into a single GIF. In the code below, you can find the FOR loop, all that is missing is the FSLeyes command line that you have copied to the clipboard: ```bash outputfolder=my_pacman @@ -249,7 +249,7 @@ Do the following: - Change the colourmap of the MNI brain to "Bone" - Change its min/max display range to 5000-10000 - Change the colourmap of the tracts to "Red-Yellow" -- Change the display type of both from "3d/4D volume" to "Maximum intensity projection" +- Change the display type of both MNI and tracts from "3d/4D volume" to "Maximum intensity projection" - Change the MNI brain to have "Spline interpolation" - Select volume number 14 for the tracts - Use the spanner to add a colourbar on the left with size 30 diff --git a/applications/data_visualisation/matplotlib.ipynb b/applications/data_visualisation/matplotlib.ipynb index b13b5413309d58026b4dfeae5e7293b530a8bc08..1092f9bcf346f743c08a66a6d2d7f21577920cfa 100644 --- a/applications/data_visualisation/matplotlib.ipynb +++ b/applications/data_visualisation/matplotlib.ipynb @@ -826,7 +826,25 @@ ] } ], - "metadata": {}, + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.11" + } + }, "nbformat": 4, "nbformat_minor": 5 } diff --git a/applications/data_visualisation/nilearn.ipynb b/applications/data_visualisation/nilearn.ipynb index 222d3b45d086d7ae88d9b76d89fefcfd6d5f5b08..1ee354dc091e3b8f2ab92eefd1da0f54fce0c1f1 100644 --- a/applications/data_visualisation/nilearn.ipynb +++ b/applications/data_visualisation/nilearn.ipynb @@ -27,11 +27,7 @@ "3. 2D maximum intensity projection\n", "4. Surfaces\n", "\n", - "`nilearn` is not installed in the `fslpython` environment so you will need to install it to run this notebook. In a terminal run the following command (you will need admin privileges):\n", - "\n", - "```\n", - "sudo $FSLDIR/fslpython/bin/conda install -c conda-forge -n fslpython nilearn\n", - "```" + "`nilearn` is not installed in the `fslpython` environment so you will need to install it to run this notebook (e.g. `pip install nilearn`)" ] }, { @@ -67,7 +63,7 @@ "source": [ "## Plotting an anatomical image\n", "\n", - "In this section we will use `nilearn` to plot an anatomical volume. For these examples we will use the 1mm MNI152 T1w that is shipped with `FSL`. In these examples you will see differnet plotting layouts, as well as different styling options.\n", + "In this section we will use `nilearn` to plot an anatomical volume. For these examples we will use the 1mm MNI152 T1w that is shipped with `FSL`. In these examples you will see different plotting layouts, as well as different styling options.\n", "\n", "First we will use the `plot_anat` function (with default values) to plot the MNI152 T1w in an **ortho** view.\n", "\n", @@ -511,7 +507,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -525,7 +521,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.8.11" } }, "nbformat": 4, diff --git a/applications/data_visualisation/plotly.ipynb b/applications/data_visualisation/plotly.ipynb index b4e7a27120b8b39179eae57c00cef4a1a74b30a2..f6a22cf3f2e19a7923d6da248814f4e3d9d0f34a 100644 --- a/applications/data_visualisation/plotly.ipynb +++ b/applications/data_visualisation/plotly.ipynb @@ -4,25 +4,24 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# `plotly.py`\n", + "## PLOTLY\n", "\n", - "[`plotly.py`](https://plotly.com/python/) a python interface to the `plotly` javascript library which is an open-source graphing library which specialises in high-quality web-based interactive graphs. `plotly.py` allows you to create these interactive web-based plots without having to code in javascript.\n", + "[`plotly.py`](https://plotly.com/python/) is a python interface to the `plotly` javascript library which is an open-source graphing library which specialises in high-quality web-based interactive graphs. `plotly.py` allows you to create these interactive web-based plots without having to code in javascript.\n", "\n", "`plotly.py` has excellent documentation: https://plotly.com/python/\n", "\n", "This notebook is not intended to instruct you how to use `plotly.py`. Instead it pulls together interesting examples from the `plotly.py` documentation into a single notebook to give you a taster of what can be done with `plotly.py`.\n", "\n", - "## Install `plotly.py`\n", + "### Install `plotly.py`\n", "\n", - "`plotly` is not installed in the `fslpython` environment so you will need to install it to run this notebook. In a terminal run the following command (you will need admin privileges):\n", + "`plotly` is not installed in the `fslpython` environment so you will need to install it to run this notebook. (e.g. with `pip install plotly`)\n", "\n", - "```\n", - "sudo $FSLDIR/fslpython/bin/conda install -c conda-forge -n fslpython plotly\n", - "```\n", + "### Line & Scatter Plots\n", + "https://plotly.com/python/line-and-scatter\n", "\n", - "## Line & Scatter Plots\n", + "The graph_objects class gives you access to all the types of graphs that plotly has to offer. \n", "\n", - "https://plotly.com/python/line-and-scatter/" + "Below are some random data plotted as scatter plots. Run the cell below and try the interactive interface. You can zoom in and out, you can see data values as you hover on the plot, and you can toggle on and off the different scatter plots.\n" ] }, { @@ -102,7 +101,9 @@ "metadata": {}, "source": [ "## Box Plots\n", - "https://plotly.com/python/box-plots/" + "https://plotly.com/python/box-plots\n", + "\n", + "Here we use `plotly.express`. It is probably the easiest way to create plotly plots (it uses graphical_objects under the hood). Here we also use it to get access to some of the toy datasets. \n" ] }, { @@ -115,9 +116,29 @@ "\n", "df = px.data.tips()\n", "\n", + "# have a peek inside this dataset\n", + "print(df)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now let's do a boxplot to see how tips change by day and by smoker status. Try to interact with the plot. It shows you useful quantities, such as min/max, as you hover." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", "fig = px.box(df, x=\"day\", y=\"total_bill\", color=\"smoker\")\n", "fig.update_traces(quartilemethod=\"exclusive\") # or \"inclusive\", or \"linear\" by default\n", - "fig.show()" + "fig.show()\n", + "\n" ] }, { @@ -125,7 +146,9 @@ "metadata": {}, "source": [ "## Distribution Plots\n", - "https://plotly.com/python/distplot/" + "https://plotly.com/python/distplot\n", + "\n", + "Here we use figure_factory, yet another collection of pre-specified nice plots. \n" ] }, { @@ -300,7 +323,9 @@ "metadata": {}, "source": [ "## Network Graph\n", - "https://plotly.com/python/network-graphs/" + "https://plotly.com/python/network-graphs\n", + "\n", + "This one is very ugly. I don't know why anyone would use this...\n" ] }, { @@ -388,8 +413,9 @@ "metadata": {}, "source": [ "## Custom Controls: Sliders\n", + "https://plotly.com/python/sliders\n", "\n", - "https://plotly.com/python/sliders/" + "Sliders are a very nice way to interact with plots. Here is a basic example where we plot a sine function and change its frequency. Note how all the data for plotting, and all the traces are pre-generated. This is not ideal if you need to change more than one parameter (e.g. both phase and frequency). \n" ] }, { @@ -439,7 +465,8 @@ " sliders=sliders\n", ")\n", "\n", - "fig.show()" + "fig.show()\n", + "\n" ] }, { @@ -587,7 +614,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -601,7 +628,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.8.11" } }, "nbformat": 4, diff --git a/applications/data_visualisation/seaborn.ipynb b/applications/data_visualisation/seaborn.ipynb index 25cc038e2795127d0a141c69087fbc0ff0191c60..14d595e6a09a8ab2c0b457c94e6d534bec7addbd 100644 --- a/applications/data_visualisation/seaborn.ipynb +++ b/applications/data_visualisation/seaborn.ipynb @@ -7,7 +7,7 @@ "source": [ "# Tabular data visualisation using Seaborn\n", "---\n", - "When it comes to tabular data, one of the best libraries to choose is `pandas` (for an intro to `pandas` see [this tutorial](https://git.fmrib.ox.ac.uk/fsl/win-pytreat/-/blob/fsleyes_branch/applications/pandas/pandas.ipynb)). \n", + "When it comes to tabular data, one of the best libraries to choose is `pandas` (for an intro to `pandas` see [this tutorial](https://git.fmrib.ox.ac.uk/fsl/win-pytreat/-/tree/master/applications/pandas)). \n", "`seaborn` is a visualisation library built on top of `matplotlib` and provides a convenient user interface to produce various types of plots from `pandas` dataframes. \n" ] }, @@ -49,7 +49,7 @@ "## Plotting relative distributions\n", "---\n", "<a id='scatter'></a>\n", - "Seaborn library provides a couple of `pandas` datsets to explore various plot types. The one we load below is about penguins 🧠" + "The seaborn library provides a couple of `pandas` datasets to explore various plot types. The one we load below is about penguins 🧠" ] }, { @@ -70,7 +70,7 @@ "metadata": {}, "outputs": [], "source": [ - "penguins" + "print(penguins)" ] }, { @@ -85,9 +85,7 @@ "cell_type": "code", "execution_count": null, "id": "lasting-battlefield", - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "penguins.plot(kind='scatter', x='bill_length_mm', y='bill_depth_mm')" @@ -148,9 +146,7 @@ "cell_type": "code", "execution_count": null, "id": "regular-oriental", - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "for style in ['darkgrid', 'whitegrid', 'dark', 'white', 'ticks']:\n", @@ -247,7 +243,7 @@ "metadata": {}, "outputs": [], "source": [ - "sns.set_context('notebook') # set the context used for the subsequecnt plots\n", + "sns.set_context('notebook') # set the context used for the subsequent plots\n", "\n", "g = sns.scatterplot(data=penguins, x='bill_length_mm', y='bill_depth_mm', hue='species', s=80)\n", "g.set(xlabel='Snoot length (mm)', ylabel='Snoot depth (mm)', title='Snoot depth vs length')\n", @@ -271,7 +267,7 @@ "source": [ "### Linear regression\n", "<a id='scatter'></a>\n", - "There also seems to be a linear dependece between the two parameters, separately in each species. A linear fit to the data can be easily plotted by using `lmplot` which is a convenient shortcut to `scatterplot` with extra features for linear regression." + "There also seems to be a linear relation between the two parameters, separately in each species. A linear fit to the data can be easily plotted by using `lmplot` which is a convenient shortcut to `scatterplot` with extra features for linear regression." ] }, { @@ -284,7 +280,7 @@ "g = sns.lmplot(data=penguins, x='bill_length_mm', y='bill_depth_mm', \n", " hue='species', \n", " scatter_kws={\"s\": 60})\n", - "g.set(xlabel='Snoot length (mm)', ylabel='Snoot depth (mm)', title='Snoot depth vs length')" + "g.set(xlabel='Snoot length (mm)', ylabel='Snoot depth (mm)', title='Snoot depth vs length')\n" ] }, { @@ -323,7 +319,7 @@ "id": "prospective-mason", "metadata": {}, "source": [ - "The confidence bounds shown above are calculated based on standard deviation by default. Alternatively confidence interval can be used by specifying the confidence interval percentage" + "The confidence bounds shown above are calculated based on standard deviation by default. Alternatively confidence intervals can be used by specifying the confidence interval percentage" ] }, { @@ -352,7 +348,7 @@ "## Data aggregation and uncertainty bounds\n", "<a id='line'></a>\n", "\n", - "In some datasets, repetitive measurements for example, there might be multiple values from one variable corresponding to each instance from the other variable. To explore an instance of such data, lets load the `fmri` dataset." + "In some datasets, repeated measurements for example, there might be multiple values from one variable corresponding to each instance from the other variable. To explore an instance of such data, let's load the `fmri` dataset." ] }, { @@ -373,7 +369,7 @@ "metadata": {}, "outputs": [], "source": [ - "fmri" + "print(fmri)" ] }, { @@ -381,7 +377,7 @@ "id": "exclusive-yahoo", "metadata": {}, "source": [ - "Lets visualise the signal values across time..." + "Let's visualise the signal values across time..." ] }, { @@ -418,7 +414,7 @@ "id": "digital-sheriff", "metadata": {}, "source": [ - "By default, mean of the signal at each `x` instance is plotted. But any arbitrary function could also be used to aggregate the data. For instance, we could use the `median` function from `numpy` package to calculate the value corresponding to each timepoint." + "By default, the mean of the signal at each `x` instance is plotted. But any arbitrary function could also be used to aggregate the data. For instance, we could use the `median` function from the `numpy` package to calculate the value corresponding to each timepoint." ] }, { @@ -490,7 +486,7 @@ "id": "silent-messenger", "metadata": {}, "source": [ - "or we could separate them even more detailed, based on the event type; _cue_ or _stimulus_" + "or we could separate them even more, based on the event type; _cue_ or _stimulus_" ] }, { @@ -552,16 +548,14 @@ "metadata": {}, "outputs": [], "source": [ - "planets" + "print(planets)" ] }, { "cell_type": "code", "execution_count": null, "id": "czech-terminology", - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "g = sns.scatterplot(data=planets, x=\"distance\", y=\"orbital_period\")\n", @@ -593,16 +587,14 @@ "source": [ "However, it seems that the data could be better delineated in log scale... but `jointplot` is not flexible enough to do so. The solution is to go one level higher and build the figure we need using `JointGrid`. \n", "\n", - "`JointGrid` creates a _joint axis_ that hosts the jont distribution of the two variables and two _marginal axes_ that hosts the two marginal distributions. Each of these axes can show almost any of the plots available in `seaborn`, and they provide access to many detailed plot tweaks." + "`JointGrid` creates a _joint axis_ that hosts the joint distribution of the two variables and two _marginal axes_ that hosts the two marginal distributions. Each of these axes can show almost any of the plots available in `seaborn`, and they provide access to many detailed plot tweaks." ] }, { "cell_type": "code", "execution_count": null, "id": "realistic-batman", - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "# define the JointGrid, and the data corresponding to each axis\n", @@ -652,7 +644,7 @@ "metadata": {}, "outputs": [], "source": [ - "iris" + "print(iris)" ] }, { @@ -685,11 +677,27 @@ "g.map_lower(sns.kdeplot)\n", "g.map_diag(sns.kdeplot, lw=3)" ] + }, + { + "cell_type": "markdown", + "id": "5e56f938-9cf2-473a-a3ae-fefa0aa8dce5", + "metadata": {}, + "source": [ + "That's all folks!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d9cf9412-5f74-408b-92de-f3d5eb2d1ee9", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -703,7 +711,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.11" } }, "nbformat": 4,