The latest release version of Larch is 0.9.65.

Larch is in active and continuing development. The goal is to release versions every six months, but we don’t use a strict schedule, and typically release more often than that.

There are three ways to install Larch. Which of these is right for you will depend on your operating system and your familiarity with the Python programming language and environment:

1. Installing from a Binary installers. Use these to get started with XAS Viewer or other Larch GUI applications, or if you are not familiar with Python.

2. Installing with the GetLarch.sh and GetLarch.bat scripts. Use these if your comfortable with the command-line or want to customize your installation.

3. Installing into an existing Anaconda Python environment. Use this if you already have an Anaconda Python environment that you want to use.

There should not be any difference in the resulting code or packages when using these different methods. One is not “more right” or even “more preferred”. In short, use the Binary installer unless you know that you want to install into an existing Python environment. If that doesn’t work, try the installation script.

## 1.1. Installing from a Binary installers¶

Table of Larch binary installers

Operating System

Binary Installer File

Installation Notes

Windows (64 bit)

Larch for Windows

Notes

Mac OSX (64 bit)

Larch for MacOSX

Notes

Linux (64 bit)

Larch for Linux

Notes

Binary installers for Windows, Mac OSX, and Linux, are available at Larch Binary Installers. These are fairly large (400 to 600 Mb files) self-contained files that will install a complete Anaconda Python environment with all of libraries needed by Larch. Normally, this installation will create a folder called xraylarch in your home folder – see platform-specific notes below.

Note

There can be no spaces in your username or the path in which Larch is installed.

If you have a space in your Windows username, you can probably install to C:\Users\Public - that has worked for some people!

Installing with these installer programs should write to files only to folders owned by the user account. It should not require administrative privilege and should not interfere with any thing else on your system (such as system Python).

These installers will also create a folder called Larch on your desktop that contains links (or shortcuts or Apps) to many of the Larch GUI applications listed in Table of Larch Applications and Programs. This includes tools for X-ray Absorption spectroscopy, X-ray fluorescence spectroscopy, and working with X-ray diffraction images.

### 1.1.1. Windows Notes¶

For Windows, download the Larch for Windows binary installer above and run it to install Larch. This will be installed to C:\Users\<YourName>\xraylarch for most individual Windows installations or to C:\Users\<YourName>\AppData\Local\xraylarch if your machine is part of a Windows Workgroup or Domain. As mentioned above, if your user name has a space in it, you will probably need to install to C:\Users\Public.

Alternatively you can download the GetLarch.bat script, and run that by double-clicking on it. This will download, install, and configure the Larch package, with a result that is nearly identical to the binary installer.

### 1.1.2. MacOS Notes¶

For Mac OS, download the Larch for MacOSX package installer above and click it to install Larch. There are two important notes:

Note

With MacOS 10.15 (Catalina), Apple will not install non-signed 3rd party packages by default. You may need to go into General Settings part of the Security & Privacy section of System Preferences and explicitly allow this package to be installed. You probably will be prompted for an Administrative password.

Note

You need to explicitly click on “Install only for me” during the installation process. If you get prompted for an Administrative password by the installer, go back and explicitly choose “Install only for me”.

Alternatively you can download the GetLarch.sh script, and run that in a Terminal session (Applications->Utilities->Terminal). This will download, install, and configure the Larch package, with a result that is nearly identical to the binary installer. If you run into any problems with permissions or administrative privileges or “unauthorized application” with the package installer, running this installer script actually avoids all of those issues since your user account will simply be running the commands to write files to your home directory.

### 1.1.3. Linux Notes¶

Warning

There have been reports of the binary installation not working well on all Linux systems. We recommend using GetLarch.sh on Linux

~> bash ./xraylarch-2022-04-Linux-x86_64.sh


Desktop shortcuts as .desktop files will be created on all Linux platforms, but whether these actually appear on your desktop depends on the Windowing system used: they will appear on the desktop with KDE and many other systems, but not with Gnome. Clickable icons should also show up in the Applications selection of the “Start Menu” or Applications list.

Alternatively you can download the GetLarch.sh script, and run that in a Terminal session. This will download, install, and configure the Larch package, with a result that is nearly identical to the binary installer.

Larch uses a relatively large number of Python packages (dependencies), and these also evolve. We try keep up with the latest versions of these packages, but changes in those sometimes complicate the installation of Larch. We also try to keep these installation instructions up-to-date, but strategies we use may change (slowly, we hope). Your feedback, bug reports, and patience are greatly appreciated.

## 1.2. Installing with the GetLarch.sh and GetLarch.bat scripts¶

