TeX Labels¶
TeX labels for most attributes can be retrieved.
In [1]:
Copied!
from beamphysics.labels import texlabel, TEXLABEL, mathlabel
from beamphysics.units import pg_units
import matplotlib.pyplot as plt
from beamphysics.labels import texlabel, TEXLABEL, mathlabel
from 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]:
False
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_\text{kinetic}
higher_order_energy_spread -> \sigma_{E_{(2)}}
higher_order_energy -> E_{(2)}
E -> E
Ex -> E_x
Ey -> E_y
Ez -> E_z
Er -> E_r
B -> B
Bx -> B_x
By -> B_y
Bz -> B_z
Br -> B_r
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 -> \text{Twiss}\ \alpha_x
twiss_beta_x -> \text{Twiss}\ \beta_x
twiss_gamma_x -> \text{Twiss}\ \gamma_x
twiss_eta_x -> \text{Twiss}\ \eta_x
twiss_etap_x -> \text{Twiss}\ \eta'_x
twiss_emit_x -> \text{Twiss}\ \epsilon_{x}
twiss_norm_emit_x -> \text{Twiss}\ \epsilon_{n, x}
twiss_alpha_y -> \text{Twiss}\ \alpha_y
twiss_beta_y -> \text{Twiss}\ \beta_y
twiss_gamma_y -> \text{Twiss}\ \gamma_y
twiss_eta_y -> \text{Twiss}\ \eta_y
twiss_etap_y -> \text{Twiss}\ \eta'_y
twiss_emit_y -> \text{Twiss}\ \epsilon_{y}
twiss_norm_emit_y -> \text{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~(1)$'
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}{\cdot}\mathrm{eV}/\mathrm{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_\text{kinetic}~(\mathrm{eV})$
higher_order_energy_spread -> $\sigma_{E_{(2)}}~(\mathrm{eV})$
higher_order_energy -> $E_{(2)}~(\mathrm{eV})$
E -> $E~(\mathrm{V}/\mathrm{m})$
Ex -> $E_x~(\mathrm{V}/\mathrm{m})$
Ey -> $E_y~(\mathrm{V}/\mathrm{m})$
Ez -> $E_z~(\mathrm{V}/\mathrm{m})$
Er -> $E_r~(\mathrm{V}/\mathrm{m})$
B -> $B~(\mathrm{T})$
Bx -> $B_x~(\mathrm{T})$
By -> $B_y~(\mathrm{T})$
Bz -> $B_z~(\mathrm{T})$
Br -> $B_r~(\mathrm{T})$
Etheta -> $E_{\theta}~(\mathrm{V}/\mathrm{m})$
Btheta -> $B_{\theta}~(\mathrm{T})$
px -> $p_x~(\mathrm{eV}/\mathrm{c})$
py -> $p_y~(\mathrm{eV}/\mathrm{c})$
pz -> $p_z~(\mathrm{eV}/\mathrm{c})$
p -> $p~(\mathrm{eV}/\mathrm{c})$
pr -> $p_r~(\mathrm{eV}/\mathrm{c})$
ptheta -> $p_{\theta}~(\mathrm{eV}/\mathrm{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~(1)$
beta_x -> $\beta_x~(1)$
beta_y -> $\beta_y~(1)$
beta_z -> $\beta_z~(1)$
gamma -> $\gamma~(1)$
theta -> $\theta~(\mathrm{rad})$
charge -> $Q~(\mathrm{C})$
twiss_alpha_x -> $\text{Twiss}\ \alpha_x~(1)$
twiss_beta_x -> $\text{Twiss}\ \beta_x~(\mathrm{m})$
twiss_gamma_x -> $\text{Twiss}\ \gamma_x~(1/\mathrm{m})$
twiss_eta_x -> $\text{Twiss}\ \eta_x~(\mathrm{m})$
twiss_etap_x -> $\text{Twiss}\ \eta'_x~(1)$
twiss_emit_x -> $\text{Twiss}\ \epsilon_{x}~(\mathrm{m})$
twiss_norm_emit_x -> $\text{Twiss}\ \epsilon_{n, x}~(\mathrm{m})$
twiss_alpha_y -> $\text{Twiss}\ \alpha_y~(1)$
twiss_beta_y -> $\text{Twiss}\ \beta_y~(\mathrm{m})$
twiss_gamma_y -> $\text{Twiss}\ \gamma_y~(1/\mathrm{m})$
twiss_eta_y -> $\text{Twiss}\ \eta_y~(\mathrm{m})$
twiss_etap_y -> $\text{Twiss}\ \eta'_y~(1)$
twiss_emit_y -> $\text{Twiss}\ \epsilon_{y}~(\mathrm{m})$
twiss_norm_emit_y -> $\text{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}{\cdot}\mathrm{eV}/\mathrm{c})$
xp -> $x'~(\mathrm{rad})$
yp -> $y'~(\mathrm{rad})$
x_bar -> $\overline{x}~(\sqrt{\mathrm{m}})$
px_bar -> $\overline{p_x}~(\sqrt{\mathrm{m}})$
y_bar -> $\overline{y}~(\sqrt{\mathrm{m}})$
py_bar -> $\overline{p_y}~(\sqrt{\mathrm{m}})$