Skip to content

Commit 722c0cb

Browse files
committed
Format
1 parent 2cd54f9 commit 722c0cb

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

examples/Diagnostics/Tunes/test_tune.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
are estimated from the phase space coordinates before/after tracking using the
55
`BunchTuneAnalysis` class.
66
"""
7+
78
import math
89
import os
910
import pathlib
@@ -64,10 +65,10 @@
6465

6566
tune_node = TeapotTuneAnalysisNode()
6667
tune_node.assignTwiss(
67-
betax=lattice_beta_x,
68-
alphax=lattice_alpha_x,
69-
etax=lattice_eta_x,
70-
etapx=lattice_etap_x,
68+
betax=lattice_beta_x,
69+
alphax=lattice_alpha_x,
70+
etax=lattice_eta_x,
71+
etapx=lattice_etap_x,
7172
betay=lattice_beta_y,
7273
alphay=lattice_alpha_y,
7374
)
@@ -77,8 +78,8 @@
7778
# Bunch
7879
# ------------------------------------------------------------------------------------
7980

80-
# Generate a matched transverse phase space distribution. The longitudinal
81-
# distribution will be uniform in position (z) and a delta function in energy
81+
# Generate a matched transverse phase space distribution. The longitudinal
82+
# distribution will be uniform in position (z) and a delta function in energy
8283
# deviation (dE).
8384
emittance_x = 25.0e-06
8485
emittance_y = 25.0e-06
@@ -113,7 +114,7 @@
113114
bunch.dumpBunch(filename)
114115

115116

116-
# Analysis
117+
# Analysis
117118
# ------------------------------------------------------------------------------------
118119

119120
# Collect phase data from bunch
@@ -124,21 +125,21 @@
124125
# Read phase data from file
125126
particles = np.loadtxt(filename, comments="%")
126127
particles = pd.DataFrame(
127-
particles,
128+
particles,
128129
columns=[ # https://github.com/PyORBIT-Collaboration/PyORBIT3/issues/78
129-
"x",
130-
"xp",
131-
"y",
132-
"yp",
130+
"x",
131+
"xp",
132+
"y",
133+
"yp",
133134
"z",
134-
"dE",
135+
"dE",
135136
"phase_x",
136137
"phase_y",
137138
"tune_x",
138139
"tune_y",
139140
"action_x",
140141
"action_y",
141-
]
142+
],
142143
)
143144
print(particles.iloc[:, 6:])
144145

@@ -159,4 +160,4 @@
159160
print("tune_y_err", tune_y_err)
160161

161162
assert np.abs(tune_x_err) < 1.00e-08
162-
assert np.abs(tune_y_err) < 1.00e-08
163+
assert np.abs(tune_y_err) < 1.00e-08

examples/Diagnostics/Tunes/test_tune_4d.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test one-turn tune estimation in coupled lattice."""
2+
23
import math
34
import os
45
import pathlib
@@ -59,7 +60,7 @@ def calc_eigtune(eigval: float) -> float:
5960
def unit_symplectic_matrix(ndim: int) -> np.ndarray:
6061
U = np.zeros((ndim, ndim))
6162
for i in range(0, ndim, 2):
62-
U[i: i + 2, i: i + 2] = [[0.0, 1.0], [-1.0, 0.0]]
63+
U[i : i + 2, i : i + 2] = [[0.0, 1.0], [-1.0, 0.0]]
6364
return U
6465

6566

@@ -68,15 +69,15 @@ def normalize_eigvec(v: np.ndarray) -> np.ndarray:
6869

6970
def _norm(v):
7071
return np.linalg.multi_dot([np.conj(v), U, v])
71-
72+
7273
if _norm(v) > 0.0:
7374
v = np.conj(v)
74-
75+
7576
v *= np.sqrt(2.0 / np.abs(_norm(v)))
7677
assert np.isclose(np.imag(_norm(v)), -2.0)
7778
assert np.isclose(np.real(_norm(v)), +0.0)
7879
return v
79-
80+
8081

8182
def calc_norm_matrix_from_eigvecs(v1: np.ndarray, v2: np.ndarray) -> np.ndarray:
8283
V = np.zeros((4, 4))
@@ -118,7 +119,7 @@ def calc_norm_matrix_from_eigvecs(v1: np.ndarray, v2: np.ndarray) -> np.ndarray:
118119

119120
# Add tune diagnostic node
120121
# ------------------------------------------------------------------------------------
121-
122+
122123
tune_node = TeapotTuneAnalysisNode()
123124
tune_node.setNormMatrix(V_inv)
124125
lattice.getNodes()[0].addChildNode(tune_node, 0)
@@ -162,7 +163,7 @@ def calc_norm_matrix_from_eigvecs(v1: np.ndarray, v2: np.ndarray) -> np.ndarray:
162163
print("turn={} xrms={:0.3f} yrms={:0.3f}".format(turn + 1, xrms, yrms))
163164

164165

165-
# Analysis
166+
# Analysis
166167
# ------------------------------------------------------------------------------------
167168

