Home - Spinmob/spinmob GitHub Wiki
Welcome to the spinmob wiki!
Spinmob is designed as a high-level, easy-to-navigate library for acquiring, saving, loading, visualizing, and analyzing data. For example, the following nonlinear fit:
is produced with the following commands:
# Import the library
import spinmob
# Create a fitter object
f = spinmob.data.fitter()
# Set the functions
f.set_functions('a*x*cos(b*x)+c', 'a=-0.2, b, c=3')
# Supply the data
f.set_data([1, 2, 3, 4, 5], [1.7, 2, 3, 4, 3], 0.115, xlabel='Time (s)', ylabel='Pants (mV)')
# Fit!
f.fit()
Check out the "chapters" on the right-hand side of this page to get a feel for what it can do (and learn a bit about python itself if you're new). By far the most popular features for new users are the fitting object (Chapter 4), the databox object (Chapter 2), and the GUI builder (Chapter 6). There are also a bunch of plotting shortcuts (Chapter 3) and a mess of random / potentially useful functions in spinmob.fun. All the code's documentation is readily accessible inside Spyder or your favorite IDE.
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. Install Miniconda or the full Anaconda Python.
Anaconda Python comes with a lot of packages. Miniconda comes with the bare bones, allowing you select only those packages you want.
The easiest way to install Spinmob is via pip
, but we need to install pip
first (note this may be installed already on newer Miniconda / Anaconda distributions). It's also good to install spyder via conda
at the same time since they do a better job packaging that (and this will set up a few other things automatically that are helpful!). From your Anaconda prompt (or system terminal), run:
conda install pip spyder
Then install Spinmob with pip:
pip install spinmob
Note you can leave spyder out, but if you do, you will then need to make sure you have some version of PyQt installed as well, e.g., by running pip install pyqt5
.
If you're new to python, check the Python Bootcamp section. Once you have a python console (ideally IPython, e.g., in Spyder), import spinmob with
import spinmob as s
The module is designed so that there are fewer high-level objects organized in a hierarchy, to facilitate learning by exploration on the command line and integrated help functionality. After importing, type s.
and press the tab key to see what options are available. To access data-related functionality, type s.data.
and see what options appear. For plotting, s.plot.
, and so on.
Like all python, Spinmob's documentation is built in. Much of this is visible via code-completion or Spyder's Help window, which can be accessed by typing <ctrl>-i
with your cursor positioned after the last character of an object. Or, you can use python's help()
command, e.g. help(s.plot.xy.data)
.
When I have just finished a new install, my first test is always this command:
In []: s.plot.magphase.function()
This should pop up a magnitude and phase plot for the supplied (default) complex function 1/(1+1j*x). If it popped up, spinmob & all its dependencies are correctly installed.
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.
-
To create a clean environment named
pants
, use the command below (following the resulting instructions):conda create --name pants
-
To activate the environment:
conda activate pants
-
To see which environments exist and which is activated (has a
*
next to it):conda env list
To upgrade Spinmob:
pip install spinmob --upgrade --no-cache-dir
or, if you're Thomas:
python -m pip install --upgrade --no-cache-dir
If you have a working python installation and just want to install Spinmob (and its dependencies), you can do so with "pip" from your system's command line ("Terminal" in OSX/Linux, "cmd.exe" in Windows):
pip install spinmob
I do not recommend this approach, as system python installs are finicky and often your system relies on them in weird ways.
If pip doesn't work for some reason, this is a sure-fire method: Create a "spinmob" folder in python's site-packages directory and either clone the spinmob repository there or download / unzip. We highly recommend using a git client as described on the contributing page. Spinmob is designed to work when cloned directly into site-packages.