Upload files to "/"

This commit is contained in:
2026-11-16 17:40:21 +00:00
parent d7ab1b823e
commit 45efc8239d
4 changed files with 1245 additions and 276 deletions
+255 -112
View File
@@ -61,13 +61,15 @@ from bd_fresnel_core import (
MECHANISM_NAMES,
calc_beam_params,
inputs_valid,
BD_Fresnel_func_ni,
BD_Fresnel_run,
save_settings,
load_settings,
MODE_BEAM_DEFLECTION,
MODE_PUMP_PROBE,
RUN_MODE_FITTING,
RUN_MODE_SIMULATION,
ALGO_FRESNEL,
ALGO_SEMI_ANALYTICAL,
mechanism_names_for_mode,
set_mode,
)
@@ -81,9 +83,9 @@ SETTINGS_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "last_s
# bd_fresnel_core.calc_beam_params for why (faithfully preserved from
# the original, not a translation gap).
CALC_BEAM_PARAMS_FIELDS = {
"E_p", "tau_p_FWHM", "w_0p", "lambda_p",
"tau_FWHM", "w_0", "lambda_",
"R_p", "R", "alpha", "alpha_p", "n", "dndl", "n_p", "dndl_p", "alpha_2d",
"E_e", "tau_e_FWHM", "w_0_e", "lambda_e",
"tau_p_FWHM", "w_0_p", "lambda_p",
"R_e", "R_p", "alpha_p", "alpha_e", "n_p", "dndl_p", "n_e", "dndl_e", "alpha_2d_e",
}
# (field, label, unit, abs_on_entry, log_name) -- mirrors each
@@ -95,34 +97,34 @@ CALC_BEAM_PARAMS_FIELDS = {
# validation there is permissive -- only NaN is actually rejected at
# entry, faithfully preserved).
PUMP_FIELDS = [
("E_p", "E_p (pump energy)", "uJ", True),
("tau_p_FWHM", "tau_p_FWHM", "fs", True),
("w_0p", "w_0p (pump waist)", "um", True),
("lambda_p", "lambda_p (pump)", "nm", True),
("E_e", "E_e (pump energy)", "uJ", True),
("tau_e_FWHM", "tau_e_FWHM", "fs", True),
("w_0_e", "w_0_e (pump waist)", "um", True),
("lambda_e", "lambda_e (pump)", "nm", True),
]
PROBE_FIELDS = [
("tau_FWHM", "tau_FWHM", "fs", True),
("w_0", "w_0 (probe waist)", "um", True),
("lambda_", "lambda (probe)", "nm", True),
("tau_p_FWHM", "tau_p_FWHM", "fs", True),
("w_0_p", "w_0_p (probe waist)", "um", True),
("lambda_p", "lambda_p (probe)", "nm", True),
]
MAT_PUMP_FIELDS = [
("R_e", "R_e (reflectivity)", "0-1", True),
("alpha_e", "alpha_e (absorption)", "cm^-1", True),
("n_e", "n_e (index)", "", True),
("dndl_e", "dndl_e (dispersion)", "um^-1", False),
("alpha_2d_e", "alpha_2d_e (2PA)", "e-11 m/W", False),
]
MAT_PROBE_FIELDS = [
("R_p", "R_p (reflectivity)", "0-1", True),
("alpha_p", "alpha_p (absorption)", "cm^-1", True),
("n_p", "n_p (index)", "", True),
("dndl_p", "dndl_p (dispersion)", "um^-1", False),
("alpha_2d", "alpha_2d (2PA)", "e-11 m/W", False),
]
MAT_PROBE_FIELDS = [
("R", "R (reflectivity)", "0-1", True),
("alpha", "alpha (absorption)", "cm^-1", True),
("n", "n (index)", "", True),
("dndl", "dndl (dispersion)", "um^-1", False),
]
SYSTEM_FIELDS = [
("l", "l (thickness)", "mm", True),
("d", "d (sample->detector)", "cm", True),
("shift", "shift (delay zero)", "fs", False),
("x_0", "x_0 (pump-probe offset)", "w_0p", False),
("x_0", "x_0 (pump-probe offset)", "w_0_e", False),
]
# Escape sequences accepted in the Delimiter field. A literal tab
@@ -155,12 +157,12 @@ def describe_delimiter(text: str) -> str:
# scan's delay range and the fields are disabled.
SIM_FIELDS = [
("X_num", "X_num (spatial pts)", "points", "int"),
("X_max", "X_max (spatial extent)", "w_0", "float"),
("X_max", "X_max (spatial extent)", "w_0_p", "float"),
("T_num", "T_num (time pts)", "points", "int"),
("T_max", "T_max (time extent)", "tau_p", "float"),
("T_max", "T_max (time extent)", "tau_e", "float"),
("T_d_num", "T_d_num (delay pts)", "points", "int"),
("T_d_min", "T_d_min (delay start)", "tau_p", "signed"),
("T_d_max", "T_d_max (delay end)", "tau_p", "signed"),
("T_d_min", "T_d_min (delay start)", "tau_e", "signed"),
("T_d_max", "T_d_max (delay end)", "tau_e", "signed"),
]
# The numeric parameter boxes, in panel order. Each entry is
@@ -208,6 +210,15 @@ RUN_MODE_CHOICES = [
]
RUN_MODE_LABELS = dict(RUN_MODE_CHOICES)
# The algorithm toggle, drawn below the run-mode one. Fresnel
# propagation is the original method; Semi-analytical uses closed-form
# detector expressions and integrates only over time.
ALGO_CHOICES = [
(ALGO_FRESNEL, "Fresnel propagation"),
(ALGO_SEMI_ANALYTICAL, "Semi-analytical"),
]
ALGO_LABELS = dict(ALGO_CHOICES)
# Which column of the imported file feeds each quantity. 1-based, in
# the order they are shown in the "Data columns" box.
DATA_COLUMN_FIELDS = [
@@ -286,11 +297,19 @@ class LabeledEntry(ttk.Frame):
class LabeledStatic(ttk.Frame):
"""Read-only calculated-value display (e.g. rho, I_0_p)."""
"""Read-only calculated-value display (e.g. rho, I_0_e)."""
# Widest label in use is "I_0_e (peak irradiance)" at 23
# characters. The width is a minimum request, not a clip, so a
# label longer than this does not truncate -- it pushes its own
# value right and breaks the column alignment, which is what
# happened when the T_lin labels gained "(transmission)".
LABEL_WIDTH = 23
def __init__(self, parent, label):
super().__init__(parent)
ttk.Label(self, text=label, width=20, anchor="w").pack(side="left")
ttk.Label(self, text=label, width=self.LABEL_WIDTH,
anchor="w").pack(side="left")
self.var = tk.StringVar(value="--")
ttk.Label(self, textvariable=self.var, width=16, anchor="w",
foreground="black").pack(side="left")
@@ -398,7 +417,7 @@ class BDFresnelApp(tk.Tk):
self.params = self._load_or_default_params()
self.data = None # dict with tau_d, tau_d_shifted, T, DeltaEoE, Delta_n
self.fit = None # dict, output of BD_Fresnel_func_ni
self.fit = None # dict, output of BD_Fresnel_run
# The file loaded this session, if any. A mode change re-reads
# it, since the two modes need different columns. Kept even if
# that re-read fails, so switching back can load it again.
@@ -564,6 +583,10 @@ class BDFresnelApp(tk.Tk):
self._run_mode_buttons = self._build_toggle_row(
sec, RUN_MODE_CHOICES, self.run_mode_var, self._on_run_mode_change,
pady=(3, 0))
self.algorithm_var = tk.StringVar(value=self.params.algorithm)
self._algorithm_buttons = self._build_toggle_row(
sec, ALGO_CHOICES, self.algorithm_var, self._on_algorithm_change,
pady=(3, 0))
sec = add_section(parent, "Data columns")
for name, label in DATA_COLUMN_FIELDS:
@@ -619,26 +642,42 @@ class BDFresnelApp(tk.Tk):
command=self._on_diagnostics_change).pack(anchor="w")
sec = add_section(parent, "Calculated Parameters (probe)")
self.calc_ng = LabeledStatic(sec, "n_g (group index)")
self.calc_ng.pack(fill="x", pady=1)
self.calc_Tlin = LabeledStatic(sec, "T_lin")
self.calc_Tlin.pack(fill="x", pady=1)
self.calc_z0 = LabeledStatic(sec, "z_0 (Rayleigh range)")
self.calc_z0.pack(fill="x", pady=1)
self.calc_ng_p = LabeledStatic(sec, "n_g_p (group index)")
self.calc_ng_p.pack(fill="x", pady=1)
self.calc_Tlin_p = LabeledStatic(sec, "T_lin_p (transmission)")
self.calc_Tlin_p.pack(fill="x", pady=1)
self.calc_z0_p = LabeledStatic(sec, "z_0_p (Rayleigh range)")
self.calc_z0_p.pack(fill="x", pady=1)
# Pump side is subscripted _e, probe side bare, matching the
# field names and the log.
sec = add_section(parent, "Calculated Parameters (pump)")
self.calc_ngp = LabeledStatic(sec, "n_g (group index)")
self.calc_ngp.pack(fill="x", pady=1)
self.calc_Tlinp = LabeledStatic(sec, "T_lin")
self.calc_Tlinp.pack(fill="x", pady=1)
self.calc_z0p = LabeledStatic(sec, "z_0 (Rayleigh range)")
self.calc_z0p.pack(fill="x", pady=1)
self.calc_I0p = LabeledStatic(sec, "I_0 (peak irradiance)")
self.calc_I0p.pack(fill="x", pady=1)
self.calc_ng_e = LabeledStatic(sec, "n_g_e (group index)")
self.calc_ng_e.pack(fill="x", pady=1)
self.calc_sigma_e = LabeledStatic(sec, "sigma_e (absorption)")
self.calc_sigma_e.pack(fill="x", pady=1)
self.calc_Tlin_e = LabeledStatic(sec, "T_lin_e (transmission)")
self.calc_Tlin_e.pack(fill="x", pady=1)
self.calc_z0_e = LabeledStatic(sec, "z_0_e (Rayleigh range)")
self.calc_z0_e.pack(fill="x", pady=1)
self.calc_I0_e = LabeledStatic(sec, "I_0_e (peak irradiance)")
self.calc_I0_e.pack(fill="x", pady=1)
sec = add_section(parent, "Other")
self.calc_rho = LabeledStatic(sec, "rho (GVM parameter)")
self.calc_rho.pack(fill="x", pady=1)
# Unlike every other value in these panels, which is derived
# from the parameters alone and so updates as they are typed,
# eta and Gamma come from the result: they are peaks over the
# whole (T, T_d) grid, which there is no way to get without
# running the calculation. They therefore read "--" until a Fit
# or Simulate completes, and go back to "--" whenever that
# result is discarded, so a stale phase is never shown beside
# freshly edited parameters. See _refresh_result_values.
self.calc_eta = LabeledStatic(sec, "eta (peak)")
self.calc_eta.pack(fill="x", pady=1)
self.calc_Gamma = LabeledStatic(sec, "Gamma (peak)")
self.calc_Gamma.pack(fill="x", pady=1)
# ------------------------------------------------------------------
# Field / state synchronization
@@ -686,6 +725,13 @@ class BDFresnelApp(tk.Tk):
for name in ("T_d_min", "T_d_max"):
self._field_widgets[name].set_enabled(simulating)
# The semi-analytical expressions are already integrated over
# the detector plane, so there is no spatial grid to size.
for name in ("X_num", "X_max"):
self._field_widgets[name].set_enabled(
self.params.algorithm != ALGO_SEMI_ANALYTICAL)
self.algorithm_var.set(self.params.algorithm)
self.import_button.config(state="disabled" if simulating else "normal")
self.fit_button.config(text=self.run_action_label)
@@ -703,7 +749,7 @@ class BDFresnelApp(tk.Tk):
row = ttk.Frame(parent)
row.pack(anchor="w", pady=pady)
width = max(len(label)
for group in (MODE_CHOICES, RUN_MODE_CHOICES)
for group in (MODE_CHOICES, RUN_MODE_CHOICES, ALGO_CHOICES)
for _, label in group)
buttons = []
for value, label in choices:
@@ -752,6 +798,28 @@ class BDFresnelApp(tk.Tk):
def _on_run_mode_change(self):
self._set_run_mode(self.run_mode_var.get())
def _on_algorithm_change(self):
self._set_algorithm(self.algorithm_var.get())
def _set_algorithm(self, algorithm):
"""Switches between Fresnel propagation and the semi-analytical
expressions. Any result on screen is discarded: it was computed
by the other method, and the point of having both is to compare
them deliberately rather than to leave one mislabelled."""
if algorithm == self.params.algorithm:
return # Tk fires on every click, re-selection included
self.params.algorithm = algorithm
self.params.data_fit = False
self.fit = None
self._refresh_param_fields_from_state()
self._refresh_plots()
self._refresh_diagnostics()
self._update_action_buttons()
self._save_settings()
message = f"Algorithm: {ALGO_LABELS[algorithm]}."
self.status_var.set(message)
print(f"bd_fresnel_gui: {message}")
def _set_run_mode(self, run_mode):
"""Switches between fitting an imported scan and simulating
without one. Any result on screen is discarded: a fit describes
@@ -818,7 +886,7 @@ class BDFresnelApp(tk.Tk):
def _set_mode_buttons_enabled(self, enabled: bool):
"""The fit runs on a worker thread that reads self.params
throughout, so neither mode must change underneath it."""
for b in self._mode_buttons + self._run_mode_buttons:
for b in self._mode_buttons + self._run_mode_buttons + self._algorithm_buttons:
b.state(["!disabled"] if enabled else ["disabled"])
def _on_field_change(self, field_name):
@@ -973,13 +1041,14 @@ class BDFresnelApp(tk.Tk):
def _recalc_beam_params(self, refresh_display=False):
calc_beam_params(self.params)
if refresh_display:
self.calc_ng.set(f"{self.params.ng:.3f}")
self.calc_Tlin.set(f"{self.params.Tlin:.3f}")
self.calc_z0.set(f"{self.params.z_0 * 1e3:.3f} mm")
self.calc_ngp.set(f"{self.params.ng_p:.3f}")
self.calc_Tlinp.set(f"{self.params.Tlin_p:.3f}")
self.calc_z0p.set(f"{self.params.z_0_p * 1e3:.3f} mm")
self.calc_I0p.set(f"{self.params.I_0_p * 1e-13:.3f} GW/cm^2")
self.calc_ng_p.set(f"{self.params.ng_p:.3f}")
self.calc_Tlin_p.set(f"{self.params.Tlin_p:.3f}")
self.calc_z0_p.set(f"{self.params.z_0_p * 1e3:.3f} mm")
self.calc_ng_e.set(f"{self.params.ng_e:.3f}")
self.calc_sigma_e.set(f"{self.params.sigma_e:.3f}")
self.calc_Tlin_e.set(f"{self.params.Tlin_e:.3f}")
self.calc_z0_e.set(f"{self.params.z_0_e * 1e3:.3f} mm")
self.calc_I0_e.set(f"{self.params.I_0_e * 1e-13:.3f} GW/cm^2")
self.calc_rho.set(f"{self.params.rho:.3f}")
def _update_fit_button_state(self):
@@ -1003,6 +1072,23 @@ class BDFresnelApp(tk.Tk):
def _update_action_buttons(self):
self._update_fit_button_state()
self._update_export_button_state()
self._refresh_result_values()
def _refresh_result_values(self):
"""Fills the result-derived readouts in the "Other" panel, or
blanks them when there is no current result.
Hooked to _update_action_buttons rather than to
_recalc_beam_params because the latter fires only for fields in
CALC_BEAM_PARAMS_FIELDS -- editing a mechanism coefficient
changes eta substantially and would have left a stale value on
screen. Every site that assigns self.fit, including every one
that clears it, already calls _update_action_buttons, so this
cannot be bypassed by a path that forgets to call it."""
fit = self.fit or {}
eta, gamma = fit.get("eta_peak"), fit.get("Gamma_peak")
self.calc_eta.set("--" if eta is None else f"{eta:.3f} rad")
self.calc_Gamma.set("--" if gamma is None else f"{gamma:.3f}")
# ------------------------------------------------------------------
# Import
@@ -1073,12 +1159,12 @@ class BDFresnelApp(tk.Tk):
T=T, DeltaEoE=None, Delta_n=None)
DeltaEoE = raw[:, col_DeltaEoE - 1]
lambda_ = self.params.lambda_ * 1e-9
lambda_p = self.params.lambda_p * 1e-9
l = self.params.l * 1e-3
w_0 = self.params.w_0 * 1e-6
w_0_p = self.params.w_0p * 1e-6
k_0 = 2 * np.pi / lambda_
Delta_n = DeltaEoE / (k_0 * l * np.sqrt(2 / np.e) * (w_0 / w_0_p) * (2 / np.sqrt(np.pi)))
w_0_p = self.params.w_0_p * 1e-6
w_0_e = self.params.w_0_e * 1e-6
k_0 = 2 * np.pi / lambda_p
Delta_n = DeltaEoE / (k_0 * l * np.sqrt(2 / np.e) * (w_0_p / w_0_e) * (2 / np.sqrt(np.pi)))
return dict(
tau_d=tau_d,
@@ -1147,8 +1233,8 @@ class BDFresnelApp(tk.Tk):
# T_d_min/T_d_max are the values entered in the panel and are
# left exactly as they are.
if not simulating:
self.params.T_d_min = float(np.min(self.data["tau_d_shifted"])) / self.params.tau_p
self.params.T_d_max = float(np.max(self.data["tau_d_shifted"])) / self.params.tau_p
self.params.T_d_min = float(np.min(self.data["tau_d_shifted"])) / self.params.tau_e
self.params.T_d_max = float(np.max(self.data["tau_d_shifted"])) / self.params.tau_e
# T_d_num is no longer forced here -- it is an input in the
# Simulation Parameters box, defaulting to the 150 this line
# used to hard-code.
@@ -1159,7 +1245,7 @@ class BDFresnelApp(tk.Tk):
def _fit_worker(self):
t0 = time.time()
try:
fit = BD_Fresnel_func_ni(self.params)
fit = BD_Fresnel_run(self.params)
elapsed = time.time() - t0
self.after(0, self._on_fit_success, fit, elapsed)
except Exception:
@@ -1466,10 +1552,11 @@ class BDFresnelApp(tk.Tk):
# and drawn by one method.
PANELS = {
"T": dict(key="T", color=TRANSMISSION_COLOR, ylabel="T (%)",
title="Transmission", range_key="T_points"),
title="Transmission", range_key="T_points",
y_sig_figs=3),
"DeltaEoE": dict(key="DeltaEoE", color=DEFLECTION_COLOR,
ylabel=r"$\Delta E/E$ (%)", title="Deflection",
range_key="DeltaEoE_points"),
range_key="DeltaEoE_points", y_sig_figs=None),
}
def _plot_signal_axis(self, ax, ctx, which, y_on_right=False):
@@ -1481,6 +1568,8 @@ class BDFresnelApp(tk.Tk):
the data's delay range and should be cut off at the border
rather than overflow it.
"""
from matplotlib.ticker import FuncFormatter
spec = self.PANELS[which]
key, color = spec["key"], spec["color"]
@@ -1510,6 +1599,25 @@ class BDFresnelApp(tk.Tk):
ax.set_xlabel(rf"$\tau_d$ ({ctx['scale_label']})")
ax.set_ylabel(spec["ylabel"])
ax.set_title(spec["title"]) # size from rc context
sig = spec.get("y_sig_figs")
if sig is not None:
# Transmission sits near 100%, so the default formatter
# spends most of its digits on the leading "99." and the
# labels get wide. "%.<n>g" keeps the stated number of
# significant digits instead.
#
# The requested count is a floor, not a cap: a shallow scan
# spanning, say, 99.94 to 100% rounds every tick to "100"
# at three figures, leaving an unreadable axis. Digits are
# added only when that would happen, so an ordinary scan
# gets exactly the figures asked for.
ticks = [t for t in ax.get_yticks()
if min(ax.get_ylim()) <= t <= max(ax.get_ylim())]
while sig < 10 and len({f"{t:.{sig}g}" for t in ticks}) < len(ticks):
sig += 1
ax.yaxis.set_major_formatter(
FuncFormatter(lambda value, _pos, n=sig: f"{value:.{n}g}"))
if y_on_right:
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
@@ -1614,10 +1722,10 @@ class BDFresnelApp(tk.Tk):
# Axis labels as matplotlib mathtext, so Greek letters render as
# Greek and sub/superscripts sit where they belong rather than
# showing the literal "tau_p" / "m^2" source. Figure *titles* keep
# showing the literal "tau_e" / "m^2" source. Figure *titles* keep
# their plain-text form: they double as the Tk frame label and the
# export filename, neither of which can render mathtext.
DIAG_LABEL_T = r"$t$ ($\tau_p$)"
DIAG_LABEL_T = r"$t$ ($\tau_e$)"
DIAG_LABEL_R = r"$R[t]$ (m$^2$/W)"
DIAG_LABEL_A = r"$A[t]$ (m/W)"
DIAG_LABEL_DN = r"$\Delta n$ (unitless)"
@@ -2035,68 +2143,69 @@ class BDFresnelApp(tk.Tk):
lines.append(f"Import data file {p.import_filepath}.\n")
lines.append(f"Operation mode: {MODE_LABELS[p.mode]}, "
f"{RUN_MODE_LABELS[p.run_mode]}\n")
lines.append(f"Algorithm: {ALGO_LABELS[p.algorithm]}\n")
if not simulating:
lines.append("Data Columns:")
lines.append(f" tau_d column: {p.col_tau_d}")
lines.append(f" T column: {p.col_T}")
lines.append(f" tau_d column: {p.col_tau_d}")
lines.append(f" T column: {p.col_T}")
if p.mode == MODE_PUMP_PROBE:
lines.append(" DeltaEoE column: not used in Pump probe")
else:
lines.append(f" DeltaEoE column: {p.col_DeltaEoE}")
lines.append(f" Delimiter: {describe_delimiter(p.delimiter)}\n")
lines.append(f" DeltaEoE column: {p.col_DeltaEoE}")
lines.append(f" Delimiter: {describe_delimiter(p.delimiter)}\n")
# The delay grid is included so a run is reproducible from the
# log alone: in Fitting mode T_d_min/T_d_max are derived from
# the imported scan's delay range at fit time, in Simulation
# mode they are entered directly.
lines.append("Simulation Parameters:")
lines.append(f" X_num: {p.X_num}")
lines.append(f" X_max: {p.X_max} w_0")
lines.append(f" T_num: {p.T_num}")
lines.append(f" T_min: {p.T_min} tau_p")
lines.append(f" T_max: {p.T_max} tau_p")
lines.append(f" T_d_num: {p.T_d_num}")
lines.append(f" T_d_min: {p.T_d_min:.6g} tau_p")
lines.append(f" T_d_max: {p.T_d_max:.6g} tau_p\n")
lines.append(f" X_num: {p.X_num}")
lines.append(f" X_max: {p.X_max} w_0")
lines.append(f" T_num: {p.T_num}")
lines.append(f" T_min: {p.T_min} tau_e")
lines.append(f" T_max: {p.T_max} tau_e")
lines.append(f" T_d_num: {p.T_d_num}")
lines.append(f" T_d_min: {p.T_d_min:.6g} tau_e")
lines.append(f" T_d_max: {p.T_d_max:.6g} tau_e\n")
lines.append("Pump (Excitation) Beam:")
lines.append(f" E_p: {p.E_p} uJ")
lines.append(f" tau_p_FWHM: {p.tau_p_FWHM} fs")
lines.append(f" tau_p (HW1/eM): {p.tau_p:6.3f} fs")
lines.append(f" w_0p: {p.w_0p} um")
lines.append(f" lambda_p: {p.lambda_p} nm\n")
lines.append(f" E_e: {p.E_e} uJ")
lines.append(f" tau_e_FWHM: {p.tau_e_FWHM} fs")
lines.append(f" tau_e (HW1/eM): {p.tau_e:6.3f} fs")
lines.append(f" w_0_e: {p.w_0_e} um")
lines.append(f" lambda_e: {p.lambda_e} nm\n")
lines.append("Probe Beam:")
lines.append(f" tau_FWHM: {p.tau_FWHM} fs")
lines.append(f" tau (HW1/eM): {p.tau:6.3f} fs")
lines.append(f" w_0: {p.w_0} um")
lines.append(f" lambda: {p.lambda_} nm\n")
lines.append(f" tau_p_FWHM: {p.tau_p_FWHM} fs")
lines.append(f" tau_p (HW1/eM): {p.tau_p:6.3f} fs")
lines.append(f" w_0_p: {p.w_0_p} um")
lines.append(f" lambda_p: {p.lambda_p} nm\n")
lines.append("Material @ Pump Wavelength:")
lines.append(f" R_p: {p.R_p * 100:6.3f} %")
lines.append(f" alpha_p: {p.alpha_p:6.3f} cm^-1")
lines.append(f" n_p: {p.n_p}")
lines.append(f" dndl_p: {p.dndl_p:6.6f} um^-1")
lines.append(f" alpha_2d: {p.alpha_2d} e-11 m/W\n")
lines.append(f" R_e: {p.R_e * 100:6.3f} %")
lines.append(f" alpha_e: {p.alpha_e:6.3f} cm^-1")
lines.append(f" n_e: {p.n_e}")
lines.append(f" dndl_e: {p.dndl_e:6.6f} um^-1")
lines.append(f" alpha_2d_e: {p.alpha_2d_e} e-11 m/W\n")
lines.append("Material @ Probe Wavelength:")
lines.append(f" R: {p.R * 100:6.3f} %")
lines.append(f" alpha: {p.alpha:6.3f} cm^-1")
lines.append(f" n: {p.n}")
lines.append(f" dndl: {p.dndl:6.6f} um^-1\n")
lines.append(f" R_p: {p.R_p * 100:6.3f} %")
lines.append(f" alpha_p: {p.alpha_p:6.3f} cm^-1")
lines.append(f" n_p: {p.n_p}")
lines.append(f" dndl_p: {p.dndl_p:6.6f} um^-1\n")
lines.append("System Geometry:")
lines.append(f" l: {p.l} mm")
lines.append(f" d: {p.d} cm")
lines.append(f" shift: {p.shift} fs")
lines.append(f" x_0: {p.x_0} w_0_p\n")
lines.append(f" l: {p.l} mm")
lines.append(f" d: {p.d} cm")
lines.append(f" shift: {p.shift} fs")
lines.append(f" x_0: {p.x_0} w_0_e\n")
for i, mech in enumerate(p.mech):
if mech.name == "None (both)":
continue
lines.append(f"Mechanism {i + 1}:")
lines.append(f" Type: {mech.name}")
lines.append(f" Type: {mech.name}")
specs = MECHANISM_PARAM_SPECS.get(mech.name, [])
for j, (pname, punits) in enumerate(specs):
spacing = " " * max(1, 20 - len(pname))
@@ -2104,18 +2213,39 @@ class BDFresnelApp(tk.Tk):
lines.append("")
lines.append("Calculated Parameters (probe):")
lines.append(f" n_g: {p.ng:6.3f}")
lines.append(f" T_lin: {p.Tlin * 100:6.3f} %")
lines.append(f" z_0: {p.z_0 * 1e3:6.3f} mm\n")
lines.append(f" n_g_p: {p.ng_p:6.3f}")
lines.append(f" T_lin_p (transmission): {p.Tlin_p * 100:6.3f} %")
lines.append(f" z_0_p: {p.z_0_p * 1e3:6.3f} mm\n")
# Pump-side labels carry _e, matching their field names and the
# program-wide convention that the pump is subscripted and the
# probe is bare. The probe block above therefore stays n_g,
# T_lin, z_0. sigma_e sits next to T_lin_e because the two are
# the same statement: with no pump two-photon absorption
# T_lin_e = (1 - R_e) exp(-2 sigma_e). All five read from the
# parameters, not the result, so they report for either
# algorithm.
lines.append("Calculated Parameters (pump):")
lines.append(f" n_g: {p.ng_p:6.3f}")
lines.append(f" T_lin: {p.Tlin_p * 100:6.3f} %")
lines.append(f" z_0: {p.z_0_p * 1e3:6.3f} mm")
lines.append(f" I_0: {p.I_0_p * 1e-13:6.3f} GW/cm^2\n")
lines.append(f" n_g_e: {p.ng_e:6.3f}")
lines.append(f" sigma_e: {p.sigma_e:6.3f}")
lines.append(f" T_lin_e (transmission): {p.Tlin_e * 100:6.3f} %")
lines.append(f" z_0_e: {p.z_0_e * 1e3:6.3f} mm")
lines.append(f" I_0_e: {p.I_0_e * 1e-13:6.3f} GW/cm^2\n")
lines.append("Other:")
lines.append(f" rho: {p.rho:6.3f}\n")
lines.append(f" rho: {p.rho:6.3f}")
# Peak nonlinear phase and absorption exponent over the whole
# grid, from whichever algorithm produced the current result.
# eta_peak is the small-signal yardstick: the semi-analytical
# dP is first order in the response while Fresnel propagation
# keeps every order, so the two agree only while eta_peak stays
# small. Guarded because a result from an older session's saved
# state may predate these keys.
fit = self.fit or {}
if "eta_peak" in fit:
lines.append(f" eta (peak): {fit['eta_peak']:6.3f} rad")
lines.append(f" Gamma (peak): {fit['Gamma_peak']:6.3f}")
lines.append("")
if exported_files:
# Every file this export run produced. They all land in one
@@ -2130,13 +2260,21 @@ class BDFresnelApp(tk.Tk):
lines.append(f" {os.path.basename(path)}")
lines.append("")
lines.append("Please cite the following references when using products from this program.\n")
lines.append(' 1: Reichert, M., et al. (2014). "Temporal, spectral, and polarization '
'dependence of the nonlinear optical response of carbon disulfide." Optica 1(6): 436.\n')
lines.append(' 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.\n')
lines.append(' 3: Ferdinandus, M. R., et al. (2013). "Beam deflection measurement of time '
'and polarization resolved ultrafast nonlinear refraction." Opt Lett 38(18): 3518-3521.\n')
# Optica style: every author, initials first, abbreviated
# journal, volume, page range, year. Wrapped with a hanging
# indent rather than run onto one very long line.
lines.append(' 1: M. Reichert, H. Hu, M. R. Ferdinandus, M. Seidel, P. Zhao, '
'T. R. Ensley,\n'
' D. Peceli, J. M. Reed, D. A. Fishman, S. Webster, D. J. Hagan, and\n'
' E. W. Van Stryland, \u201cTemporal, spectral, and polarization '
'dependence of\n'
' the nonlinear optical response of carbon disulfide,\u201d '
'Optica 1, 436\u2013445 (2014).\n')
lines.append(' 2: M. R. Ferdinandus, H. Hu, M. Reichert, D. J. Hagan, and '
'E. W. Van Stryland,\n'
' \u201cBeam deflection measurement of time and polarization resolved '
'ultrafast\n'
' nonlinear refraction,\u201d Opt. Lett. 38, 3518\u20133521 (2013).\n')
return "\n".join(lines)
@@ -2146,7 +2284,12 @@ class BDFresnelApp(tk.Tk):
# itself -- everything the export run produced.
exported = [export_path, *image_paths, log_path]
text = self._build_log_text(exported_files=exported)
with open(log_path, "w+", newline="\r\n") as f:
# encoding is explicit: the citation block uses typographic
# quotes and an en dash, and open() otherwise writes in the
# locale's encoding. Windows-1252 happens to contain those
# characters, but latin-1, cp437/cp850 and the CJK code pages
# do not, and would raise UnicodeEncodeError mid-export.
with open(log_path, "w+", newline="\r\n", encoding="utf-8") as f:
f.write(text)
# ------------------------------------------------------------------