TeX Labels¶
TeX labels for most attributes can be retrieved.
In [1]:
Copied!
from pmd_beamphysics.labels import texlabel, TEXLABEL, mathlabel
from pmd_beamphysics.units import pg_units
import matplotlib.pyplot as plt
from pmd_beamphysics.labels import texlabel, TEXLABEL, mathlabel
from pmd_beamphysics.units import pg_units
import matplotlib.pyplot as plt
This is basic function
In [2]:
Copied!
?texlabel
?texlabel
Example:
In [3]:
Copied!
texlabel("norm_emit_x")
texlabel("norm_emit_x")
Out[3]:
'\\epsilon_{n, x}'
Example with two parts:
In [4]:
Copied!
texlabel("cov_x__px")
texlabel("cov_x__px")
Out[4]:
'\\left<x, p_x\\right>'
Returns None if a label cannot be formed:
In [5]:
Copied!
texlabel("garbage") is None
texlabel("garbage") is None
Out[5]:
True
In [6]:
Copied!
examples = ["cov_x__px", "sigma_y", "mean_Jx"]
examples += list(TEXLABEL)
examples = ["cov_x__px", "sigma_y", "mean_Jx"]
examples += list(TEXLABEL)
In [7]:
Copied!
for key in examples:
tex = texlabel(key)
s = rf"${tex}$"
print(key, "->", tex)
fig, ax = plt.subplots(figsize=(1, 1))
plt.axis("off")
ax.text(0.5, 0.5, s, fontsize=32)
plt.show()
for key in examples:
tex = texlabel(key)
s = rf"${tex}$"
print(key, "->", tex)
fig, ax = plt.subplots(figsize=(1, 1))
plt.axis("off")
ax.text(0.5, 0.5, s, fontsize=32)
plt.show()
cov_x__px -> \left<x, p_x\right>
sigma_y -> \sigma_{ y }
mean_Jx -> \left<J_x\right>
t -> t
energy -> E
kinetic_energy -> E_{kinetic}
Ex -> E_x
Ey -> E_y
Ez -> E_z
Bx -> B_x
By -> B_y
Bz -> B_z
Etheta -> E_{\theta}
Btheta -> B_{\theta}
px -> p_x
py -> p_y
pz -> p_z
p -> p
pr -> p_r
ptheta -> p_{\theta}
x -> x
y -> y
z -> z
r -> r
Jx -> J_x
Jy -> J_y
beta -> \beta
beta_x -> \beta_x
beta_y -> \beta_y
beta_z -> \beta_z
gamma -> \gamma
theta -> \theta
charge -> Q
twiss_alpha_x -> Twiss\ \alpha_x
twiss_beta_x -> Twiss\ \beta_x
twiss_gamma_x -> Twiss\ \gamma_x
twiss_eta_x -> Twiss\ \eta_x
twiss_etap_x -> Twiss\ \eta'_x
twiss_emit_x -> Twiss\ \epsilon_{x}
twiss_norm_emit_x -> Twiss\ \epsilon_{n, x}
twiss_alpha_y -> Twiss\ \alpha_y
twiss_beta_y -> Twiss\ \beta_y
twiss_gamma_y -> Twiss\ \gamma_y
twiss_eta_y -> Twiss\ \eta_y
twiss_etap_y -> Twiss\ \eta'_y
twiss_emit_y -> Twiss\ \epsilon_{y}
twiss_norm_emit_y -> Twiss\ \epsilon_{n, y}
average_current -> I_{av}
norm_emit_x -> \epsilon_{n, x}
norm_emit_y -> \epsilon_{n, y}
norm_emit_4d -> \epsilon_{4D}
Lz -> L_z
xp -> x'
yp -> y'
x_bar -> \overline{x}
px_bar -> \overline{p_x}
y_bar -> \overline{y}
py_bar -> \overline{p_y}
Math label with unit¶
mathlabel
provides the complete string with optional units
In [8]:
Copied!
?mathlabel
?mathlabel
In [9]:
Copied!
mathlabel("beta_x", units=pg_units("beta_x"))
mathlabel("beta_x", units=pg_units("beta_x"))
Out[9]:
'$\\beta_x$'
Multiple keys. Note that units are not checked for consistency!
In [10]:
Copied!
mathlabel("sigma_x", "sigma_y", units="µm")
mathlabel("sigma_x", "sigma_y", units="µm")
Out[10]:
'$\\sigma_{ x }, \\sigma_{ y }~(\\mathrm{ µm } )$'
In [11]:
Copied!
for key in examples:
label = mathlabel(key, units=pg_units(key))
print(key, "->", label)
fig, ax = plt.subplots(figsize=(1, 1))
plt.axis("off")
ax.text(0.5, 0.5, label, fontsize=32)
plt.show()
for key in examples:
label = mathlabel(key, units=pg_units(key))
print(key, "->", label)
fig, ax = plt.subplots(figsize=(1, 1))
plt.axis("off")
ax.text(0.5, 0.5, label, fontsize=32)
plt.show()
cov_x__px -> $\left<x, p_x\right>~(\mathrm{ m*eV/c } )$
sigma_y -> $\sigma_{ y }~(\mathrm{ m } )$
mean_Jx -> $\left<J_x\right>~(\mathrm{ m } )$
t -> $t~(\mathrm{ s } )$
energy -> $E~(\mathrm{ eV } )$
kinetic_energy -> $E_{kinetic}~(\mathrm{ eV } )$
Ex -> $E_x~(\mathrm{ V/m } )$
Ey -> $E_y~(\mathrm{ V/m } )$
Ez -> $E_z~(\mathrm{ V/m } )$
Bx -> $B_x~(\mathrm{ T } )$
By -> $B_y~(\mathrm{ T } )$
Bz -> $B_z~(\mathrm{ T } )$
Etheta -> $E_{\theta}~(\mathrm{ V/m } )$
Btheta -> $B_{\theta}~(\mathrm{ T } )$
px -> $p_x~(\mathrm{ eV/c } )$
py -> $p_y~(\mathrm{ eV/c } )$
pz -> $p_z~(\mathrm{ eV/c } )$
p -> $p~(\mathrm{ eV/c } )$
pr -> $p_r~(\mathrm{ eV/c } )$
ptheta -> $p_{\theta}~(\mathrm{ eV/c } )$
x -> $x~(\mathrm{ m } )$
y -> $y~(\mathrm{ m } )$
z -> $z~(\mathrm{ m } )$
r -> $r~(\mathrm{ m } )$
Jx -> $J_x~(\mathrm{ m } )$
Jy -> $J_y~(\mathrm{ m } )$
beta -> $\beta$
beta_x -> $\beta_x$
beta_y -> $\beta_y$
beta_z -> $\beta_z$
gamma -> $\gamma$
theta -> $\theta~(\mathrm{ rad } )$
charge -> $Q~(\mathrm{ C } )$
twiss_alpha_x -> $Twiss\ \alpha_x$
twiss_beta_x -> $Twiss\ \beta_x~(\mathrm{ m } )$
twiss_gamma_x -> $Twiss\ \gamma_x~(\mathrm{ /m } )$
twiss_eta_x -> $Twiss\ \eta_x~(\mathrm{ m } )$
twiss_etap_x -> $Twiss\ \eta'_x$
twiss_emit_x -> $Twiss\ \epsilon_{x}~(\mathrm{ m } )$
twiss_norm_emit_x -> $Twiss\ \epsilon_{n, x}~(\mathrm{ m } )$
twiss_alpha_y -> $Twiss\ \alpha_y$
twiss_beta_y -> $Twiss\ \beta_y~(\mathrm{ m } )$
twiss_gamma_y -> $Twiss\ \gamma_y~(\mathrm{ /m } )$
twiss_eta_y -> $Twiss\ \eta_y~(\mathrm{ m } )$
twiss_etap_y -> $Twiss\ \eta'_y$
twiss_emit_y -> $Twiss\ \epsilon_{y}~(\mathrm{ m } )$
twiss_norm_emit_y -> $Twiss\ \epsilon_{n, y}~(\mathrm{ m } )$
average_current -> $I_{av}~(\mathrm{ A } )$
norm_emit_x -> $\epsilon_{n, x}~(\mathrm{ m } )$
norm_emit_y -> $\epsilon_{n, y}~(\mathrm{ m } )$
norm_emit_4d -> $\epsilon_{4D}~(\mathrm{ (m)^2 } )$
Lz -> $L_z~(\mathrm{ m*eV/c } )$
xp -> $x'~(\mathrm{ rad } )$
yp -> $y'~(\mathrm{ rad } )$
x_bar -> $\overline{x}~(\mathrm{ \sqrt{ m } } )$
px_bar -> $\overline{p_x}~(\mathrm{ \sqrt{ m } } )$
y_bar -> $\overline{y}~(\mathrm{ \sqrt{ m } } )$
py_bar -> $\overline{p_y}~(\mathrm{ \sqrt{ m } } )$