Installing HyperSpy with Anaconda is slightly more involved, but provides moreflexibility if you plan to do more development with Python, or need to run manydifferent Python programs on your machine alongside each other.
While it is mostly unattended, the download and installation of Anaconda cantake a fair amount of time (approximately 10 to 15 minutes, depending on thespeed of your system), so it is highly recommended to do this before youarrive at the tutorial session (and when you have access to a decent internetconnection).
Download#
The installation process for Anaconda varies a bit depending on your operatingsystem. Instructions for Windows are detailed here. MacOS will be somewhat similar,while if you run Linux, you will need to use the command line installer (anexercise left to the reader). From the Anaconda Python link, click theright download for your operating system:
Installing Anaconda#
Detailed instructions forWindows,macOS, andLinux are available onthe Anaconda website. Specific instructions for Windows are reproduced below.
Run the downloaded file to proceed with the installation. This process is fairlystraightforward. For the installation location, we highly recommend an easilyaccessed path that does not require administrative rights, such as the folderanaconda3
within your user directory:
The next screen will present you with options about adding Anaconda to thesystem PATH
variable, and whether or not you want this installation tobe registered as the “default” Python installation on your system (via akey saved to the registry on Windows). We recommend the default options (asshown below), but if you have other Python installations on your system, you maywant to uncheck the “Register as default” option:
Click the “Install” button at this point, and go to get a coffee or tea (or gofor a walk), as the installation process takes some time depending on your diskspeed.
Once the installation completes, click the “Next” button to continue and then“Finish” to exit the installer.
Usage#
After Anaconda is installed, we suggest taking a look at the“Getting Started” guide from its documentation to familiarize yourself withhow Anaconda is used. There are a few ways to interact with Anaconda, primarilythrough either the “navigator” application, or on the command line. One of themost powerful features of Anaconda is the conda
environment and packagemanager, which allows you to create multiple different “installations” (known asenvironments) of Python, enabling you to select which version of Python isused for each environment and what packages are installed inside thatenvironment. A common setup is to have one environment for each project orapplication you are working with. For this tutorial however, we will installHyperSpy into the base
(the default) environment (for ease of use) usingthe command line.
Installing HyperSpy with Anaconda#
Like for Anaconda, detailed installation instructions for HyperSpy areavailable directly from its documentation.The process will also be summarized here with a bit more instruction.
Info about code blocks
In the following section, lines in code blocks will be prefaced with $
or >>>
. $
is used to indicate regular terminal input, while >>>
represents inputs to the Python interpreter (accessed by running python
from the regular command line. Any lines without these symbolsindicate the expected output of the given command. To run thecommands provided, copy everything after the $
or >>>
character intoyour terminal. Where necessary, commands will be given for both the WindowsAnaconda prompt and the macOS/Linux terminal, so only use the commandsspecific to your operating system.
From the Start Menu (on Windows), open the Anaconda Prompt:
On Mac or Linux, open a terminal as normal. If during installation you toldthe installer to “initialize” Anaconda3, all the conda
commands shouldbe immediately available. If not, you will have to run the following, replacingthe bracketed term with the actual path in which you installed Anaconda:
$ source <ANACONDA_INSTALL_PATH>/bin/activate
before any of the conda
commands will work. Again, this is only forMac/Linux, the commands should be available with no problem on Windows whenyou launch the Anaconda Prompt.
From the prompt, run the following to install HyperSpy, its UI package, and itsdependencies:
$ conda install -c conda-forge hyperspy hyperspyui kikuchipy atomap pyxem
After Anaconda calculates the dependencies (this may take quite a while,please be patient) it will need to install, it will ask for confirmation to continue.Press Enter
to accept the changes, and wait for the requested libraries to beinstalled.
Extension packages
The “extension” libraries kikuchipy
, pyxem
, and atomap
will beinstalled using the command above. These are not absolutely necessary to installif you wish to just use HyperSpy on its own, but since these libraries willbe covered in the short course, you will need to have them installed if youwish to follow along interactively.
Testing the installation#
Once the install is completed, if you would like to test that your installationis working properly, you can run a small test example by opening the“Qt Console”. From within the Anaconda Prompt, enter the following commandand then press Enter
:
$ jupyter qtconsole
The Qt Console is an interactive Python interpreter that allows you to enterPython statements directly and immediately see their output. Once the consolehas opened and you see a prompt that says In [1]:
, copy the following codesnippet at the location of the blinking cursor:
%matplotlib qtimport hyperspy.api as hss = hs.datasets.artificial_data.get_core_loss_eels_signal(add_powerlaw=True)s.remove_background()
Very briefly, this code is loading the interactive plotting libraries, loadingHyperSpy, creating an example EELS signal from some artificial data, and thentelling the interpreter you want to interactively remove the Power Lawbackground. Press Shift-Enter
within the console to run the lines of codeyou pasted in (it may take a few moments to run if this is the first timeyou’ve used HyperSpy on your machine):
Eventually, you should see a spectrum window and a small tool window forremoving the background open (they may be stacked on top of each other;drag them out of the way, if so). If you click and drag on part of the spectrumdisplay, HyperSpy will fit a Power Law to the signal within that region,and also show you a preview of the background-subtracted signal:
Clicking “OK” in the Background removal tool window will perform thebackground subtraction, and replace the window with one showing the resultingsignal:
Assuming all of this worked, congratulations! You have a working HyperSpyinstallation and you have run your first bit of open-source HyperSpy-basedmaterials science data analysis! Click the button below to return to the maintutorial homepage:
Click here to returnto the main page