-
Notifications
You must be signed in to change notification settings - Fork 14
Home
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.
Windows: Install Python 3 from the built-in Microsoft store. You can get it from python.org but then you have to mess with environment variables.
Linux: Linux usually comes with at least one Python3 environment installed. You can see which version you have with the command python3 --version. If you want to use a different version, you'll have to read about how to do this for your specific Linux distribution. You will also want to make sure the Python packages venv and pip are installed, so you can create virtual environments and install python packages. In Debian/Ubuntu variants, e.g., this is achieved with sudo apt-get install python3-venv python3-pip.
At this point, it is a very good idea to create a new virtual environment, so that anything you do beyond this point will not affect the default Python installation. To create a virtual environment, open a command prompt and type something like
python3 -m venv my_new_environment
where my_new_environment can be replaced with whatever you like, e.g., Python3_Spinmob. This will create a directory of the same name.
To interact with this environment on the command prompt, you need to "activate" it, every time:
-
Windows: From the command prompt, run the
activatescript withpath\to\my_new_environment\Scripts\activate(appropriately editing the path).- If you get a security error about running scripts being disabled, you may have to first unlock this with the command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. - I so often want to activate my python environment that I created a windows shortcut pointing to
C:\Windows\System32\cmd.exe /K "C:\path\to\my\Activate.bat"(and add it to my start menu / pin it there).
- If you get a security error about running scripts being disabled, you may have to first unlock this with the command
-
Linux: From the terminal, use the command
source my_new_environment/bin/activate(appropriately editing the path). If you always want to use this Python environment in the terminal, you can add a similar command to your.bashrcscript (or equivalent for non-Ubuntu-like distributions).
If it works, you will see the name of your activated environment in parenthesis before your prompt.
Sometimes an old version of pip is installed, and this can cause problems. It's a good idea to run
python -m pip install --upgrade pip
to make sure it's at the latest version. It is also a good idea to make sure the Python package wheel is installed with
pip install wheel
You can then install packages with pip. To get spinmob running, use
pip install spinmob
This will download and install spinmob and all its dependencies except for the finicky "PyQt", which is responsible for creating graphics. We intentionally left this choice up to you, because you cannot have more than one installed at a time, and many people have their own preferred version. If you do not have a PyQt variant installed, you can install one as follows:
pip install PyQt5
On some (linux) systems importing spinmob will still fail, despite PyQt5 being present, complaining about libg or something. To rectify this, you may have to install glib2-devel or equivalent using apt or zypper or your distribution's package manager. Or dump your console's output into claude and ask it what happened. :)
You can quickly test if spinmob is installed properly by typing
python
then
>>> import spinmob
>>> spinmob.plot.xy.function()
which should pop up a plot of sin(x).
I have found VSCode to be the best development environment for all things Python. It is a general-purpose tool, however, so it takes a little initial effort to get it configured for Python.
Tricks to explain eventually:
- Install the Python and Jupyter Extensions from Microsoft
- Windows: install
ipykernelwithpip install ipykernel - EITHER: Preferences -> Settings -> Extensions -> Python -> Default interpreter (enter the path to python executable)
- OR:
ctrl-shift-p"Python: Select Interpreter" "Enter interpreter path" "Find..." to browse. - Bind shortcuts to Jupyter: Run current file in interactive terminal
- On first run, it may ask you to install libraries, e.g., ipykernel
To upgrade Spinmob:
pip install spinmob --upgrade --no-cache-dir
or, if you're Thomas:
python -m pip install --upgrade --no-cache-dir
Spinmob is designed to work when cloned directly into site-packages. To help with development or get the bleeding-edge version, you can create a "spinmob" folder in python's site-packages directory and clone the spinmob repository there or download / unzip. We highly recommend using a git client as described on the contributing page.