Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: documentation

on: [push, pull_request, workflow_dispatch]

permissions:
contents: write

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.2.2
- uses: actions/setup-python@v5.4.0
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r docs/requirements.txt
- name: Sphinx build
run: sphinx-build -W docs/source docs/build/html
- name: Create .nojekyll file
run: touch docs/build/html/.nojekyll
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
# only the default branch publishes: a force-orphan push from a feature branch would replace the site
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/5.3.x' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build/html
force_orphan: true
41 changes: 41 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ Actuators
* **Current**: current of the electromagnet, through a National Instruments analog output (needs ``pymodaq_plugins_daqmx``)
* **CurrentMock**: simulated version of the above, with a magnetic hysteresis
* **LedDC4104**: Thorlabs DC4104 four-channel LED driver of the Kerr microscope
* **MokeMagnetSim**: simulated electromagnet (field in mT, first order response), see *Simulated MOKE bench* below
* **MokeWavePlateSim**: simulated half-wave plate rotation mount (balance of the detection)
* **MokeSampleRotationSim**: simulated rotation of the sample about its normal
* **MokeGoniometerSim**: simulated angle of incidence

Viewer0D
++++++++

* **ReadCurrent**: reads the electromagnet current on a National Instruments analog input
* **MokeBalancedSim**: simulated balanced detection (two photodiodes), see *Simulated MOKE bench* below

Viewer1D
++++++++
Expand All @@ -53,6 +58,42 @@ Extensions
* **MicroMOKE**: acquisition of Kerr microscope images with the sequence of LED illuminations


Simulated MOKE bench
====================

``MokeMagnetSim``, ``MokeWavePlateSim``, ``MokeSampleRotationSim``, ``MokeGoniometerSim`` and ``MokeBalancedSim`` simulate
a MOKE bench with balanced detection, to develop and test acquisitions, scans and extensions without hardware.
The five plugins share one simulated bench through the controller: give them the same *controller ID* in the Dashboard,
one as ``Master`` (it creates the bench) and the others as ``Slave``. A plugin alone works as a master on its own bench.

* The magnet field (mT) drives the magnetisation of a simulated sample. Two models: Stoner-Wohlfarth (vector
magnetisation, uniaxial anisotropy ``Hk`` along an easy axis, switching when the energy minimum disappears) and a
scalar ``tanh`` loop (coercive field, width).
* The Kerr rotation is the sum of a polar term (magnetisation along the normal) and a longitudinal one (in the plane of
incidence, proportional to the sine of the angle of incidence). The geometry follows from the direction of the
field, the easy axis, the sample rotation and the angle of incidence. A transverse term changes the intensity (``p``
polarisation only).
* The detector emits one 0D dataset with four channels in V: ``diode_A``, ``diode_B``, ``difference`` and ``sum``.
The balance is set by the half-wave plate angle (22.5 deg from its zero, an offset of which can be hidden), the
Kerr rotation is ``difference / (2 * sum)`` near the balance. The plugins add no Kerr rotation and no semantic
annotation: that is left to the extension or the analysis.
* Optional imperfections, each adjustable: shot noise, electronic noise, laser intensity noise (common mode),
gain imbalance between the diodes, Faraday rotation of the optics, slow drift.

The angles that the plugins control, and how they are measured, are drawn below (``docs/make_angles_figure.py``
regenerates the figure): the angle of incidence (goniometer), the direction of the field (settings of the magnet),
the azimuth of the sample (rotation stage) and of its easy axis, and the angle of the half-wave plate that balances the
detection.

.. image:: docs/source/moke_bench_angles.png
:alt: Definition of the angles of the simulated MOKE bench
:width: 100%

The equations, the settings and the limits of the model are described in ``docs/source/simulated_bench_model.md`` (published as a GitHub Pages site by the ``documentation`` workflow).

The physics is approximate (see ``hardware/simulated_bench.py``) and has not been reviewed by MOKE experts yet.


Installation instructions
=========================

