Skip to content
Snippets Groups Projects

External scripts

This directory contains extra scripts that might be required for data preparation. At the moment, these are all python scripts.

Getting started with python

Here is a short, straightforward way to install python to launch a jupyter notebook on a mac. If anything is unclear or doesn't work, please let us know.

For terminal comments, just type everything after the $ sign exactly as it appears.

Step 1: check whether you have python

First, open a terminal and type

$ which python

if you get something like

$ which python
/Users/lmcneill/opt/anaconda3/bin/python

then you already have python installed. Check for anaconda.

Otherwise, if you got a blank response e.g.:

$ which python
$

then you'll need to install python.

Step 2: installing python with anaconda3

We recommmend installing via anaconda, where the direct download .zip can be found here.

Once you have successfully gone through the installation steps in the graphical installer, close the terminal, open a new one, and then repeat step 1. You should get a path to where python is now i.e.

$ which python
/Users/lmcneill/opt/anaconda3/bin/python

nd2converter.ipynb

at the moment, anaconda installed most of the packages we will need for this. Except for nd2reader. So we return to the terminal and type:

$ conda config --add channels conda-forge

After this, we can install packages from the command line. To install the python package nd2reader, type:

$ conda install nd2reader

Step 3: Launching jupyter notebook

Once you have installed nd2converter.ipynb, put it somewhere that you will remember. Then, in the terminal, navigate to the folder that the file is located. For example, if I put it in a folder called jupyter-notebooks in

'/Users/lmcneill/Documents/svi/jupyter-notebooks'

then I would open a terminal and type

$ cd Documents/svi/jupyter-notebooks

to check that the notebook is there, type

$ ls

and it should return all the files you have in there, including our notebook

$ ls
nd2converter.ipynb

OK, we are ready to launch jupyter notebook. Type:

$ jupyter notebook

A window should open in your browser. Click on nd2converter.ipynb.

When you have changed the path to the images you want to analyse i.e. change

parent_dir = '/Users/lmcneill/Documents/svi/imaging/data-folder/from-sharepoint/OneDrive_1_01-06-2021'

in the python script, click inside the cell and press Shift+Enter. The notebook should run for a few mins. You can look in parent_dir in Finder to watch the .nd2s get converted.

Navigating the terminal

By the way, if you're new to using the mac terminal, here are some commands that will help you.

To list all files and directories in your current location, type

$ ls

to go into a folder (or complete path) in your current directory (i.e. appears in ls)

$ cd Documents

to go to the previous folder

$ cd ..

to go home

$ cd

to make a folder

$ mkdir

to make a file

$ touch test.md

to remove a file (a bit dangerous)

$ rm test.md

to print working directory (helpful for getting the full path to use parent_dir in nd2converter.ipynb)

$ pwd