Metadata-Version: 2.5
Name: mag-opt-detective
Version: 1.0.0
Summary: Plot, pick, fit and export magneto-optical FTIR field sweeps (OPUS and OPUS-macro text files).
Project-URL: Homepage, https://github.com/wyzula-jan/mag-opt-detective
Project-URL: Documentation, https://wyzula-jan.github.io/mag-opt-detective/
Project-URL: Source, https://github.com/wyzula-jan/mag-opt-detective
Project-URL: Issues, https://github.com/wyzula-jan/mag-opt-detective/issues
Project-URL: Changelog, https://github.com/wyzula-jan/mag-opt-detective/blob/main/CHANGELOG.md
Author-email: Jan Wyzula <wyzula.jan@gmail.com>
License-Expression: GPL-3.0-only
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: MacOS X
Classifier: Environment :: Win32 (MS Windows)
Classifier: Environment :: X11 Applications :: Qt
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.12
Requires-Dist: matplotlib>=3.11
Requires-Dist: numpy>=2.0
Requires-Dist: pillow>=12
Requires-Dist: pyqtgraph>=0.13.7
Requires-Dist: pyside6-essentials>=6.8
Requires-Dist: scipy>=1.13
Description-Content-Type: text/markdown

# Magneto-Optical Detective

[![CI](https://github.com/wyzula-jan/mag-opt-detective/actions/workflows/ci.yml/badge.svg)](https://github.com/wyzula-jan/mag-opt-detective/actions/workflows/ci.yml)

Desktop app to plot, pick, fit and export magneto-optical FTIR measurements: field sweeps
recorded with Bruker OPUS, either as OPUS binary files (`*.0`, `*.1`, …) or as two-column
text files written by the OPUS export macro.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/wyzula-jan/mag-opt-detective/main/docs/images/main-window-dark.webp">
  <img alt="The main window: the Sample panel, an R(B)/R(0) map with picked points, a Dirac model and a legend, and the inspector" src="https://raw.githubusercontent.com/wyzula-jan/mag-opt-detective/main/docs/images/main-window-light.webp">
</picture>

*All screenshots show a synthetic Landau fan, drawn by
[`docs/make_screenshots.py`](https://github.com/wyzula-jan/mag-opt-detective/blob/main/docs/make_screenshots.py).*

The documentation and download site ([`docs/site`](https://github.com/wyzula-jan/mag-opt-detective/tree/main/docs/site)) is published at
<https://wyzula-jan.github.io/mag-opt-detective/>.

## Features

The window is a workbench: a rail of panels on the left (**Sample**, **Reference**,
**Processing**, **Library**, **Points**), the plots in the middle (**Map**, **Stacked**,
**Reference**), an inspector on the right (**View**, **Colour**, **Traces**, **Models**) and a
log drawer at the bottom. Every side area slides open and closed.

**Load.** Drop a sweep folder or files on the Sample panel (and optionally a reference sweep
on the Reference panel). The fields are read from the file names or set as a custom range;
the panel lists the files by field and reports missing fields. One or two zero-field
spectra (measured before and after the sweep) correct the drift. While a sweep is measured,
**Watch folder** adds the new spectra of its folder as they appear and processes them.

**Process** (Ctrl+Return).
- Plots: R(B)/R(0), the data, R(B)/R(B-AVR) (the field average) and R(B)/R(B-ΔB)
  (neighbouring fields).
- 1st or 2nd derivative along energy (d/dE) or field (d/dB), per data point or **per unit**
  (cm⁻¹, meV, THz or T).
- Reference correction with a separate sweep or with the sample itself, smoothed with
  Savitzky–Golay; an energy window and baseline normalisation.
- The baseline region is a band to drag on the map or the stacked plot; with **Live** on it
  applies at once, without processing again. The status bar shows the baseline of the map on
  screen.
- A dot on Process (and on the Processing panel) shows settings changed since the last run.

**View.**
- **Live energy unit**: the cm⁻¹ | meV | THz switch in the toolbar converts maps, axes,
  ranges, picked points, model parameters and curves, and exports at once, without
  processing again.
- Field, energy and intensity ranges (Auto or Fixed), shared by the map and the stacked
  plot. Colour maps magma, inferno, viridis, plasma, turbo, grey and bipolar, with levels
  Auto (1–99 %), Fixed or Symmetric, remembered per plot kind, and a histogram.
- Colour scales as the classic histogram or a slim bar (a switch in the plot toolbar);
  each one collapses with its handle, or all at once. The histograms hold still while
  you set the levels, or follow them with the toolbar's auto-scale button.
- Stacked spectra: offset, every n-th field and colours by field.
- A legend in the map and the stacked plot (a button in the plot toolbar) lists the
  picked curves and the models drawn; drag it anywhere.
- Appearance: light, dark or following the system.

**Pick points** (P). A click on the map records the energy of the current curve at that
field (e.g. a Landau-level transition), Alt-click removes the point. Picking also works on
the stacked plot, by clicking a trace. Curves are chips in the Points panel, with a table of
their points, import and export, and Ctrl+Z / Ctrl+Shift+Z to undo and redo every edit.

**Auto-pick** (W, or the Points panel). *Track* follows a clicked line field by field in both
directions; *Detect* finds every line in a region drawn on the map: a box, a rotated box, an
ellipse or a freehand polygon, which stays there to be moved and reshaped. Options: maxima,
minima or rising / falling inflection points, the search window, Savitzky–Golay smoothing and
the prominence. The lines found are a preview until **Accept** puts them into the current
curve (one undo step).

**Models and fitting** (inspector › Models).
- **Massive Dirac** interband transitions (Fermi velocity, half-gap Δ).
- **Zeeman / magnon** branches E₀ + m g μB B, linear or hyperbolic, optionally **coupled**
  by a constant Δᵢⱼ per pair: the energies are the eigenvalues of diag(Eᵢ) + Δ, which gives
  avoided crossings.
- **Custom expressions** in B, one branch per line, with the constants `muB`, `hbar`, `kB`,
  `e`, `c`, `pi` and functions such as `sqrt`, `exp`, `log`; every other name is a parameter
  shared between the lines.
- **Fit to points**: assign each picked curve to a branch (or match the points by energy
  order or to the nearest branch), fit, and read every parameter as value ± σ with χ². The
  results can be copied or saved as a TSV table. Model curves are drawn live and go into
  figure exports.

**Library.** Keep processed maps, load exported tables, cut each to an energy and field
range, then merge spectral ranges, merge field ranges or average repeated sweeps.

**Export.**
- **Data table…** (Ctrl+E): the map shown, tab-separated.
- **Journal figure…** (Ctrl+Shift+E): the figure window, with a live preview. Presets
  **Nature**, **APS** and **Custom**: width and height in mm, text and lines in pt, dpi;
  the map or the stacked plot, its colour range (as in the window, Auto or Fixed), the
  colour bar on the right or on top, ticks (in or out, on all four sides, minor ticks),
  model curves, points, a legend and a panel label. Your own presets keep these styles and can be
  renamed, deleted, exported and imported (JSON). Saves PDF, SVG and EPS with editable
  text, and PNG and TIFF.
- **Quick image (PNG/SVG)…**: the plot as on screen, with its colour scale.

Choices (units, ranges, levels, colours, layout) are remembered between sessions;
*View › Reset settings* restores the defaults (and keeps your figure presets).

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/wyzula-jan/mag-opt-detective/main/docs/images/points-dark.webp">
  <img alt="Picked points in meV, with the slim colour bar" src="https://raw.githubusercontent.com/wyzula-jan/mag-opt-detective/main/docs/images/points-light.webp">
</picture>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/wyzula-jan/mag-opt-detective/main/docs/images/export-window-dark.webp">
  <img alt="The journal figure window with a Nature single-column preview" src="https://raw.githubusercontent.com/wyzula-jan/mag-opt-detective/main/docs/images/export-window-light.webp">
</picture>

## Installation

The standalone apps need no Python (see *Without Python* below). With
Python ≥ 3.12, install it from PyPI as an app of its own, with [uv](https://docs.astral.sh/uv/)
or [pipx](https://pipx.pypa.io). On a Mac this needs macOS 15 or newer, also on Intel Macs:

```bash
uv tool install mag-opt-detective   # or: pipx install mag-opt-detective
mag-opt-detective
```

`uv tool upgrade mag-opt-detective` updates it. To run it from a source checkout instead:

```bash
uv sync
```

## Running

From a source checkout:

```bash
uv run mag-opt-detective
```

or `uv run python -m mag_opt_detective`.

Once a day the app asks GitHub whether a newer version is out and says so in a bar above the
plot; it never installs anything (*Help › Check for updates…*, and *Help › Check for updates at
startup* to switch the daily check off).

### Without Python

Standalone apps are attached to each
[release](https://github.com/wyzula-jan/mag-opt-detective/releases) (and to every run of the
*App bundles* workflow):

| Archive | Runs on |
| --- | --- |
| `mag-opt-detective-windows.zip` | Windows 10 or 11, 64-bit (x86-64) |
| `mag-opt-detective-macos.zip` | macOS 15 or newer on Apple silicon (no Intel build) |
| `mag-opt-detective-linux.tar.gz` | 64-bit (x86-64) Linux with glibc 2.39 or newer (Ubuntu 24.04, Debian 13, Fedora 40 or newer) |

Unpack it and start `mag-opt-detective` (`.exe` on Windows, *Magneto-Optical Detective.app*
on macOS). The bundles are not code-signed: on macOS open the app once, then allow it under
*System Settings › Privacy & Security › Open Anyway*; on Windows choose *More info › Run
anyway*.

The first **Journal figure…** export after installing takes about 20 s while matplotlib
builds its font cache. The cache is kept for later sessions in
`~/Library/Caches/mag-opt-detective` (macOS), `%LOCALAPPDATA%\mag-opt-detective` (Windows)
or `~/.cache/mag-opt-detective` (Linux).

Build one yourself (the dev tools stay out of the bundle):

```bash
uv sync --locked --no-default-groups --group bundle
uv run --no-sync pyinstaller packaging/mag-opt-detective.spec --noconfirm
```

`mag-opt-detective --smoke-test` processes a small synthetic measurement, saves a figure in
every format and exits with 0; the workflow runs it on every bundle.

## Input files

| File | Content |
| --- | --- |
| OPUS binary (`*.0`, `*.1`, …) | the single-channel sample spectrum (`ScSm`) is read |
| text (`*.txt`, …) | two whitespace-separated columns: wavenumber (cm⁻¹), intensity |

The file type is detected automatically. With field values **From file names** the field
is taken from the name: `..._a01p250T.txt` → 1.25 T. Files are sorted by field, and the
Sample panel reports missing fields. Otherwise choose **Custom range** and enter start /
step / end.

**Zero field.** Load one zero-field spectrum, or two: measured before and after the
sweep, e.g. `..._a00p000T_a00p000T.txt` and `..._a00p000T_a16p000T.txt`. With two
spectra the zero-field reference is interpolated linearly between the first and the
last field point to compensate drift during the sweep. Files dropped on the Sample or
Reference panel (or a whole sweep folder) are sorted: names whose first field is 0 T go
to the zero-field list.

## Exported files

**Data tables** are tab-separated, in the energy unit shown; the library loads them back:

```
Energy (meV)	0.25T	0.50T	...
12.5	1.0012	0.9987	...
```

**Point tables** hold field (rows) × curve name (columns), with empty cells for missing
points; the first header cell names the energy unit:

```
Energy (meV)	LL 1	LL 2
0.5	12.398
1.0		24.797
```

Tables without the unit in the first header cell are read in the unit shown.

**Fit results** (TSV) start with `#` lines (model, curve assignment, number of points, χ²),
then one row per parameter: `parameter`, `value`, `sigma`, `unit`.

**Journal figures** have the exact print size. PDF, SVG and EPS keep their text editable
(TrueType fonts in PDF and EPS, text elements in SVG); PNG and TIFF store the dpi.

## Library

The Library panel keeps processed maps: **Add** (in the Processed sweep box) adds the
R(B)/R(0) map of the last Process (also *File › Add processed map to library*), **Load
table…** adds exported tables. **Tick maps to plot them**: ticked maps of one kind are drawn
together, the one ticked or clicked last on top, and where they overlap the upper ones are
drawn with the **Overlap** opacity. The top map is the one you pick on, fit and export; the
list highlights the maps on the plot (a map not drawn says why) and the plot head names them. Open a map's row to give it an energy (E min / E max, in the
energy unit shown) and field (B min / B max) range; empty limits mean no cut.

**Combine** joins the ticked maps, each cut to its limits, into a product, with a preview of
the result (or why it cannot be made) before you create it:

- **By energy** joins spectral ranges (e.g. FIR + MIR): an overlap is split at its middle,
  every measured energy is kept (no resampling; per-point derivatives count the typical
  step as one point) and a gap stays empty.
- **By field** joins field ranges (e.g. 0–8 T and 8–16 T sweeps); fields measured twice are
  averaged.
- **Average** averages repeated measurements with the same field values.

The **Product** box names the product (editable), lists the maps it was made of with their
limits, and plots it, saves it to the library or exports it as a data table as plotted
(with a `<file>_provenance.txt` note of how it was made) or a journal figure.

## Keyboard shortcuts

Ctrl is ⌘ and Alt is ⌥ on macOS. *Help › Shortcuts* lists them in the app.

| Keys | Action |
| --- | --- |
| Ctrl+Return (or Ctrl+F) | Process |
| Ctrl+E | Export the shown data as a table |
| Ctrl+Shift+E | Export a journal figure (PDF, SVG, EPS, PNG, TIFF) |
| Ctrl+L / Ctrl+Shift+L | Open sample field / zero-field files |
| Ctrl+R / Ctrl+Shift+R | Load reference field / zero-field files |
| Ctrl+1 / 2 / 3 / 4 | Plot R(B)/R(0) / Data / R(B)/R(B-AVR) / R(B)/R(B-ΔB) |
| Alt+1 / 2 / 3 | No / 1st / 2nd derivative |
| V / Z / P | Pan and zoom / box zoom / pick points |
| W | Auto-pick: follow a clicked line, or find the lines in a drawn region |
| Ctrl+Z / Ctrl+Shift+Z | Undo / redo a point edit (Alt-click removes a point) |
| A | Fit the plot to the data |
| F1 (on macOS also ⌘?) | Open the documentation |

## Feedback

Found a bug or missing a feature? *Help › Report a bug…* and *Help › Request a feature…*
open the [bug report](https://github.com/wyzula-jan/mag-opt-detective/issues/new?template=bug_report.yml)
and [feature request](https://github.com/wyzula-jan/mag-opt-detective/issues/new?template=feature_request.yml)
forms in the browser; the bug form comes with the app version and the system filled in.
Never attach measurement data you cannot share.

## Development

See [CONTRIBUTING.md](https://github.com/wyzula-jan/mag-opt-detective/blob/main/CONTRIBUTING.md). In short:

```bash
uv sync
uv run pre-commit install --hook-type pre-commit --hook-type commit-msg
uv run pytest
```

Tests that need real measurement data look for a `Data_to_test/` folder in the
repository root and are skipped when it is missing. Measurement data is never
committed.

## Citing

If you use Magneto-Optical Detective for an analysis in a publication, please cite it with
the version you used, which the About box shows (*Help › About*, on macOS in the app menu).
[`CITATION.cff`](https://github.com/wyzula-jan/mag-opt-detective/blob/main/CITATION.cff) has the details (GitHub shows them under *Cite this
repository*), for example:

> J. Wyzula, *Magneto-Optical Detective*, version *x.y.z*,
> https://github.com/wyzula-jan/mag-opt-detective

## Licence

Copyright © 2026 Jan Wyzula.

Magneto-Optical Detective is free software under the [GNU General Public License,
version 3](https://github.com/wyzula-jan/mag-opt-detective/blob/main/LICENSE) (GPL-3.0-only): you may use, study, change and share it. What you
share, changed or not, must stay under the same licence and come with its source code.
It comes without any warranty.

To build it into a product that is not released under the GPL, a commercial licence is
available from the author: wyzula.jan@gmail.com.

## Third-party software

The app is built on [Qt](https://www.qt.io) and [PySide6](https://pyside.org) (GNU LGPL
v3), [numpy](https://numpy.org), [scipy](https://scipy.org),
[matplotlib](https://matplotlib.org), [pyqtgraph](https://www.pyqtgraph.org) and
[Pillow](https://python-pillow.org). The icons are [Lucide](https://lucide.dev) icons (ISC
licence, parts MIT), see
[`LICENSE-lucide.txt`](https://github.com/wyzula-jan/mag-opt-detective/blob/main/src/mag_opt_detective/gui/icons/LICENSE-lucide.txt). The app bundles
contain every licence text in `THIRD_PARTY_NOTICES.txt`, which *Help › About › Licences…*
also shows.