168169
# Collect phase data from bunch
@@ -184,4 +185,4 @@ def calc_norm_matrix_from_eigvecs(v1: np.ndarray, v2: np.ndarray) -> np.ndarray:
184185
print("tune_2_err", tune_2_err)
185186

186187
assert np.abs(tune_1_err) < 1.00e-08
187-
assert np.abs(tune_2_err) < 1.00e-08
188+
assert np.abs(tune_2_err) < 1.00e-08

examples/Diagnostics/Tunes/test_tune_4d_uncoupled.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
in the lattice, the (eigen)tunes {nu1, nu2} should be the same as horizontal
66
and vertical tunes {nux, nuy}.
77
"""
8+
89
import math
910
import os
1011
import pathlib
@@ -50,6 +51,7 @@
5051
# Analyze transfer matrix
5152
# ------------------------------------------------------------------------------------
5253

54+
5355
def build_norm_matrix_from_twiss_2d(alpha: float, beta: float) -> np.ndarray:
5456
norm_matrix_inv = np.array([[beta, 0.0], [-alpha, 1.0]]) * np.sqrt(1.0 / beta)
5557
norm_matrix = np.linalg.inv(norm_matrix_inv)
@@ -75,7 +77,7 @@ def build_norm_matrix_from_twiss_2d(alpha: float, beta: float) -> np.ndarray:
7577

7678
# Add tune diagnostic node
7779
# ------------------------------------------------------------------------------------
78-
80+
7981
tune_node = TeapotTuneAnalysisNode()
8082
tune_node.setNormMatrix(norm_matrix)
8183
lattice.getNodes()[0].addChildNode(tune_node, 0)
@@ -116,7 +118,7 @@ def build_norm_matrix_from_twiss_2d(alpha: float, beta: float) -> np.ndarray:
116118
bunch.dumpBunch(filename)
117119

118120

119-
# Analysis
121+
# Analysis
120122
# ------------------------------------------------------------------------------------
121123

122124
# Collect phase data from bunch
@@ -127,21 +129,21 @@ def build_norm_matrix_from_twiss_2d(alpha: float, beta: float) -> np.ndarray:
127129
# Read phase data from file
128130
particles = np.loadtxt(filename, comments="%")
129131
particles = pd.DataFrame(
130-
particles,
132+
particles,
131133
columns=[ # https://github.com/PyORBIT-Collaboration/PyORBIT3/issues/78
132-
"x",
133-
"xp",
134-
"y",
135-
"yp",
134+
"x",
135+
"xp",
136+
"y",
137+
"yp",
136138
"z",
137-
"dE",
139+
"dE",
138140
"phase_1",
139141
"phase_2",
140142
"tune_1",
141143
"tune_2",
142144
"action_1",
143145
"action_2",
144-
]
146+
],
145147
)
146148
print(particles.iloc[:, 6:])
147149

@@ -161,4 +163,4 @@ def build_norm_matrix_from_twiss_2d(alpha: float, beta: float) -> np.ndarray:
161163
print("tune_2_err", tune_2_err)
162164

163165
assert np.abs(tune_1_err) < 1.00e-08
164-
assert np.abs(tune_2_err) < 1.00e-08
166+
assert np.abs(tune_2_err) < 1.00e-08

examples/Diagnostics/Tunes/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def make_lattice(
1818
start: str = "drift",
1919
) -> AccLattice:
2020
"""Create FODO lattice.
21-
21+
2222
Args:
2323
length: Length of lattice [m].
2424
fill_frac: Fraction of lattice occupied by quadrupoles.
@@ -38,14 +38,14 @@ def make_lattice(
3838
QuadTEAPOT("qd"),
3939
QuadTEAPOT("qf2"),
4040
]
41-
41+
4242
drift_nodes[0].setLength(length_drift)
4343
drift_nodes[1].setLength(length_drift)
44-
44+
4545
quad_nodes[0].setLength(length_quad * 0.5)
4646
quad_nodes[1].setLength(length_quad)
4747
quad_nodes[2].setLength(length_quad * 0.5)
48-
48+
4949
quad_nodes[0].setParam("kq", +kq)
5050
quad_nodes[1].setParam("kq", -kq)
5151
quad_nodes[2].setParam("kq", +kq)
@@ -69,14 +69,14 @@ def make_lattice(
6969
QuadTEAPOT("qd"),
7070
QuadTEAPOT("qf2"),
7171
]
72-
72+
7373
drift_nodes[0].setLength(length_drift)
7474
drift_nodes[1].setLength(length_drift)
75-
75+
7676
quad_nodes[0].setLength(length_quad * 0.5)
7777
quad_nodes[1].setLength(length_quad)
7878
quad_nodes[2].setLength(length_quad * 0.5)
79-
79+
8080
quad_nodes[0].setParam("kq", +kq)
8181
quad_nodes[1].setParam("kq", -kq)
8282
quad_nodes[2].setParam("kq", +kq)
@@ -91,7 +91,7 @@ def make_lattice(
9191

9292
else:
9393
raise ValueError
94-
94+
9595
for node in lattice.getNodes():
9696
node.setUsageFringeFieldIN(False)
9797
node.setUsageFringeFieldOUT(False)

0 commit comments

Comments
 (0)