python - neuralinterfacinglab/LabManual GitHub Wiki
A good and easy way to install python environments is Anaconda.
This includes jupyter notebooks and a full python distribution. There is a lot of good python IDEs. Christian and Maarten use Visual Studio Code ( https://code.visualstudio.com/ ).
Collection of python tutorials:
- Codecademy
- Coursera
- Python Data Science Handbook, by Jake vd Plas, organised in Jupiter notebooks.
- Case Studies in Neural Data Analysis https://elifesciences.org/labs/f779833b/python-for-the-practicing-neuroscientist-an-online-educational-resource
- Simple GUIs with TKinter https://realpython.com/python-gui-tkinter/
- Getting Started scripts for our sEEG data
Visualizing your results and data is absolutely crucial for scientific progress.
- Matplotlib can create beautiful figures in python. Here is the gallery.
- Fundamentals of data visualization is a very good read.
- Python Graph Gallery gives great inspiration for data viz.
-
Color schemes are important!
For example, check these out: Scientific color maps
These colors are great for your scientific projects, because:- Perceptually uniform
- Perceptually ordered
- Colour-blind friendly
- Readable as B&W print
- Highly compatible
- Versioned & citable
Check the Userguide (section Python) for installation and usage.
Python comes with a style guide called PEP or "Python Enhancement Proposal" to write clear and "pythonic" code. It's really important to adhere to these standard as much as possible. Why? Well, you might understand the code you've written today, but are you still able to understand it quickly when you come back to it in two months? Or, maybe more importantly, will someone else understand your code? This is especially important when helping someone to debug.
- Read a brief introduction here
- Find the complete styleguide here - It's a lot, but very worthy to give it a good scroll through
- Styleguide don't show the overall code structure. I've written a quick template that's essential. Find it here
There are also plugins called linters that check you're code for adherence to the style guides. Personally, I'm not a big fan of them, because your clutter your screen and sometimes its better to not adhere to the style guide. Though, it can definitely help you to when starting.
Version control is a really good idea. We use git.
Here are a few resources
- https://swcarpentry.github.io/git-novice/
- https://eglerean.wordpress.com/2016/04/19/git-in-10-minutes/
- https://docs.github.com/en/free-pro-team@latest/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line
If you are working on several projects, it is advisable to manage your software. You can do this easily by creating environments for every project. Imagine the following (#true story):
- you do analysis Jan 2021, you submit this paper in May, June, August, and October 2021. (In July 2021 you updated all your python/conda packages)
- In Jan 2022 you are asked by a reviewer to repeat an analysis with a small difference, or you need to adjust that legend or axis in that figure. BUT, you updated your python/numpy/pandas and are getting different results!
- Now, you have to search which packages you used in Jan 2021, and re-install/downgrade all your packages again.
So, use environments. Here are some explanations about it: https://docs.conda.io/projects/conda/en/latest/commands/create.html, https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html.
And example code (it is that easy):
To create an environment (via conda), Mac-users go to Terminal and type:
conda create --prefix /Users/jeroenhabets/Research/DBS_PREDICT/n322_multicenter/env python=3.7.3 pandas==0.24.0 scipy==1.3.0 numpy==1.16.4 matplotlib==3.1.0 statsmodels seaborn
You can also create environment using the conda navigator app, although creating one from command line by conda create --name myenv python
is preferred, as it creates an empty environment. Using environments also allows you to export an environment, so you can easily send it to someone else or install it on a new laptop
In this case, the folders until n322_multicenter are existing, the folder 'env' will be created by conda. The packages are installed in the latest available version in conda, or in the version you specified.
To start working in this environment you command:
conda activate /Users/jeroenhabets/Research/DBS_PREDICT/n322_multicenter/env
To end working in the environment, you command:
conda deactivate
.