Simply store jupyter script as executable

To save a jupyter script as an executable .py script you can use the nbconvert command in terminal:

$ jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb

Make sure to either cd into the directory where the ipynb file is located or to paste the complete path of the file.

But even better is to call the command directly in a jupyter notebook by prepending !, which will run bash code inside any jupyter script:

!jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb

In this way you can save your .ipynb file to .py file in an easy and fast way and only when you need it, such as when pushing a commit to github, saving time compared to when using auto convert.

Learning a new skill: LaTeX

The last few weeks I delved into learning \LaTeX, a code language for more aesthetically pleasing article writing, especially in terms of mathematical formulas. As my research has increasingly been focused on the mechanisms underlying collective behaviour, for which I do a lot of mathematical computations, such an advanced yet simple text-editor is very helpful and overcomes the many pains I have with MS word!

(1)   \begin{equation*} v_i(t) = |\mathbf v_i(t)| = \sqrt{u_i^2(t)+w_i^2(t)}. \end{equation*}

(2)   \begin{equation*} \mathbf a_i(t)= \frac{\mathbf v_i(t+\Delta t) - \mathbf v_i(t)}{\Delta t} = \frac{\mathbf r_i(t+\Delta t) - \mathbf 2r_i(t)+\mathbf r_i(t-\Delta t)}{\Delta t^2}, \end{equation*}

(3)   \begin{equation*} \rho(t)=\frac{1}{n}\sqrt{\left( \sum_{i=1}^{n}\sin(\psi_i(t))\right)^2+\left( \sum_{i=1}^{n}\cos(\psi_i(t))\right)^2} \end{equation*}

It was quite a steep learning curve, but I managed to write my first paper with it last week. The great thing is that it is also possible to use \LaTeX in wordpress (which I used to create this website). It is also the standard language for drafting preprint articles, which is increasingly suggested and done in the biological sciences, thus a very relevant skill to learn.

How to create an interactive scientific plot online

In my previous post I showed a fully interactive online graph of one of the plots in my recent paper on leadership in sticklebacks. In this follow-up post I will explain how to easily create such an interactive plot yourself. To be able to do this you will need some experience with the R-language and ideally with ggplot2.

First create an account at plot.ly, which is free. After you have created your account, go to “settings” and click on “generate API key”. You will need your username and this key to link your account to R.

Now you have your account ready start-up R and set-up the R workspace:

Read further…