Compare commits
29
Commits
add_readme
...
520542ee1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
520542ee1b | ||
|
|
1bc882e163 | ||
|
|
50d0d27464 | ||
|
|
45efc8239d | ||
|
|
d7ab1b823e | ||
|
|
98e95180cc | ||
|
|
38c09a4272 | ||
|
|
cc67401de9 | ||
|
|
6d7996ff30 | ||
|
|
61dbd0452b | ||
|
|
667c37fcb5 | ||
|
|
526185a980 | ||
|
|
f593c3ff07 | ||
|
|
cc5f7622cf | ||
|
|
4c4ec2d1ce | ||
|
|
7cd523b5db | ||
|
|
5d8a132031 | ||
|
|
32f335562f | ||
|
|
a6b56dabe3 | ||
|
|
f3a760bc62 | ||
|
|
81c7c3234c | ||
|
|
1f324d678c | ||
|
|
56430a6202 | ||
|
|
c1187cd846 | ||
|
|
03acb17de4 | ||
|
|
bc06521601 | ||
|
|
6cf2bf4b8a | ||
|
|
cb12b8cfc7 | ||
|
|
67dbda7c19 |
+359
@@ -0,0 +1,359 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to BD Fresnel are documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
## [3.0] - 2026-11-14
|
||||
|
||||
### Added
|
||||
|
||||
- **Semi-analytical** algorithm, selectable from a third toggle in the
|
||||
Operation mode box alongside **Fresnel propagation**:
|
||||
- Instead of propagating the exit field to the detector by FFT, it
|
||||
uses closed-form expressions for the power difference and total at
|
||||
the detector, already integrated over the detector plane. Only an
|
||||
integral over time at each delay remains.
|
||||
- The time window runs +/- 5T about each delay, where T = tau_p/tau_e.
|
||||
- Transmission is the energy total normalised to its value before the
|
||||
pump arrives: the first delay point when fitting, and
|
||||
min(-3 rho, -3) tau_e when simulating, so a thin sample with
|
||||
rho -> 0 still normalises away from the peak.
|
||||
- `X_num` and `X_max` are disabled in this mode: the expressions are
|
||||
already integrated over space, so there is no spatial grid.
|
||||
- Applies to both measurement modes. In pump probe the probe is
|
||||
centred, x_0 = 0, so the deflection term vanishes identically and
|
||||
the transmission alone is calculated.
|
||||
- Both algorithms are kept so results can be compared. Switching
|
||||
discards the current result, which belongs to the other method.
|
||||
- The algorithm is saved with the other settings and recorded in the
|
||||
parameter log.
|
||||
- The absorptive term in the deflection expression carries a
|
||||
PROVISIONAL coefficient, `SA_ABSORPTIVE_FACTOR`. As derived, that
|
||||
term matched neither the sign nor the magnitude of the Fresnel
|
||||
result: a purely absorptive mechanism disagreed by a factor of
|
||||
about -69, with correlation exactly -1. Dividing by
|
||||
D = d / (pi w_0_p^2 / lambda_p) = d / z_0_p accounts for the distance and
|
||||
wavelength dependence exactly, and is independent of sample
|
||||
thickness at constant alpha_2_exp*l; the remaining -1/(1 + 2W^2) was
|
||||
measured against the Fresnel path rather than derived. With it the
|
||||
two methods agree to 0.5% for mechanisms with a refractive part and
|
||||
4.5% for purely absorptive ones. It is isolated in one function
|
||||
pending a corrected derivation.
|
||||
|
||||
- The parameter log's `Calculated Parameters (pump)` section reports
|
||||
`sigma_e`, the normalised pump linear absorption `alpha_e * L / 2`.
|
||||
It sits next to `T_lin`, which restates it: with no pump two-photon
|
||||
absorption `T_lin = (1 - R_p) exp(-2 sigma_e)`. Read from the
|
||||
parameters rather than the result, so it is reported for either
|
||||
algorithm.
|
||||
|
||||
- The `Other` panel and the parameter log's `Other` section both report
|
||||
`eta (peak)` and `Gamma (peak)`, the largest nonlinear phase and
|
||||
absorption exponent anywhere on the grid, from whichever algorithm
|
||||
produced the result. These are the only readouts in those panels that
|
||||
come from the result rather than from the parameters, since they are
|
||||
peaks over the whole (T, T_d) grid and cannot be had without running
|
||||
the calculation. They therefore show `--` until a Fit or Simulate
|
||||
completes, and return to `--` whenever that result is discarded, so a
|
||||
stale phase is never displayed beside freshly edited parameters.
|
||||
`eta (peak)` is the yardstick for the semi-analytical algorithm's
|
||||
validity: its `dP` is first order in the response while Fresnel
|
||||
propagation keeps every order, so the two agree only while the phase
|
||||
is small. On the 4-layer mechanisms the peak of `DeltaEoE` sits at
|
||||
the same delay to within 0.0003 tau_e at `eta (peak)` = 0.14, but
|
||||
0.0035 at 1.41, 0.077 at 5.6 and 0.36 at 14.1. Holding `eta (peak)`
|
||||
fixed, the agreement is unaffected by sample thickness (0.05 to
|
||||
2 mm), by walk-off (`rho` 0.04 to 1.7) and by pump absorption
|
||||
(`sigma_e` 0 to 10), so this one number sets the regime. Both
|
||||
algorithms report it to within 2e-5 of each other.
|
||||
|
||||
### Changed
|
||||
|
||||
- **Both beams are now explicitly subscripted: the pump carries `_e`
|
||||
(excitation) and the probe carries `_p`.** This restores the
|
||||
convention the original MATLAB used, which the Python port had
|
||||
partly inverted (`_p` for the pump) and partly dropped (no suffix
|
||||
for the probe). No beam quantity is unsubscripted any more; the only
|
||||
unsuffixed parameters left are the ones belonging to neither beam --
|
||||
the sampling grid, the sample geometry (`l`, `d`, `shift`), the
|
||||
relative offset `x_0`, and the walk-off `rho`.
|
||||
|
||||
| pump: was | now | | probe: was | now |
|
||||
|-----|-----|-|-----|-----|
|
||||
| `E_p` | `E_e` | | `tau_FWHM` | `tau_p_FWHM` |
|
||||
| `tau_p_FWHM` | `tau_e_FWHM` | | `w_0` | `w_0_p` |
|
||||
| `w_0p` | `w_0_e` | | `lambda_` | `lambda_p` |
|
||||
| `lambda_p` | `lambda_e` | | `R` | `R_p` |
|
||||
| `R_p` | `R_e` | | `alpha` | `alpha_p` |
|
||||
| `alpha_p` | `alpha_e` | | `n` | `n_p` |
|
||||
| `n_p` | `n_e` | | `dndl` | `dndl_p` |
|
||||
| `dndl_p` | `dndl_e` | | `tau` | `tau_p` |
|
||||
| `alpha_2d` | `alpha_2d_e` | | `ng` | `ng_p` |
|
||||
| `tau_p` | `tau_e` | | `z_0` | `z_0_p` |
|
||||
| `sigma_p` | `sigma_e` | | `Tlin` | `Tlin_p` |
|
||||
| `I_0_p` | `I_0_e` | | | |
|
||||
| `ng_p` | `ng_e` | | | |
|
||||
| `z_0_p` | `z_0_e` | | | |
|
||||
| `Tlin_p` | `Tlin_e` | | | |
|
||||
| `sigma_p2` / `sigma_p20` | `sigma_e2` / `sigma_e20` | | | |
|
||||
| `a_p_0`, `W_0_p`, `I_p_pulse` | `a_e_0`, `W_0_e`, `I_e_pulse` | | | |
|
||||
|
||||
Note that six probe names -- `tau_p_FWHM`, `lambda_p`, `R_p`,
|
||||
`alpha_p`, `n_p`, `dndl_p` -- are spelled exactly like what were
|
||||
**pump** names before this release. Reading an old log or settings
|
||||
file alongside a new one needs care; see the settings note below for
|
||||
how the program itself is protected.
|
||||
|
||||
The pump pass renamed 389 identifier occurrences textually; the
|
||||
probe pass was done by rewriting 116 exact AST node positions
|
||||
instead, because `n`, `R`, `alpha` and `tau` are overloaded in this
|
||||
codebase (lambda parameters, the author's initials in the copyright
|
||||
line, the semi-analytical formula's geometric `R`, a diagnostics
|
||||
dict key) and no text pattern distinguishes them.
|
||||
|
||||
| was | now | | was | now |
|
||||
|-----|-----|-|-----|-----|
|
||||
| `E_p` | `E_e` | | `tau_p` | `tau_e` |
|
||||
| `tau_p_FWHM` | `tau_e_FWHM` | | `sigma_p` | `sigma_e` |
|
||||
| `w_0p` | `w_0_e` | | `I_0_p` | `I_0_e` |
|
||||
| `lambda_p` | `lambda_e` | | `ng_p` | `ng_e` |
|
||||
| `R_p` | `R_e` | | `z_0_p` | `z_0_e` |
|
||||
| `alpha_p` | `alpha_e` | | `Tlin_p` | `Tlin_e` |
|
||||
| `n_p` | `n_e` | | `sigma_p2` | `sigma_e2` |
|
||||
| `dndl_p` | `dndl_e` | | `sigma_p20` | `sigma_e20` |
|
||||
| `alpha_2d` | `alpha_2d_e` | | `a_p_0` | `a_e_0` |
|
||||
|
||||
`w_0p` gains the separating underscore it was missing, so the field
|
||||
name finally matches the variable that held it (`w_0_p`) and its
|
||||
siblings `z_0_e` and `I_0_e`. `alpha_2d_e` keeps the `d` for
|
||||
degenerate.
|
||||
|
||||
- **The Electronic mechanism's parameters are renamed `alpha_2e` ->
|
||||
`alpha_2el` and `n_2e` -> `n_2el`**, since their `e` meant
|
||||
*electronic* and would otherwise collide with `_e` for excitation --
|
||||
the pump's degenerate two-photon coefficient would have wanted the
|
||||
name `alpha_2e`, which was taken. `_e` now means excitation and
|
||||
nothing else.
|
||||
|
||||
- `BD_3_level_triplet`, `I_e_func` and `excite_prop` needed no
|
||||
renaming at all: transliterated from the MATLAB, they already used
|
||||
`_e` for the pump and `_p` for the probe, so `n_g_p`, `v_p` and
|
||||
`I_p` inside them were correct all along. With both beams now
|
||||
subscribed to that convention, the whole file reads against the
|
||||
MATLAB without translation.
|
||||
|
||||
- **`last_settings.json` written by an earlier version is now refused
|
||||
rather than misread.** Saved settings carry a `settings_schema`
|
||||
stamp, and a file without the current one is rejected with a message
|
||||
explaining why. This is not housekeeping: because six probe field
|
||||
names are spelled exactly like former pump keys, loading an old file
|
||||
by name alone would have installed the pump's wavelength, index,
|
||||
reflectivity, absorption and dispersion as the *probe's* -- every
|
||||
number plausible, every result wrong. Re-enter the parameters once
|
||||
and they save in the new layout. Any other unrecognised key is still
|
||||
dropped with a note on stderr.
|
||||
|
||||
- Log and panel labels follow their fields on both sides: `n_g_e`,
|
||||
`sigma_e`, `T_lin_e`, `z_0_e`, `I_0_e` for the pump and `n_g_p`,
|
||||
`T_lin_p`, `z_0_p` for the probe, with the beam parameters and
|
||||
material blocks likewise. The GUI's pump calculated-parameters panel
|
||||
also gains a `sigma_e` readout, which it had not displayed before.
|
||||
|
||||
- `T_lin_p` and `T_lin_e` are labelled `T_lin_p (transmission)` and
|
||||
`T_lin_e (transmission)` in both the panel and the log, so the
|
||||
quantity is named and not just abbreviated. The log's value column
|
||||
moved from 25 to 29 to fit them, and the panel's label column from 20
|
||||
to 23 characters -- which also squares up `z_0_p (Rayleigh range)`,
|
||||
`z_0_e (Rayleigh range)` and `I_0_e (peak irradiance)`, all of which
|
||||
had been overrunning the old 20 and pushing their own values out of
|
||||
line.
|
||||
|
||||
- The rename is numerically inert: across 8 mechanism types x 2
|
||||
algorithms x 3 pump-absorption configurations (49 cases, 3275
|
||||
values), `DeltaEoE`, `T`, `Delta_n`, `eta_peak` and `Gamma_peak` are
|
||||
bit-identical to the pre-rename code, and `pyflakes` reports zero
|
||||
warnings before and after.
|
||||
|
||||
- Transmission y-axis tick labels are limited to three significant
|
||||
digits, so "99.75" reads "99.8". The count is a floor rather than a
|
||||
cap: a shallow scan spanning a few hundredths of a percent would
|
||||
round every tick to "100", so digits are added only where that would
|
||||
happen. The deflection axis is unaffected.
|
||||
|
||||
- The reference list in the README and the parameter log follows Optica
|
||||
style: every author listed, initials first, abbreviated journal,
|
||||
volume, full page range, year. Author lists and page ranges were
|
||||
checked against the published papers.
|
||||
- The duplicate supplementary-material citation is dropped, leaving two
|
||||
references.
|
||||
- The parameter log is written as UTF-8. The citations use typographic
|
||||
quotes and an en dash, which the locale's encoding cannot always
|
||||
represent.
|
||||
|
||||
### Fixed
|
||||
|
||||
- The instantaneous (Electronic) response for a sample with both
|
||||
walk-off and pump absorption is evaluated through the scaled
|
||||
complementary error function `erfcx` instead of the form in
|
||||
`BD_Fresnel_func_ni.m`. That form multiplied `exp(sigma_e^2/rho^2 +
|
||||
2 sigma_e u/rho)` by a difference of error functions falling to zero,
|
||||
so the product was lost to cancellation well before it overflowed:
|
||||
at `rho = 0.4336` (l = 0.5 mm) it was already wrong over 8.6% of the
|
||||
delay axis at `sigma_e = 2.5` (alpha_e = 100 cm^-1), **returning
|
||||
exactly 0.0 with no NaN to signal it**, and returned NaN above
|
||||
`sigma_e = 3`. The usable ceiling on `alpha_e` for an Electronic
|
||||
mechanism at that thickness was therefore about 60 cm^-1, not the
|
||||
~120 where NaN first appeared. The rearrangement is algebraic, with
|
||||
every surviving exponent non-positive; it reproduces the original
|
||||
evaluated at 600 decimal digits to 1e-16..3e-13 relative over
|
||||
`sigma_e` = 0.25 to 10 and `u` = -3 to 18, both where the original
|
||||
works and where it does not.
|
||||
- Pump absorption is applied to non-instantaneous mechanisms when the
|
||||
walk-off is exactly zero. Substituting `T1 = (T+T_d) - rho +
|
||||
rho*zeta` shows the `rho != 0` branch to be a depth average over
|
||||
`atten_fac`, whose `rho -> 0` limit is the response at one instant
|
||||
times the *mean* of `atten_fac`; the original used the bare response.
|
||||
The dropped factor is `(1 - exp(-2 sigma_e))/(2 sigma_e)` for linear
|
||||
pump absorption, so the response was previously **independent of
|
||||
`alpha_e` altogether** in this case -- identical at `alpha_e` = 0 and
|
||||
200 cm^-1. It was 1.27x too large at `alpha_e` = 10 cm^-1 and
|
||||
l = 0.5 mm, and 10x at 200 cm^-1. The two branches now agree to nine
|
||||
digits across `rho = 0`. This affects only samples with `ng_p` exactly
|
||||
equal to `ng_e` (for example no dispersion entered at either
|
||||
wavelength) *and* non-zero pump absorption; with `alpha_e = alpha_2d_e
|
||||
= 0` the mean is exactly 1 and results are bit-identical to before.
|
||||
- Pump absorption through the sample depth, `atten_fac`, is computed
|
||||
from the closed-form solution of
|
||||
`dI_e/dz = -alpha_e I_e - alpha_2d_e I_e^2` rather than the two-branch
|
||||
expression carried over from `BD_Fresnel_func_ni.m`. That expression's
|
||||
pump two-photon branch, `sqrt((B1 B2)/sigma_e)`, failed three ways: it
|
||||
did not reduce to its own `sigma_e2 == 0` branch as `alpha_2d_e -> 0`
|
||||
(it decayed at half the correct rate), it divided by zero whenever
|
||||
`alpha_e` was zero, and it took the square root of a negative number
|
||||
whenever `sigma_e20 > sigma_e`. The net effect was that **every run
|
||||
combining a non-zero `alpha_2d_e` with a non-instantaneous mechanism
|
||||
returned NaN at every delay** -- pump two-photon absorption worked
|
||||
only for the Electronic mechanism, which does not use `atten_fac`.
|
||||
Dropping the stray square root recovers that expression as the
|
||||
linearisation of the exact one in `sigma_e20`, which is how the
|
||||
intent was identified. Results for `alpha_2d_e = 0` are bit-identical
|
||||
to before; the new form agrees with numerical integration of the
|
||||
pump propagation equation to 2e-12 relative over `sigma_e` and
|
||||
`sigma_e20` from 0 to 20, including both limits.
|
||||
- A negative `alpha_2d_e` large enough to make the pump diverge inside
|
||||
the sample (two-photon gain, no finite depth average) is now refused
|
||||
with a message naming the largest `|alpha_2d_e|` that works for the
|
||||
current thickness and pump irradiance, rather than silently returning
|
||||
a meaningless attenuation of order 1e12.
|
||||
- `mpmath` is imported only where it is used, in the pump two-photon
|
||||
absorption term. Importing it at module level made an optional
|
||||
dependency fatal at startup, so the program would not run at all
|
||||
without it. If that term is ever reached without mpmath installed,
|
||||
the error now says which package is missing and why.
|
||||
|
||||
## [2.6] - 2026-09-30
|
||||
|
||||
### Added
|
||||
|
||||
- **Simulation** run mode: a second toggle in the Operation mode box,
|
||||
offering **Fitting** and **Simulation**. Fitting is the default and
|
||||
behaves as before.
|
||||
- Simulation mode, for computing a signal without a measurement:
|
||||
- No file is imported. **Import...** and the data column and
|
||||
delimiter fields are disabled.
|
||||
- The delay range is entered as `T_d_min` and `T_d_max` (in `tau_p`)
|
||||
in the Simulation parameters box. In Fitting mode these are taken
|
||||
from the imported scan and the fields are disabled.
|
||||
- Only the calculated curves are plotted, without data markers, and
|
||||
the plot legend reads **Simulated** rather than Fit.
|
||||
- The **Fit** button is relabelled **Simulate**, and is enabled by
|
||||
valid parameters alone rather than by an imported file.
|
||||
- The export holds the calculated signals on their own delay grid,
|
||||
with no data columns to pair them with. The parameter log omits the
|
||||
import path and the data column section.
|
||||
- The mode combines with the measurement mode: Pump probe and
|
||||
Simulation together give a single Transmission panel and a
|
||||
two-column table, as Pump probe does when fitting.
|
||||
- The run mode is saved with the other settings and recorded in the
|
||||
parameter log.
|
||||
|
||||
### Changed
|
||||
|
||||
- The **Mode** box is renamed **Operation mode** and moved to the top of
|
||||
the parameter panel, above Data columns. The parameter log and status
|
||||
messages use the new name, and the log records both modes on one line.
|
||||
- Changing run mode discards the current result, which described the
|
||||
other mode's delay range or a measurement the new mode does not show.
|
||||
Switching to Simulation sets the imported scan aside and switching
|
||||
back reloads it. The run mode cannot be changed while a fit runs.
|
||||
- `inputs_valid` takes a `require_data` argument, so Simulation can
|
||||
enable its action button without an imported file. Fitting is
|
||||
unaffected.
|
||||
|
||||
## [2.5] - 2026-09-21
|
||||
|
||||
### Added
|
||||
|
||||
- **Mode** box, below Data columns: a two-button toggle selecting
|
||||
**Beam deflection** or **Pump probe**. Beam deflection is the default
|
||||
and behaves as before.
|
||||
- Pump probe mode, for measurements with the probe centred on the pump:
|
||||
- Only the delay and transmission columns are required, so a
|
||||
two-column scan can be imported. The DeltaEoE column is ignored and
|
||||
its field disabled.
|
||||
- `x_0` is fixed at 0 and cannot be edited.
|
||||
- Only the Transmission plot is displayed and exported. The exported
|
||||
image is named `<name>_fit_transmission.jpg` / `.svg` and is 3.25 in
|
||||
wide, a single column. The exported data table holds delay, T (data)
|
||||
and T (fit).
|
||||
- The mechanism pull-downs offer the absorptive (NLA) and mixed
|
||||
(both) mechanisms; a mixed mechanism contributes its absorptive
|
||||
part. The purely refractive (NLR) mechanisms, which cannot change
|
||||
the transmission, are excluded. Switching to pump probe empties any
|
||||
slot holding one; switching back restores it, provided the slot is
|
||||
still empty.
|
||||
- The selected mode is saved with the other settings and recorded in the
|
||||
parameter log.
|
||||
|
||||
### Changed
|
||||
|
||||
- Changing mode discards the current fit, which was computed with the
|
||||
other mode's settings, and re-reads the imported file under the new
|
||||
mode's column requirements. A file the new mode cannot use is cleared
|
||||
with an explanation, and loaded again on switching back. The mode
|
||||
cannot be changed while a fit runs.
|
||||
- The source files carry the GPLv3 notice.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Values such as `nan`, `inf` or `1e999` are rejected in parameter fields.
|
||||
They previously turned the fit to NaN, and crashed the mechanism
|
||||
parameters dialog.
|
||||
- An invalid entry in a numeric field reverts to its previous value, as the
|
||||
integer fields and the mechanism dialog already did, instead of becoming 0.
|
||||
- Every parameter change is saved as it is made. Numeric fields, mechanism
|
||||
choices and the diagnostics option were previously saved only on Import,
|
||||
Fit, Export or Exit, so a crash lost them.
|
||||
- Changing a column number or the delimiter re-reads only a file imported in
|
||||
the current session. Straight after launch it could load the previous
|
||||
session's file, or report an error about one that had since moved.
|
||||
- When a file cannot be read with a new column number or delimiter, its data
|
||||
and fit are cleared. They previously stayed on screen, and could be
|
||||
exported, under settings that no longer described them.
|
||||
- The data columns in use must each be different. Two quantities could
|
||||
previously be read from the same column without any warning.
|
||||
- The x tick label at the join between the Transmission and Deflection plots
|
||||
is hidden when it collides with its neighbour. A rounding error let some
|
||||
such labels through.
|
||||
|
||||
## [2.4] - 2026-09-21
|
||||
|
||||
First release recorded in this changelog. Earlier history is not documented
|
||||
here.
|
||||
|
||||
### Fixed
|
||||
|
||||
- README parameter tables corrected to match the program's window: the
|
||||
default T and DeltaEoE data columns were swapped, and several defaults,
|
||||
labels and descriptions disagreed with what the interface shows.
|
||||
@@ -10,6 +10,15 @@ diffraction, and computes the transmission `T` and normalised beam deflection
|
||||
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.
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
@@ -22,7 +31,17 @@ publication-sized figures.
|
||||
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.
|
||||
- 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
|
||||
@@ -54,40 +73,192 @@ 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**.
|
||||
|
||||
A typical session:
|
||||
Fitting a measured scan:
|
||||
|
||||
1. Set the **Data columns** to match your file, and the delimiter.
|
||||
2. Press **Import…** and choose a scan. The plots show the measured data.
|
||||
3. Fill in the beam, material and geometry parameters, and configure one or
|
||||
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.
|
||||
4. Press **Fit** to run the simulation and overlay it on the data.
|
||||
5. Press **Export…** to write the results.
|
||||
5. Press **Fit** to run the simulation and overlay it on the data.
|
||||
6. Press **Export…** to write the results.
|
||||
|
||||
**Fit** stays disabled until a file is imported, and **Export** until a fit has
|
||||
completed.
|
||||
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. Three
|
||||
columns are required; which ones is set in the **Data columns** box, so extra
|
||||
columns can be present and ignored.
|
||||
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 |
|
||||
| --- | --- | --- |
|
||||
| Delay `τ_d` | fs | 1 |
|
||||
| `ΔE/E` | fractional | 2 |
|
||||
| `T` | fractional (1.0 = no change) | 3 |
|
||||
| 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 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 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 |
|
||||
@@ -101,65 +272,72 @@ to split on any run of whitespace.
|
||||
`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` |
|
||||
|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `<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 |
|
||||
| `<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.
|
||||
|
||||
The log records enough to reproduce a run: data columns and delimiter, the
|
||||
simulation grid, 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 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. |
|
||||
|
||||
## Notes on the port
|
||||
|
||||
The translation follows the MATLAB closely, including its array axis order, so
|
||||
that intermediate results can be compared directly. Places where this port
|
||||
deliberately differs are commented at the point of departure. The substantive
|
||||
ones:
|
||||
|
||||
- **Physical constants** are taken from `scipy.constants` rather than
|
||||
transcribed. The original hard-coded `c = 299797548` in `calc_beam_params`, a
|
||||
digit transposition of the correct value used elsewhere in the same codebase,
|
||||
and truncated Planck's constant to seven figures. Correcting the former
|
||||
shifts `rho` by about 1.7 × 10⁻⁵ relative.
|
||||
- **Delay-frame consistency**: the delay grid is derived from the shifted
|
||||
`τ_d`, matching what the plots and export compare against. The original used
|
||||
the unshifted values, a mismatch whenever `shift ≠ 0`.
|
||||
- **Diagnostic instantaneous response**: the original's diagnostic plot used
|
||||
`n_2e` where its four physics branches all used `2·n_2e`, so the plotted
|
||||
electronic curve was half the simulated one. The plot now matches the
|
||||
simulation.
|
||||
- **Dialog close**: closing the parameter dialog with the window button is
|
||||
treated as OK. In the original it left the caller's `uiwait` blocked forever.
|
||||
|
||||
## References
|
||||
|
||||
Please cite the following when using results from this program.
|
||||
|
||||
1. Reichert, M., et al. (2014). "Temporal, spectral, and polarization
|
||||
dependence of the nonlinear optical response of carbon disulfide."
|
||||
*Optica* **1**(6): 436.
|
||||
2. Reichert, M., et al. (2014). "Temporal, spectral, and polarization
|
||||
dependence of the nonlinear optical response of carbon disulfide:
|
||||
supplementary material." *Optica* **1**(6): 436.
|
||||
3. Ferdinandus, M. R., et al. (2013). "Beam deflection measurement of time and
|
||||
polarization resolved ultrafast nonlinear refraction." *Opt. Lett.*
|
||||
**38**(18): 3518–3521.
|
||||
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.
|
||||
|
||||
+737
-169
File diff suppressed because it is too large
Load Diff
+796
-163
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 355 KiB |
@@ -0,0 +1,165 @@
|
||||
{
|
||||
"E_e": 1.0,
|
||||
"tau_e_FWHM": 45.0,
|
||||
"w_0_e": 142.83,
|
||||
"lambda_e": 800.0,
|
||||
"tau_p_FWHM": 100.0,
|
||||
"w_0_p": 22.253,
|
||||
"lambda_p": 650.0,
|
||||
"R_e": 0.0,
|
||||
"alpha_e": 0.0,
|
||||
"n_e": 1.4533,
|
||||
"dndl_e": -0.017284,
|
||||
"alpha_2d_e": 0.0,
|
||||
"R_p": 0.0,
|
||||
"alpha_p": 0.0,
|
||||
"n_p": 1.4565,
|
||||
"dndl_p": -0.027158,
|
||||
"l": 1.72e-06,
|
||||
"d": 15.0,
|
||||
"shift": 70.0,
|
||||
"x_0": 0.5,
|
||||
"tau_e": 27.025254197695123,
|
||||
"tau_p": 60.05612043932249,
|
||||
"sigma_e": 0.0,
|
||||
"I_0_e": 651473158047437.0,
|
||||
"ng_e": 1.4671272,
|
||||
"ng_p": 1.4741526999999999,
|
||||
"rho": 0.8671350632529666,
|
||||
"z_0_p": 0.0023933909907098232,
|
||||
"z_0_e": 0.0801122184130848,
|
||||
"Tlin_p": 1.0,
|
||||
"Tlin_e": 1.0,
|
||||
"X_max": 5.0,
|
||||
"X_num": 50,
|
||||
"T_min": -5.0,
|
||||
"T_max": 5.0,
|
||||
"T_num": 100,
|
||||
"T_d_min": -9.579367435592124,
|
||||
"T_d_max": 39.791355601447556,
|
||||
"T_d_num": 150,
|
||||
"n_mech": 7,
|
||||
"mech": [
|
||||
{
|
||||
"name": "Exponential rise/decay (both)",
|
||||
"param": [
|
||||
3600.0,
|
||||
-200000.0,
|
||||
1.0,
|
||||
170.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Exponential rise/decay (both)",
|
||||
"param": [
|
||||
15000.0,
|
||||
-500000.0,
|
||||
0.1,
|
||||
10000.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "None (both)",
|
||||
"param": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "None (both)",
|
||||
"param": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "None (both)",
|
||||
"param": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "None (both)",
|
||||
"param": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "None (both)",
|
||||
"param": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
}
|
||||
],
|
||||
"col_tau_d": 1,
|
||||
"col_DeltaEoE": 2,
|
||||
"col_T": 3,
|
||||
"delimiter": ",",
|
||||
"diagnostics": true,
|
||||
"data_imported": true,
|
||||
"data_fit": true,
|
||||
"mode": "beam_deflection",
|
||||
"run_mode": "fitting",
|
||||
"algorithm": "semi_analytical",
|
||||
"x_0_beam_deflection": 0.5,
|
||||
"mech_beam_deflection": [],
|
||||
"filename": "20190802 - BD 4 layer run 2_DeltaEoE_subtraction.txt",
|
||||
"pathname": "/home/manuel/Documents/Projects/Code/BD_Fresnel_GUI/Test data/",
|
||||
"import_filepath": "/home/manuel/Documents/Projects/Code/BD_Fresnel_GUI/Test data/20190802 - BD 4 layer run 2_DeltaEoE_subtraction.txt",
|
||||
"settings_schema": 3
|
||||
}
|
||||
@@ -9,4 +9,9 @@
|
||||
numpy>=2.0
|
||||
scipy>=1.6
|
||||
matplotlib>=3.4
|
||||
|
||||
# Optional. Only needed for the pump two-photon absorption term
|
||||
# (alpha_2d_e != 0), which uses the polylogarithm Li_3/2. The core
|
||||
# imports it lazily, so the program runs without it until that term is
|
||||
# used, and then says so.
|
||||
mpmath>=1.2
|
||||
|
||||
+30
-3
@@ -1,5 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# BD Fresnel - mechanism parameter dialog
|
||||
#
|
||||
# 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/>.
|
||||
"""
|
||||
set_params_dialog.py
|
||||
=====================
|
||||
@@ -39,6 +55,7 @@ Usage:
|
||||
previous_mechanism=old_mech)
|
||||
"""
|
||||
|
||||
import math
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
@@ -102,6 +119,16 @@ class SetParamsDialog(tk.Toplevel):
|
||||
if self._entries and self._entries[0] is not None:
|
||||
self.after(10, self._entries[0].focus_set)
|
||||
|
||||
@staticmethod
|
||||
def _parse(text: str) -> float:
|
||||
"""float(), but rejecting what it accepts and no parameter can
|
||||
take: "nan", "inf", and overflows such as "1e999". Letting those
|
||||
through also crashed _format, which calls int() on the value."""
|
||||
value = float(text)
|
||||
if not math.isfinite(value):
|
||||
raise ValueError(f"{text!r} is not finite")
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def _format(value: float) -> str:
|
||||
# MATLAB's num2str-equivalent-enough default formatting.
|
||||
@@ -114,10 +141,10 @@ class SetParamsDialog(tk.Toplevel):
|
||||
if var is None:
|
||||
return
|
||||
try:
|
||||
value = float(var.get())
|
||||
value = self._parse(var.get())
|
||||
except ValueError:
|
||||
name = MECHANISM_PARAM_SPECS[self.mechanism_name][idx][0]
|
||||
print(f"set_params_dialog: '{name}' must be a real number; reverting.")
|
||||
print(f"set_params_dialog: '{name}' must be a finite real number; reverting.")
|
||||
value = self._last_valid[idx]
|
||||
self._last_valid[idx] = value
|
||||
var.set(self._format(value))
|
||||
@@ -128,7 +155,7 @@ class SetParamsDialog(tk.Toplevel):
|
||||
if var is None:
|
||||
continue
|
||||
try:
|
||||
values[i] = float(var.get())
|
||||
values[i] = self._parse(var.get())
|
||||
except ValueError:
|
||||
values[i] = self._last_valid[i]
|
||||
self.result = Mechanism(name=self.mechanism_name, param=values)
|
||||
|
||||
Reference in New Issue
Block a user