Intro to CZI files Part 1
This post explores how to set up your enviroment for doing confocal image analyis in Python.
Dependencies
Before we get into image analysis we will have to go through the hellish process of installing shit. I personally hate this the most because all of this work is riddled with the anxiety that it is all for nothing because the program might not be right for what I am doing anyway. Here at least you can rest assured that all of this crap will definitely be useful for you in the future. There are only a few things that are even image analysis related (at the end) so nearly everything I talk about here will be useful for you at some point if you ever plan on using python.
Another common fear I have when installing shit is that it might take up crazy amounts of space on my computer. Fear not! I don't have much room on my computer but I was able to install all of these things (and many more) with relatively little space bloating. Anaconda is 3Gb but it comes with so many other things that I use that it makes it worth it for me. And you probably won't have to install a bunch of other stuff too. But if you just want to dip your toes in the water you can try with miniconda.. or just uninstall anaconda when you are done.
Dependencies
General note: Everyone is going to go on their own journey with installs. Follow the directions for the specific packages. I am not super great at installs and find them super frustrating and time consuming. Marc and Ciera are really good at them and each have helped me through it, usually with us googling whatever the error was. I feel like every computer has weird permissions and shit that you have to figure out individually. If you plan on following along (which I would def recommend for max learning) try to get conda, jupyter, and the relevant packages installed before Tuesday! If you are planning on doing any sort of coding in python it's worth it.
-
I made a specific environment for image analysis. to do this I used conda environment manager.
Why should I use conda?
- conda is good to start using because it means you can have several "versions" of packages and python installs at any given time. This means that if I need to use an old version of Numpy for this one package (which happens constantly with poorly maintained scientific packages) I can make a new environment where I do that and it won't break all of my other stuff.
- Also means that if you still do stuff in python 2 you can make a python 3 environment where you do this tutorial and image analysis without breaking any preexisting stuff you already have going....it's very useful and definitely worth getting up and running. I don't know how I would do any analysis without it.
Anaconda vs miniconda
- Miniconda is just the environment manager and maybe python? It doesn't come with any other packages installed. I didn't install miniconda (I did anaconda) so I have no idea what those packages will be and it might result in dependency hell. if you don't want to install a lot of packages but you might have to install more individually as you go or anaconda if you have space and are not about installing shit (Me)
- Anaconda has jupyter already installed so you won't have to worry about that.
Choose Anaconda if you:
- Are new to conda or Python
- Like the convenience of having Python and over 150 scientific packages automatically installed at once
- Have the time and disk space (a few minutes and 3 GB), and/or
- Don’t want to install each of the packages you want to use individually.
Choose Miniconda if you:
- Do not mind installing each of the packages you want to use individually.
- Do not have time or disk space to install over 150 packages at once (~3Gb I think?), and/or
- Just want fast access to Python and the conda commands, and wish to sort out the other programs later
- More info
- Working with Conda
- Once you have conda up and running play around with setting up new environments and installing packages. All the commands are through the terminal.
- Conda command cheat sheet
- Tip: Always try to install new packages through conda first before using PIP (if you did miniconda you might have to download or update pip). Conda will always put that install in the right directory for the environment you are in - PIP does not .. sometimes it puts it in your root python bin which (at least for me) was not related to my conda bins and it was very frustrating.
-
- if you installed Anaconda - GOOD JOB YOU'RE DONE!! Launch jupyter notebook by typing- jupyter notebook - into the terminal and BAM you got a jupyter notebook!
- if you installed miniconda I think all you have to do is : conda install jupyter
- you can install with PIP which I have done before.. I then had to uninstall it later because it wasn't syncing with any of my environments and I wasted a whole day uninstalling and reinstalling python .. not fun...
- (more info)[https://jupyter.readthedocs.io/en/latest/install.html]
Test it out!
once you have installed conda + Jupyter all you need to do is:
Open terminal
Type 'source activate nameofyourenvironmenthere'
go to whatever directory you want your notebooks to be stored in
type 'jupyter notebook' to open up a directory in your browser where you can launch a new notebook by clicking new or you can type 'jupyter notebook pathtonotebook
you can also open notebooks in visual studio code now which I have started doing when I just need to check one quickly
Czi file/ Image analysis specific dependencies -¶
- You need the Czifile python package to import CZI files into python.
- welcome to dependecy hell. In order to install this package you need the following:
- CPython 2.7 or 3.5+
- Numpy 1.14
- Tifffile 2019.7.2
- Imagecodecs 2019.5.22 (optional; used for decoding LZW, JPEG, and JPEG XR) <-- i never did this one.. I get an annoying warning every time that I just ignore
- I think I needed to install or update xcode for some of them..
- install as many as possible with conda but I think the final Czifile install will be with pip. Getting pip to play nice with conda is challenging but try it out! to test to see if it worked launch python in the terminal by just typing python then type 'import czifile'
- Directions from Ciera
pip install imagecodecs==2018.10.28
- Download package czifile.py
- Then pip install on zipped package: `pip install ~/Downloads/czifile-2018.10.18.tar.gz
- Directions from Ciera
- welcome to dependecy hell. In order to install this package you need the following:
other packages that are useful to have
Disclaimer many of these packages come with anaconda and so I have never used the links I provided to install it. I just put those there for reference. Don't @ me bro.
Many of these packages will already be installed with anaconda. Check to see if you have them by going into your python 3 conda environment (source activate *condaenvname*) typing in python, and then import *packageName* - before installing make sure you are in the right conda environment
- scipy's ndimage package for multi dimensional image processing
- i don't know if this comes pre-downloaded with anaconda but if you don't have it install it with conda
- if not : conda install -c anaconda scipy source page
- sci-kit image or skimage for image processing in python
- conda install -c conda-forge scikit-image source page
- matplotlib - making graphs and stuff. I hate it but also that is how you output images in jupyter notebooks which is very essential to seeing what you are doing.
- comes with anaconda
- should have already been installed with jupyter?
- more info - https://anaconda.org/conda-forge/matplotlib
I use the following a lot but they are probably already installed with python
- xml.etree - I think this comes with python too.
- os - allows to interact with the operating system. This is probably included in the conda install
- math - also to perform basic math functions. probably included something you installed already