Expand Down
140 changes: 140 additions & 0 deletions docs/make_angles_figure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""Draws docs/source/moke_bench_angles.png / .svg: how the angles of the simulated MOKE bench are defined.

Run ``python docs/make_angles_figure.py`` (needs matplotlib)."""
from pathlib import Path

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Arc, FancyArrowPatch, Polygon

OUT = Path(__file__).parent / "source"
BEAM, FIELD, SAMPLE, POL, AXIS = '#c0392b', '#2471a3', '#444444', '#1e8449', '#7d3c98'


def arrow(ax, p0, p1, color, lw=2., style='-|>', ls='-', ms=14, z=3):
ax.add_patch(FancyArrowPatch(p0, p1, arrowstyle=style, mutation_scale=ms, color=color, lw=lw, ls=ls, zorder=z))


def arc(ax, center, r, a0, a1, color, label=None, label_r=None, fs=11, lw=1.4):
ax.add_patch(Arc(center, 2 * r, 2 * r, theta1=a0, theta2=a1, color=color, lw=lw, zorder=4))
if label:
a = np.radians((a0 + a1) / 2)
lr = label_r or r * 1.35
ax.text(center[0] + lr * np.cos(a), center[1] + lr * np.sin(a), label, color=color, fontsize=fs,
ha='center', va='center', zorder=5)


def polar(r, deg):
return r * np.cos(np.radians(deg)), r * np.sin(np.radians(deg))


def setup(ax, title, xlim, ylim):
ax.set_xlim(*xlim), ax.set_ylim(*ylim)
ax.set_aspect('equal'), ax.axis('off')
ax.set_title(title, fontsize=12, fontweight='bold', loc='left')


fig, axes = plt.subplots(1, 3, figsize=(17, 6.2), gridspec_kw=dict(width_ratios=[1.15, 1, 1]))

# ---------------------------------------------------------------- A: side view, plane of incidence (x-z)
ax = axes[0]
setup(ax, 'A Side view, in the plane of incidence (x, z)', (-2.3, 2.6), (-1.75, 2.9))
ax.add_patch(Polygon([(-2, 0), (2.1, 0), (2.1, -0.18), (-2, -0.18)], color='#d5d8dc', zorder=1))
ax.plot([-2, 2.1], [0, 0], color=SAMPLE, lw=2.5, zorder=2)
ax.text(-2.2, -0.42, 'sample surface', color=SAMPLE, fontsize=10)
arrow(ax, (0, 0), (0, 2.5), SAMPLE, lw=1.2, ls='--')
ax.text(0.07, 2.55, 'z (sample normal)', fontsize=10, color=SAMPLE)
arrow(ax, (0, 0), (2.4, 0), SAMPLE, lw=1.2, ls='--', style='-|>')
ax.text(2.2, -0.34, 'x', fontsize=10, color=SAMPLE)
ti = 32
bx, bz = polar(2.3, 90 + ti)
arrow(ax, (bx, bz), (0, 0), BEAM, lw=2.5)
ex, ez = polar(2.3, 90 - ti)
arrow(ax, (0, 0), (ex, ez), BEAM, lw=2.5, ls=(0, (4, 2)))
ax.text(bx - 0.35, bz + 0.12, 'probe beam\n(polarisation s or p)', color=BEAM, fontsize=10, ha='center')
ax.text(ex + 0.1, ez + 0.1, 'reflected\nbeam', color=BEAM, fontsize=10, ha='center')
arc(ax, (0, 0), 1.05, 90, 90 + ti, BEAM, r'$\theta_i$', 1.3, fs=13)
ax.text(-2.2, -0.85, 'Goniometer:\n' r'$\theta_i$ = angle of incidence', color=BEAM, fontsize=10.5, va='top')
tH = 62
fx, fz = polar(1.95, 90 - tH)
arrow(ax, (0, 0), (fx, fz), FIELD, lw=3.5)
arc(ax, (0, 0), 0.62, 90 - tH, 90, FIELD, r'$\theta_H$', 0.8, fs=13)
ax.text(fx + 0.12, fz - 0.05, 'B\n(field)', color=FIELD, fontsize=11, fontweight='bold')
ax.text(0.2, -0.85, 'Magnet: B (mT) is the actuator value;\n' r'$\theta_H$ = "Field direction from the normal":' '\n0° polar geometry, 90° in plane',
color=FIELD, fontsize=10, va='top')

# ---------------------------------------------------------------- B: top view (x-y)
ax = axes[1]
setup(ax, 'B Top view (x, y): sample, easy axis, field', (-2.4, 2.7), (-3.2, 2.5))
ax.add_patch(Polygon([(-2.3, -0.28), (2.5, -0.28), (2.5, 0.28), (-2.3, 0.28)], color='#fdedec', zorder=0))
ax.text(-2.25, 0.4, 'plane of incidence (x)', color=BEAM, fontsize=9.5)
arrow(ax, (-2.2, 0), (-0.05, 0), BEAM, lw=2.2)
ax.text(-2.2, -0.2, 'beam', color=BEAM, fontsize=9.5, va='top')
psi, phi_e, phi_h = 28, 40, -35
rot = np.radians(psi)
R = np.array([[np.cos(rot), -np.sin(rot)], [np.sin(rot), np.cos(rot)]])
sq = np.array([[-1, -1], [1, -1], [1, 1], [-1, 1]]) * 0.95
ax.add_patch(Polygon((R @ sq.T).T, closed=True, fc='#eaecee', ec=SAMPLE, lw=2, zorder=1))
ax.text(*(R @ np.array([0.45, -0.7])), 'sample', color=SAMPLE, fontsize=10, rotation=psi, ha='center', va='center')
arrow(ax, (0, 0), (2.4, 0), SAMPLE, lw=1.1, ls='--')
ax.text(2.45, -0.17, 'x', fontsize=10, color=SAMPLE)
arrow(ax, (0, 0), (0, 2.05), SAMPLE, lw=1.1, ls='--')
ax.text(0.07, 2.08, 'y', fontsize=10, color=SAMPLE)
xs = polar(1.85, psi)
arrow(ax, (0, 0), xs, SAMPLE, lw=1.4, ls=(0, (3, 2)), ms=10)
ax.text(xs[0] + 0.08, xs[1] + 0.02, r'$x_s$ (sample)', fontsize=9.5, color=SAMPLE)
arc(ax, (0, 0), 1.25, 0, psi, SAMPLE, r'$\psi$', 1.5, fs=13)
ea = polar(2.15, psi + phi_e)
arrow(ax, (-ea[0] * 0.55, -ea[1] * 0.55), ea, AXIS, lw=2.6, style='<|-|>', ms=14)
ax.text(ea[0] + 0.05, ea[1] + 0.12, 'easy axis', color=AXIS, fontsize=10.5)
arc(ax, (0, 0), 0.8, psi, psi + phi_e, AXIS, r'$\phi_e$', 1.05, fs=13)
fh = polar(2.2, phi_h)
arrow(ax, (0, 0), fh, FIELD, lw=3.5)
arc(ax, (0, 0), 1.6, phi_h, 0, FIELD, r'$\phi_H$', 1.88, fs=13)
ax.text(fh[0] + 0.1, fh[1] - 0.12, 'B (in-plane\ncomponent)', color=FIELD, fontsize=10, ha='left', va='top')
ax.text(-2.35, -1.95,
r'Sample rotation stage: $\psi$ = azimuth of the sample (from x)' '\n'
r'Sample setting "Easy axis azimuth": $\phi_e$, measured from $x_s$' '\n'
r'Magnet setting "Field azimuth": $\phi_H$, from x, in the lab' '\n'
'The easy axis is at ' r'$\psi + \phi_e$' ' from x in the lab',
fontsize=9.5, va='top', linespacing=1.5)

# ---------------------------------------------------------------- C: polarisation, half-wave plate, PBS
ax = axes[2]
setup(ax, 'C Polarisation in front of the polarising beam splitter', (-2.2, 2.6), (-2.5, 2.4))
arrow(ax, (-2.0, 0), (2.1, 0), SAMPLE, lw=1.2)
ax.text(1.55, -0.3, 'port B axis', color=SAMPLE, fontsize=10)
arrow(ax, (0, -0.9), (0, 2.0), SAMPLE, lw=1.2, style='-|>')
ax.text(0.08, 2.05, 'port A axis', color=SAMPLE, fontsize=10)
al = 14
fa = polar(2.0, al)
ax.plot([-fa[0], fa[0]], [-fa[1], fa[1]], color=AXIS, lw=3, solid_capstyle='round', zorder=2, alpha=.8)
ax.text(-fa[0] - 0.05, -fa[1] - 0.12, 'fast axis of the\nhalf-wave plate', color=AXIS, fontsize=9.5, va='top')
arc(ax, (0, 0), 0.62, 0, al, AXIS, r'$\alpha_{eff}$', 0.95, fs=12)
ph0 = polar(1.7, 0)
ax.plot([0, 1.7], [0, 0], color=POL, lw=0, zorder=0)
phi = 2 * al + 6
pv = polar(1.95, phi)
arrow(ax, (0, 0), pv, POL, lw=3.5)
ax.plot([0, polar(1.95, 45)[0]], [0, polar(1.95, 45)[1]], color=SAMPLE, lw=1.2, ls=':')
ax.text(*polar(2.5, 52), 'balance\n45°', fontsize=9.5, color=SAMPLE, ha='center', va='center')
arc(ax, (0, 0), 1.3, 0, phi, POL, r'$\varphi$', 1.55, fs=13)
arc(ax, (0, 0), 1.75, 2 * al, phi, BEAM, None, lw=2.2)
ax.text(*polar(2.1, (2 * al + phi) / 2 + 3), r'$\theta_K$', color=BEAM, fontsize=12, ha='left', va='center')
ax.text(pv[0] - 0.05, pv[1] + 0.22, 'polarisation', color=POL, fontsize=10.5, fontweight='bold', ha='right')
ax.text(-2.15, -1.25,
r'$\alpha_{eff}$ = waveplate angle $-$ zero offset (hidden defect)' '\n'
r'The plate rotates the polarisation by $2\alpha_{eff}$;' '\n'
r'the sample adds the Kerr rotation $\theta_K$: $\varphi = 2\alpha_{eff} + \theta_K$' '\n'
r'$I_A = P\,\sin^2\varphi$, $I_B = P\,\cos^2\varphi$' '\n'
r'Balanced when $\varphi$ = 45°, i.e. $\alpha_{eff}$ = 22.5°:' '\n'
r'$A - B \approx P \sin 2\theta_K$',
fontsize=9.5, va='top', linespacing=1.5)
ax.text(-2.15, 2.4, 'Waveplate rotation mount:\n' r'$\alpha$ = angle of the plate', color=AXIS, fontsize=10.5, va='top')

fig.suptitle('Angles of the simulated MOKE bench and the plugin that sets each of them', fontsize=14, y=0.995)
fig.tight_layout()
fig.savefig(OUT / 'moke_bench_angles.png', dpi=130)
fig.savefig(OUT / 'moke_bench_angles.svg')
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx
sphinx_rtd_theme
myst_parser
Empty file added docs/source/_static/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project = 'pymodaq_plugins_moke'
copyright = '2025, CEMES'
author = 'Sébastien Weber'
extensions = ['myst_parser']
myst_enable_extensions = ['dollarmath', 'amsmath']
templates_path = []
exclude_patterns = ['_build']
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
13 changes: 13 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pymodaq_plugins_moke documentation
==================================

PyMoDAQ plugins for a magneto-optical Kerr effect (MOKE) bench. This site documents the
**simulated MOKE bench** (plugins ``MokeMagnetSim``, ``MokeWavePlateSim``, ``MokeSampleRotationSim``,
``MokeGoniometerSim`` and ``MokeBalancedSim``), which runs scans and gives realistic hysteresis loops
without any hardware.

.. toctree::
:maxdepth: 2
:caption: Contents:

simulated_bench_model
Binary file added docs/source/moke_bench_angles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading