bfit: A Python Application For Beta-Detected NMR

Beta-detected nuclear magnetic resonance (β-NMR) measures the beta-decay of probe radioactive nuclei to infer the electromagnetic character of the probe’s local environment. Similar to muon spin rotation (μSR), this technique allows for unique insight of material properties not easily measured by conventional NMR. The bfit package provides a graphical user interface (GUI) and application programming interface (API) to facilitate the analysis of implanted-ion β-NMR measurements taken at TRIUMF.


Summary
Beta-detected nuclear magnetic resonance (β-NMR) measures the beta-decay of probe radioactive nuclei to infer the electromagnetic character of the probe's local environment. Similar to muon spin rotation (µSR), this technique allows for unique insight of material properties not easily measured by conventional NMR. The bfit package provides a graphical user interface (GUI) and application programming interface (API) to facilitate the analysis of implanted-ion β-NMR measurements taken at TRIUMF. Background β-NMR leverages the parity-violating nuclear weak interaction to measure the spin precession of a ensemble of radioactive probe nuclei (MacFarlane, 2015). These nuclei can either be activated by neutrons or implanted as a foreign species in the form of a low-energy particle beam. Upon decay, the direction of the emitted electron is correlated with the nuclear spin orientation. As with many nuclear and particle physics experiments, the data collected is the counted number of electrons emitted in a given direction. These counts are then histogrammed and processed to yield a signal of interest.
The activation or implantation of the probe nuclei require high-intensity particle beams, restricting the technique to large nationally-supported facilities. Even today, there are only a handful of locations capable of conducting β-NMR measurements, such as TRIUMF, which is situated in Vancouver, Canada. This facility has been running β-NMR experiments for the past 20 years, and has developed the Muon Data (MUD) file format (Whidden et al., 1994) as a means of storing µSR and β-NMR data.

Statement of need
At TRIUMF, β-NMR receives approximately 5 weeks of radioactive beam time per year. As with other large-facility experiments employing particle beams, this data is extremely limited and expensive to generate. Having the tools for rapid on-line analysis is therefore crucial for efficient and informed measurement. Additionally, many of the experimenters using the β-NMR spectrometer are visiting scientists or students who have little experience with the technical aspects of the measurement.
As with many older science applications, the MUD API is written in C and FORTRAN. These statically-typed and compiled languages are known for their computational efficiency, but are accompanied by long development times, relative to modern languages. In many communities, scientific computing has shifted to languages such as Python: a dynamicallytyped and interpreted language. As a result, Python has amassed a massive library of data analysis tools (Virtanen et al., 2020). The short development time of Python programs is particularly important in the context of scientific analyses, which are typically run only a few times by select individuals. As a result, the development time of the analysis code comprises a large part of the program's effective run time. The aim of this work is to bring this rapid prototyping style of analysis to β-NMR. To further streamline on-line analyses, bfit provides an intuitive GUI capable of a moderately high degree of sophistication.
It should be acknowledged that, while a large body of analysis software exists to support µSR workers (such as WIMDA (Pratt, 2000), MANTID (Arnold et al., 2014), and Musrfit (Suter & Wojek, 2012)), β-NMR does not have a comparably extensive suite of maintained analysis programs. While there have been some recent improvements to this situation (Saadaoui, 2018), the analysis required for any non-trivial β-NMR experiment necessitates the development of new code to meet the individual requirements of each experiment. While such code may employ Musrfit, which is compatible with the MUD file format, this approach may be cumbersome for complex or rapid analyses, and presents a entry high entry barrier for new users. The Python API of bfit is well suited for addressing these issues.

Usage and features
The bfit GUI has three primary functions which are contained in the Inspect, Fetch, and Fit tabs. The purpose of the Inspect tab (shown below) is to quickly view the file headers and plot the data in order to detect and solve problems as they may arise during measurement. The Fetch tab has been designed to prepare the data for analysis, loading runs in batch and allowing the user to draw and compare each run. The Fit tab provides the tools needed to fit a model to the data, and to view and analyze the result. These tools include global fitting (i.e., sharing fit parameters between data sets), constrained fitting (i.e., constraining a parameter to follow a specific model dependent on the experimental conditions, such as temperature), non-trivial fitting functions specific to pulsed-beam operation (leveraging double exponential integration (Cook, 2014)), multiple minimization routines, and more. While the GUI greatly facilitates rapid on-line analysis, the bfit API provides the flexibility needed for publishable analyses. The analysis tools and functions utilized in the GUI are readily accessible via the API, and documented in the wiki. Many of these tools are very general, easily interfacing with other Python packages, and can accommodate a great deal of complexity and sophistication.