This method is recommended for those who are relatively comfortable using a command-line, and is helpful for debugging cases where the binary installer has failed. The approach here is basically to run a script that follows the steps that the binary installer should follow, but is likely to give more useful error messages if something goes wrong. On Linux and MacOS, there are also command-line options.

To install with this method, download and execute one of the following:

Open a Shell or Terminal, find the location of this script and run that. On Windows, that would be launching the cmd program, and doing something like:

cd C:\Users\<YOURNAME>\Downloads
GetLarch


On MacOS on Linux, open a Terminal (from Applications -> Utilities on MacOS), and then type:

cd Downloads
sh GetLarch.sh


If this script fails, report it to the Larch Github Issues (including the error trace and the GetLarch.log file).

The scripts will download and install Miniforge Python which uses Anaconda Python and the conda-forge channel as the basis of an installation that will be essentially identical to the environment installed by the binary installers, that is, the whole environment is stored in a folder called xraylarch in your home folder. In case of problems, simply remove this folder to clean the installation.

You can also read these scripts and modify them for your needs (or maybe suggest ways we could maintain that for others to use too).

## 1.3. Installing into an existing Anaconda Python environment¶

The following procedure is recommended for those who are familiar with Anaconda Python / Conda and have already installed it in their system.

Note

Some packages that Larch uses are not currently (January 2022) handled by the standard Python package manager Pip. For this reason, we use a Conda environment and “conda forge” for installing them. These packages include:

• pymatgen: needed for handling CIF files and running FEFF calculations.

• wxpython: needed for all plotting, graphics and GUI applications.

• tomopy: needed for reconstructing X-ray fluorescence tomography.

• python.app: needed (from conda-forge) for Anaconda-based Python on MacOS.

• epicsapps: applications using the Epics control system.

Most of Larch functionality can be used as a library without these packages installed.

Within a shell:

1. activate your conda environment (called base by default) and update it:

conda activate
conda update -y conda python pip

1. (optional/expert) create a dedicated environment for Larch and activate it:

conda create -y --name xraylarch python=>3.9.10
conda activate xraylarch

1. install main dependencies:

conda install -y "numpy=>1.20" "scipy=>1.6" "matplotlib=>3.0" scikit-learn pandas
conda install -y -c conda-forge wxpython pymatgen tomopy pycifrw

1. install Larch (latest release):

pip install xraylarch

1. if anything of the above fails, report it to the Larch Github Issues

Putting that all together:

conda create -y --name xraylarch python=>3.9.10
conda activate xraylarch
conda install -y "numpy=>1.20" "scipy=>1.6" "matplotlib=>3.0" scikit-learn pandas
conda install -y -c conda-forge wxpython pymatgen tomopy pycifrw
pip install xraylarch
larch -m


### 1.3.1. Notes on Anaconda and on Python Versions¶

By default, Anaconda Python installs into your own home folder (on Windows, this will be the APPDATA location, which is typically something like C:\\Users\<YourName>\Anaconda3 or C:\\Users\<YourName>\AppData\Local\Anaconda3). As with the single-file installers below, installing Anaconda Python does not require extra permissions to install, upgrade, or remove components. Anaconda includes a robust package manager called conda that makes it easy to update the packages it manages, including Larch. You can start by installing the latest version of Anaconda Python from the Anaconda Downloads site, or by downloading and installing Miniconda from Miniconda Downloads as a starting distribution.

Python 3.9 is recommended, and using Python 3.8 is also supported. Testing of basic functionality with Python 3.10 does work, but at this writing (June, 2022) only “bleeding edge” versions of wxPython support Python 3.10 and we cannot recommend using Python 3.10 for most users (such as those who would expect GUIs to work). We no longer test with Python 3.7 or earlier: Python 3.7 should still work, Python 3.6 and earlier will probably not work.

## 1.4. Updating a previous installation¶

Updating xraylarch with conda is no longer supported. to update xraylarch, use pip, even when using Anaconda Python:

pip install --upgrade xraylarch


## 1.5. Installing the development version¶

For the brave, a nightly build of the latest development version can be downloaded and installed with

python -m pip install https://millenia.cars.aps.anl.gov/xraylarch/downloads/xraylarch-latest-py3-none-any.whl


We try hard to keep this “working”, but as this is an automated snapshot it might catch the development in the middle of trying to fix something tricky.

## 1.7. Larch for developers (source installation)¶

For developers, Larch is an open-source project, with active development happening at the Larch Repository (github.com). There, you will find the latest source code and pages for submit bug reports.

To get started, we recommend following the installation instructions for or ref:install-binary, ref:install-script, or ref:install-conda. That gives you a base starting Python environment that we can all be pretty sure is working. With that in place, to install Larch from source, you can clone the source repository with:

