Files
BD_Fresnel_GUI/README.md
T
2026-11-17 00:13:07 +00:00

344 lines
17 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# BD Fresnel
Beam-deflection pump–probe simulator and fitting tool. A Python port of the
MATLAB `BD_Fresnel_GUI` suite.
The program models a weak probe beam crossing a sample that has been excited by
a strong pump, propagates the perturbed probe field to the detector and computes
the transmission `T` and normalised beam deflection `ΔE/E` as a function of
pump–probe delay. Measured scans can be imported and compared against the
simulation, and the result exported as data, a log, and publication-sized
figures.
Two measurement modes are supported. **Beam deflection** fits both signals.
**Pump probe** is for measurements with the probe centred on the pump, where
there is no deflection: it fits the transmission alone, and needs only delay
and transmission data.
The program also runs without a measurement. In **Simulation** mode nothing is
imported: the signal is computed from the parameters alone, over a delay range
entered by hand, and only the calculated curves are plotted and exported.
![BD Fresnel fitting a measured scan](docs/screenshot.png)
## Features
- Seven mechanism slots, each independently configurable, summed into the total
nonlinear response.
- Instantaneous (electronic) and non-instantaneous responses, the latter
convolved with the pulse envelope.
- Group-velocity mismatch between pump and probe handled through the walk-off
parameter `rho`.
- Excited-state absorption via a five-level population model (S₀, S₁, S₂, T₁,
T₂) solved through the sample depth for a range of radial irradiances.
- Side-by-side transmission and deflection plots, with imported data overlaid
when there is any.
- Beam deflection and pump probe measurement modes. Pump probe reads a
two-column delay/transmission scan, fixes the probe on the pump axis, and
offers only the mechanisms that can change the transmission.
- Fitting and simulation run modes. Simulation computes the signal with no
data imported, over a delay range entered in the panel.
- Two interchangeable algorithms. Fresnel propagation carries the exit field to
the detector by FFT; the semi-analytical method uses closed-form detector
power expressions instead, needing no spatial grid and running about 32x
faster, at the cost of holding only to first order in the nonlinear response.
- Optional diagnostic figures showing each mechanism's response function before
and after convolution, plus the ESA populations and beam transmissions.
- Export of the data/fit comparison, a full parameter log, and figures at
6.5 in / 300 dpi.
## Requirements
- Python 3.10 or newer (developed against 3.12)
- `numpy`, `scipy`, `matplotlib`, `mpmath`
- Tkinter, which ships with most Python builds. On Debian/Ubuntu it is a
separate package:
```sh
sudo apt install python3-tk
```
Install the Python dependencies with:
```sh
pip install -r requirements.txt
```
## Running
```sh
python bd_fresnel_gui.py
```
The window opens with the parameter panel on the left and three tabs on the
right: **Fitting**, **Diagnostics**, and **Parameter log**.
Fitting a measured scan:
1. Under **Operation mode**, choose **Beam deflection** or **Pump probe**,
leave the second toggle on **Fitting**, and pick an algorithm on the third:
**Fresnel propagation** or the faster **Semi-analytical**.
2. Set the **Data columns** to match your file, and the delimiter.
3. Press **Import…** and choose a scan. The plots show the measured data.
4. Fill in the beam, material and geometry parameters, and configure one or
more mechanisms with the **Params…** buttons.
5. Press **Fit** to run the simulation and overlay it on the data.
6. Press **Export…** to write the results.
Simulating without a measurement:
1. Under **Operation mode**, choose **Simulation**. **Import…** and the data
column fields are disabled, and **Fit** becomes **Simulate**. The algorithm
toggle works the same way as in Fitting mode.
2. Set `T_d_min` and `T_d_max` in **Simulation parameters** to the delay range
to compute over. In Fitting mode these come from the imported file, so they
are editable only here.
3. Fill in the parameters and mechanisms as above.
4. Press **Simulate**, then **Export…**.
**Fit** stays disabled until a file is imported; **Simulate** needs only valid
parameters. **Export** stays disabled until a fit or simulation has completed.
Changing the mode, a column number or the delimiter re-reads the imported file.
Any fit is discarded, since it belonged to the previous settings. If the file
cannot be read with the new settings, its data is cleared rather than left on
screen, and it is read again once the settings allow.
Parameters are saved to `last_settings.json` beside the scripts when they
change, and restored at the next launch. The data file itself is not restored.
## Input data format
A delimited text file with one header line, then one row per delay point. Beam
deflection needs three columns and pump probe two; which ones is set in the
**Data columns** box, so extra columns can be present and ignored. Each
quantity must come from a different column.
| Quantity | Units | Default column | Needed in |
|----------|------------------------------|----------------|----------------------|
| `τ_d` | fs | 1 | both modes |
| `ΔE/E` | fractional | 2 | Beam deflection only |
| `T` | fractional (1.0 = no change) | 3 | both modes |
The delimiter field takes a single character, `\t` for a tab, or is left blank
to split on any run of whitespace.
## Parameters
### Data columns (1-indexed)
| Variable | Default | Column contents |
|-------------------|---------|---------------------------------|
| `tau_d column` | `1` | Delay column (fs) |
| `T column` | `3` | Transmission data column |
| `DeltaEoE column` | `2` | Deflection data column |
| `Delimiter` | `,` | Data column delimiter character |
### Operation mode
Three independent toggles. Any combination is valid.
| Toggle | Option | Effect |
|-------------|-----------------------|--------------------------------------------------|
| Measurement | `Beam deflection` | Transmission and deflection, offset probe |
| | `Pump probe` | Transmission only, centered probe |
| Run | `Fitting` | Compare the calculation against an imported scan |
| | `Simulation` | Calculate without a scan, over an entered range |
| Algorithm | `Fresnel propagation` | Propagate the exit field to the detector by FFT |
| | `Semi-analytical` | Closed-form detector power, no spatial grid |
#### Algorithm
**Fresnel propagation** is the original method. The field at the exit face is
built on an (x, y) grid, propagated to the detector by FFT, and integrated over
the detector halves to get the power difference and total at each instant.
**Semi-analytical** skips the propagation. It evaluates closed-form expressions
for the detector power difference `dP` and total `P`, already integrated over
the detector plane, then integrates each over time at every delay to get the
energy difference `dE` and total `E`. The deflection is `dE/E` and the
transmission is `E` normalised. With no spatial grid to size, `X_num` and
`X_max` are greyed out; every other parameter, `Delta_n` included, is
unaffected. On the four-layer graphene example it runs in 0.11 s against 3.65 s,
about **32x faster**.
The trade-off is that `dP` is **first order in the nonlinear response**, where
the Fresnel path keeps every order. The two therefore agree only while the
phase is small, which the `eta (peak)` line of the parameter log reports:
| `eta (peak)` | Peak of `DeltaEoE` displaced by |
|--------------|---------------------------------|
| 0.14 rad | 0.0003 tau_e |
| 1.41 rad | 0.0035 tau_e |
| 5.64 rad | 0.077 tau_e |
| 14.1 rad | 0.36 tau_e |
Below roughly 1 rad the two are interchangeable, and the four-layer graphene
example sits at 0.049 rad with a correlation of 1.000000 and amplitudes within
0.5%. Above a few rad the semi-analytical curve shifts noticeably and is no
longer a substitute. Sample thickness, walk-off and pump absorption do not
themselves affect the agreement once `eta (peak)` is held fixed.
The remaining 0.5% amplitude offset is the on-axis approximation: the Fresnel
path attenuates by `exp(-2 a_e^2 Gamma)` across the probe profile, where `a_e`
is the pump amplitude profile, while the semi-analytical form uses the on-axis
`exp(-2 x_0^2)`.
One coefficient in `dP`'s absorptive term, `SA_ABSORPTIVE_FACTOR`, is at present
fitted against the Fresnel path rather than derived. It is isolated in a single
function in `bd_fresnel_core.py`, with the measurements behind it recorded
there.
The transmission needs a reference delay, taken from before the pump arrives.
In **Fitting** mode it is the first delay point of the imported scan; in
**Simulation** mode it is `min(-3 rho, -3)` tau_e, which follows the walk-off
when that is the larger scale and is three pulse widths otherwise, so a thin
sample still normalises away from the peak.
### Simulation parameters
| Variable | Default | Column contents |
|-----------|---------|-------------------------------------------------|
| `X_num` | `50` | Number of spatial points, Fresnel only |
| `X_max` | `5.0` | Range of spatial sampling (w_0_p), Fresnel only |
| `T_num` | `100` | Number of temporal points |
| `T_max` | `5.0` | Range of temporal sampling (tau_e) |
| `T_d_num` | `150` | Number of delay points over range |
| `T_d_min` | `-5.0` | Delay range start (tau_e), Simulation only |
| `T_d_max` | `5.0` | Delay range end (tau_e), Simulation only |
`X_num` and `X_max` size the spatial grid the Fresnel method propagates, so the
semi-analytical method greys them out.
### Excitation beam parameters
| Variable | Default | Column contents |
|--------------|---------|----------------------------------|
| `E_e` | `1.36` | Excitation pulse energy (uJ) |
| `tau_e_FWHM` | `55.0` | Excitation pulse duration (fs) |
| `w_0_e` | `246.0` | Excitation beam waist (um) |
| `lambda_e` | `800.0` | Excitation pulse wavelength (nm) |
### Probe beam parameters
| Variable | Default | Column contents |
|--------------|---------|-----------------------------|
| `tau_p_FWHM` | `60.0` | Probe pulse duration (fs) |
| `w_0_p` | `43.0` | Probe beam waist (um) |
| `lambda_p` | `650.0` | Probe pulse wavelength (nm) |
### Material parameters at excitation wavelength
| Variable | Default | Column contents |
|--------------|-------------|--------------------------------|
| `R_e` | `0.0` | Reflectivity |
| `alpha_e` | `0.0` | Linear absorption (cm^-1) |
| `n_e` | `1.4533` | Linear index |
| `dndl_e` | `-0.017284` | First order dispersion (um^-1) |
| `alpha_2d_e` | `0.0` | 2 photon absorption (e-11 m/W) |
### Material parameters at probe wavelength
| Variable | Default | Column contents |
|-----------|-------------|--------------------------------|
| `R_p` | `0.0` | Reflectivity |
| `alpha_p` | `0.0` | Linear absorption (cm^-1) |
| `n_p` | `1.4565` | Linear index |
| `dndl_p` | `-0.027158` | First order dispersion (um^-1) |
### Measurement parameters
| Variable | Default | Column contents |
|----------|---------|-------------------------------|
| `l` | `1.0` | Sample thickness (mm) |
| `d` | `15.0` | Distance to detector (cm) |
| `shift` | `0.0` | Temporal shift (fs) |
| `x_0` | `0.5` | Displacement of probe (w_0_e) |
## Mechanisms
| Mechanism | Parameters |
|--------------------------------|------------|
| Electronic (both) | 2 |
| Collisional (NLR) | 3 |
| Librational (NLR) | 4 |
| Reorientational (NLR) | 3 |
| Vibrational (NLR) | 3 |
| ESA – 3 level + triplet (both) | 10 |
| Exponential rise/decay (NLA) | 3 |
| Exponential rise/decay (NLR) | 3 |
| Exponential rise/decay (both) | 4 |
`NLR` denotes a purely refractive response, `NLA` a purely absorptive one, and
`both` a mechanism carrying each.
Pump probe offers only the `NLA` and `both` mechanisms: with the probe centred,
a `both` mechanism contributes its absorptive part, and an `NLR` mechanism
cannot change the transmission at all. Switching to Pump probe sets aside any
`NLR` mechanism already chosen; switching back restores it, provided its slot
is still empty.
## Export output
Exporting to `<name>_fit.txt` also writes, in the same directory:
| File | Contents |
|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| `<name>_fit.txt` | delay, data and fit for `T`, `ΔE/E` and `Δn`; in Pump probe, delay and `T` only. In Simulation, the calculated signals alone |
| `<name>_fit_log.txt` | every parameter, plus a manifest of the files written |
| `<name>_fit_combined.jpg` / `.svg` | transmission and deflection, 6.5 in at 300 dpi (Beam deflection) |
| `<name>_fit_transmission.jpg` / `.svg` | transmission only, 3.25 in at 300 dpi (Pump probe) |
| `<name>_fit_raw_response.jpg` | each mechanism's `R[t]` and `A[t]` |
| `<name>_fit_convolved_response.jpg` | the same after convolution, plus the total |
The last two appear only when *Show diagnostic plots during Fit* is ticked.
In Simulation mode the export is named after the file you choose rather than an
imported scan, and the table holds the calculated signals on their own delay
grid, with no data columns to pair them with.
The log records enough to reproduce a run: both modes, the data columns and
delimiter, the simulation grid including the delay range, every beam, material
and geometry value, each mechanism with its parameters, and the derived
quantities (`n_g`, `T_lin`, `z_0`, `I_0`, `rho`). In Simulation mode the import
path and data column sections are omitted, having nothing to describe.
## Files
| File | Role |
|------------------------|--------------------------------------------------------------------------------------------------------------------------|
| `bd_fresnel_core.py` | physics: field propagation, mechanism responses, ESA solver, parameter dataclass, settings I/O. No display dependencies. |
| `bd_fresnel_gui.py` | Tkinter interface, plotting, import/export, logging. Entry point. |
| `set_params_dialog.py` | modal dialog for entering one mechanism's parameters. |
## References
Please cite the following when using results from this program.
1. M. Reichert, H. Hu, M. R. Ferdinandus, M. Seidel, P. Zhao, T. R. Ensley,
D. Peceli, J. M. Reed, D. A. Fishman, S. Webster, D. J. Hagan, and
E. W. Van Stryland, “Temporal, spectral, and polarization dependence of the
nonlinear optical response of carbon disulfide,” Optica **1**, 436–445 (2014).
2. M. R. Ferdinandus, H. Hu, M. Reichert, D. J. Hagan, and E. W. Van Stryland,
“Beam deflection measurement of time and polarization resolved ultrafast
nonlinear refraction,” Opt. Lett. **38**, 3518–3521 (2013).
## License
Copyright (C) 2019-2026 Manuel R. Ferdinandus
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
NumPy, SciPy, Matplotlib and mpmath are all BSD-licensed, so distributing this program
under the GPL alongside them poses no conflict.