python - neuralinterfacinglab/LabManual GitHub Wiki

Python

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:

Data visualization

Visualizing your results and data is absolutely crucial for scientific progress.

Check the Userguide (section Python) for installation and usage.

Python Style guide

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.

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

Version control is a really good idea. We use git.

Here are a few resources

Environments management

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.

⚠️ **GitHub.com Fallback** ⚠️