git clone https://github.com/xraypy/xraylarch.git


and then install with:

pip install -e .


This use of pip will install any requirements and Larch itself, but those should have been installed already when you installed. Depending on your platform and version of Python you are installing to, you may need elevated permissions as from sudo to install Larch to a system folder.

### 1.7.1. Optional Python Packages¶

While most of the packages required for Larch will be installed automatically (and are listed in the requirements.txt file in the source tree), there are a few packages that are useful for some functionality but somewhat less easy to have as a hard dependency (usually because they are not readily available on PyPI for all platforms). These optional packages are listed in the table below. Note that most of these will be installed with Larch whether you install from a binary installer, with conda install xraylarch, with pip install xraylarch, or with python setup.py install

## 1.8. Getting Help¶

For questions about using or installing Larch, please use the Ifeffit Mailing List.

For reporting bugs or working with the development process, please submit an issue at the Larch Github Pages.

## 1.9. Docs and Examples¶

The source kit includes sources for documentation in the docs folder and several examples (including all those shown in this documentation) in the examples folder.

These are also available separately in the zip file at Docs and Examples that contains a doc folder with this full documentation, and an examples folder with all of the Larch examples.

## 1.10. Citing Larch¶

Currently, the best citation for Larch is M. Newville, Larch: An Analysis Package For XAFS And Related Spectroscopies. Journal of Physics: Conference Series, 430:012007 (2013).

## 1.11. Funding and Support¶

Larch development at the GeoScoilEnviroCARS sector of Center for Advanced Radiation Sources at the University of Chicago has been supported by the US National Science Foundation - Earth Sciences (EAR-1128799), and Department of Energy GeoSciences (DE-FG02-94ER14466). In addition, funding specifically for Larch was granted by the National Science Foundation - Advanced CyberInfrastructure (ACI-1450468).

## 1.12. Acknowledgements¶

Larch was mostly written by and is maintained by Matt Newville <newville@cars.uchicago.edu>. Bruce Ravel has an incalculable influence on the design and implementation of this code and has provided countless fixes for serious problems in design and execution in the early stages. More importantly, Larch would simply not exist without the long and fruitful collaboration we’ve enjoyed. Margaret Koker wrote most of the X-ray diffraction analysis code, and much of the advanced functionality of the GSECARS XRF Map Viewer. Mauro Rovezzi has provided the spec-data reading interface and the RIXS viewer. Tom Trainor had a very strong influence on the original design of Larch, and helped with the initial version of the python implementation. Yong Choi wrote the code for X-ray standing wave and reflectivity analysis and graciously allowed it to be included and modified for Larch. Tony Lanzirotti and Steve Sutton have provided wonderful and patient feedback on many parts of Larch, especially for XANES processing and testing of the XAS Viewer GUI.

Because Larch began as a rewrite of the Ifeffit XAFS Analysis Package, it also references and builds on quite a bit of code developed for XAFS over many years at the University of Chicago and the University of Washington. The existence of the code and a great deal of its initial design therefore owes a great thanks to Edward Stern, Yizhak Yacoby, Peter Livens, Steve Zabinsky, and John Rehr. More specifically, code written by Steve Zabinsky and John Rehr for the manipulation of results from FEFF and for the calculation of thermal disorder parameters for XAFS are included in Larch with little modification. Both Feff6l and Feff8l, the product of many man years of effort by the Feff group led by John Rehr, are included in Larch. A great many people have provided excellent bug reports, feedback, in depth conversations, and suggestions for making Ifeffit better, including on the ifeffit mailing list. Many of these contributions have found their way into Larch.

Larch uses X-ray scattering factors and cross-sections fro the xraydb library. This uses code to store and read the X-ray Scattering data from the Elam Tables was modified from code originally written by Darren S. Dale. Refined values for anomalous scattering factors there have been provided directly by Christopher T. Chantler. Further details of the origin of much of the tabularized X-ray data is given in X-ray Databases.

As Larch depends on the fantastic scientific librarie written and maintained in python, especially the numpy, scipy, and matplotlib, the entire scientific python community deserves a hearty thanks. In particular, Larch uses the lmfit library, which began as part of Larch but was spun off into a standalone, general purpose fitting library that became useful for application areas other than XAFS, and has benefited greatly from numerous collaborators and added many features that Larch, in turn, has been able to depend on.

Except where explicitly noted in the individual files, the code, documentation, and all material associated with Larch are distributed under the BSD License:

BSD-2-CLAUSE LICENSE

-----------------------------------------

Unless otherwise stated, all files included here are copyrighted and

Copyright (c) 2010-2022 Matthew Newville, The University of Chicago

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.