mcphysics

McPhysics

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.

  1. Download and install Miniconda Python 3 or the full bloaty Anaconda Python 3. See additional instructions below for OSX.

  2. From the Anaconda Prompt (or system terminal, depending on your installation options), install the “core” packages:
    conda install pip spyder pyqtgraph
    

    then

    pip install spinmob mcphysics imageio sounddevice
    
  3. Open Spyder and start playing. Example script:
    import mcphysics
    mcphysics.playground.fitting_statistics_demo()
    

OSX Notes

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.

Creating and Activating a New Environment

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.

  1. To create a clean environment named pants, use the command below (following the resulting instructions):
    conda create --name pants
    
  2. To activate the environment:
    conda activate pants
    
  3. To see which environments exist and which is activated (has a * next to it):
    conda env list
    

Upgrading

To upgrade to the latest stable versions,

   pip install mcphysics spinmob --upgrade --no-cache-dir

Optional instrument drivers

If you need to talk to the supported equipment, you may also need to install some drivers.

VISA and serial instruments

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.

ADALM2000

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

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.

Organization

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.

mcphysics.data

### 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: