This is a library of tools spefically aimed at the McGill undergraduate physics labs, namely PHYS 359/469 at the moment. It can be thought of as an augmentation of the Spinmob library, which provides general-purpose, broadly applicable data handling, plotting, fitting, graphical interface, and other analysis tools.
The installation discussed below automatically installs Spinmob, and you can read the Spinmob wiki, which provides a lot of information about Python, data handling, automated fitting, and graphical interface building.
Below is the standard installation method that works most reliably. Note many people already have a conda python installation and either do not want to mess with it or cannot make the following installation work due to library conflicts; in these cases, we recommend creating a new conda environment as discussed below.
Download and install Miniconda Python 3 or the full bloaty Anaconda Python 3. See additional instructions below for OSX.
conda install pip spyder pyqtgraph
then
pip install spinmob mcphysics imageio sounddevice
import mcphysics
mcphysics.playground.fitting_statistics_demo()
You may need to tell your system where Anaconda’s bin
folder is located manually. A method that worked is to create a text file named .bash_profile
in your home directory, and add the line export PATH="/path/to/Anaconda3/bin:$PATH"
, replacing /path/to/Anaconda3
with the appropriate location of the bin
folder. Log out and back in, and the terminal should now “know about” conda
and pip
.
If you wish to create a completely “clean” conda environment, you can do so with the following commands. Once a new environment is activated, you can then install packages as discussed above.
pants
, use the command below (following the resulting instructions):
conda create --name pants
conda activate pants
*
next to it):
conda env list
To upgrade to the latest stable versions,
pip install mcphysics spinmob --upgrade --no-cache-dir
If you need to talk to the supported equipment, you may also need to install some drivers.
To access VISA-based instruments (see below) you will also need a “standard” VISA driver, such as Rhode & Schwartz VISA or National Instruments VISA. I recommend Rhode & Schwarz because it’s lightweight and works with everything we’ve tested. You will then need to run pip install pyvisa pyserial
to get python access.
To access an ADALM2000, you will need to install libiio and libm2k (with python bindings!). On Windows, you will also need the m2k driver, and you may have to download the appropriate *.whl
file for your system, then manually run a pip install [filename].whl
from the anaconda prompt to get it into python. On Linux (and probably osx), we are required to manually compile the libm2k library, so McPhysics may require a specific version to be installed. If this is the case, import mcphysics
should complain and tell you which version is required when you try to access the device.
Fancy sound cards may require their own drivers to be installed, but do not need anything more than the sounddevice
library, which is installed by default above.
The McPhysics library is organized heirarchically, and you should use Spyder’s code completion suggestions to navigate it. You can also type <ctrl>-i
while your cursor is beside an object to access its documentation. Below is a list of the existing functionality. All of these objects are documented within the code itself, and detailed help is available via python’s help()
command or your favorite IDE’s or ipython’s built in help / autocomplete functionality. An introduction to some of the complex items is available on our (growing) wiki.
load_chns()
on all the .Chn files in a selected directory.plot_chns()
on all the .Chn files in a selected directory.### mcphysics.functions
### mcphysics.instruments
### mcphysics.playground
### mcphysics.experiments Some of the experiments have a collection of the above tools, along with some additional tools specific to the experiment: