Skip to content

Commit dff5b5c

Browse files
authored
Version 0.19.0 bulk (#82)
1 parent dca2933 commit dff5b5c

37 files changed

+47779
-331
lines changed

.gitignore

+3-6
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ Temporary Items
250250
/.idea/PyhDToolkit.iml
251251

252252
# Sphinx build directory and sphinx-gallery generated documents
253-
.doc_build
254-
.doc_build/
255-
.docs/gallery
256-
.docs/gallery/
257-
.docs/gen_modules
258-
.docs/gen_modules/
253+
doc_build/
254+
docs/gallery/
255+
docs/gen_modules/

docs/api/plotting.rst

+9
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33
Plotting
44
========
55

6+
.. automodule:: pyhdtoolkit.plotting.sbs.coupling
7+
:members:
8+
9+
.. automodule:: pyhdtoolkit.plotting.sbs.phase
10+
:members:
11+
12+
.. automodule:: pyhdtoolkit.plotting.sbs.utils
13+
:members:
14+
615
.. automodule:: pyhdtoolkit.plotting.helpers
716
:members:

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,5 @@ def __call__(self, *args, **kwargs):
527527
"tfs-pandas": ("https://pylhc.github.io/tfs/", None),
528528
"tfs": ("https://pylhc.github.io/tfs/", None),
529529
"cpymad": ("https://hibtc.github.io/cpymad/", None),
530+
"optics_functions": ("https://pylhc.github.io/optics_functions/", None),
530531
}

docs/release.rst

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ Release Notes
33

44
The full list of releases can be found in the Github repository's `releases page <https://github.com/fsoubelet/PyhDToolkit/releases>`_.
55

6+
.. _release_0.19.0:
7+
8+
0.19.0
9+
------
10+
11+
Enhancements
12+
~~~~~~~~~~~~
13+
14+
* The `pyhdtoolkit.plotting` package has a new sub-package, `pyhdtoolkit.plotting.sbs` with modules to plot coupling (`~pyhdtoolkit.plotting.sbs.coupling`) and phase (`~pyhdtoolkit.plotting.sbs.phase`) segment-by-segment results.
15+
* The `pyhdtoolkit.plotting.sbs` package has a new utility module, `~pyhdtoolkit.plotting.sbs.utils`, with helpful functions for plotting.
16+
* The `pyhdtoolkit.cpymadtools.lhc` module has a new function, `~pyhdtoolkit.cpymadtools.lhc.get_lhc_bpms_twiss_and_rdts` to easily get coupling RDTs at all observation points (BPMs) in the LHC sequence.
17+
18+
Maintenance
19+
~~~~~~~~~~~
20+
21+
* A new dependency, the `optics_functions` package, was added.
22+
* The documentation for the `~pyhdtoolkit.maths.plotting` module has been extended.
23+
* Tests were added for the new functionality.
24+
* A new gallery was added showcasing the plotting of segment-by-segment coupling and phase results.
25+
26+
See `v0.19.0 release notes on GitHub <https://github.com/fsoubelet/PyhDToolkit/releases/tag/0.19.0>`_ and the `full changes since v0.18.0 <https://github.com/fsoubelet/PyhDToolkit/compare/0.18.0...0.19.0>`_.
27+
28+
629
.. _release_0.18.0:
730

831
0.18.0

examples/demo_sbs_plotting.py

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"""
2+
3+
.. _demo-sbs-plotting:
4+
5+
==========================
6+
Segment-by-Segment Results
7+
==========================
8+
9+
This example shows how to use the modules in `pyhdtoolkit.plotting.sbs` and their various functions
10+
to easily visualize results of segment-by-segment runs.
11+
"""
12+
# sphinx_gallery_thumbnail_number = 2
13+
import matplotlib.pyplot as plt
14+
import tfs
15+
16+
from pyhdtoolkit.plotting.sbs import coupling, phase
17+
from pyhdtoolkit.utils import defaults
18+
19+
defaults.config_logger(level="warning")
20+
plt.rcParams.update(defaults._SPHINX_GALLERY_PARAMS) # for readability of this tutorial
21+
plt.rcParams.update({"text.usetex": True, "legend.fontsize": 16}) # for these specific plots
22+
23+
###############################################################################
24+
# The functions in `pyhdtoolkit.plotting.sbs` modules usually need to be provided
25+
# different dataframes corresponding to specific components of segment-by-segment
26+
# results, which can be obtained by directly loading the output **TFS** files.
27+
# Let's load below the coupling results of a segment-by-segment run and related
28+
# model files.
29+
30+
b1_model_tfs = tfs.read("sbs/b1_twiss_elements.dat")
31+
b2_model_tfs = tfs.read("sbs/b2_twiss_elements.dat")
32+
33+
couple_b1_tfs = tfs.read("sbs/b1_sbscouple_IP1.out")
34+
couple_b2_tfs = tfs.read("sbs/b2_sbscouple_IP1.out")
35+
36+
###############################################################################
37+
# One can now easily plot these results in a few lines with functions from the
38+
# `~.plotting.sbs.coupling` module. Here we will plot a single component of a
39+
# given coupling RDT through the segment.
40+
#
41+
# .. tip::
42+
# Providing a dataframe with the model information is optional. If it is given, it is
43+
# used to determine the position of the IP point in the segment, and this position
44+
# will then be highlighted in the plot.
45+
46+
# Here we plot the real part of the f1001 coupling resonance driving term (default rdt plotted)
47+
coupling.plot_rdt_component(
48+
couple_b1_tfs,
49+
couple_b2_tfs,
50+
b1_model_tfs,
51+
b2_model_tfs,
52+
ip=1,
53+
component="RE",
54+
figsize=(8, 8),
55+
b1_ylabel=r"$\mathrm{Beam\ 1}$ $\Re f_{1001}$",
56+
b2_ylabel=r"$\mathrm{Beam\ 2}$ $\Re f_{1001}$",
57+
)
58+
# We can set specific limits to the axes by accessing them through the returned Figure
59+
for ax in plt.gcf().axes:
60+
ax.set_ylim(-0.1, 0.1)
61+
plt.show()
62+
63+
###############################################################################
64+
# One can plot all components of a given coupling RDT for both beams with the
65+
# `~.plotting.sbs.coupling.plot_full_ip_rdt` function.
66+
#
67+
# .. tip::
68+
# Specific limits can be provided for different components of the RDT. At the
69+
# moment, these limits apply to the plots of both beams as they share their y
70+
# axis. Keyword arguments can be used to specify properties of the figure and
71+
# set the position of the legend.
72+
73+
74+
coupling.plot_full_ip_rdt(
75+
couple_b1_tfs,
76+
couple_b2_tfs,
77+
b1_model_tfs,
78+
b2_model_tfs,
79+
ip=1,
80+
figsize=(18, 9),
81+
abs_ylimits=(5e-3, 6.5e-2),
82+
real_ylimits=(-1e-1, 1e-1),
83+
imag_ylimits=(-1e-1, 1e-1),
84+
bbox_to_anchor=(0.535, 0.945),
85+
)
86+
plt.show()
87+
88+
###############################################################################
89+
# Similarly, one can plot the phase results of a segment-by-segment run with the
90+
# functions in `~.plotting.sbs.phase`. The plotting logic is the same as above,
91+
# with the simplification that no component has to be chosen. Let's load data for
92+
# this example: one dataframe for each plane for Beam 2.
93+
94+
sbs_phasex = tfs.read("sbs/b2sbsphasext_IP5.out")
95+
sbs_phasey = tfs.read("sbs/b2sbsphaseyt_IP5.out")
96+
97+
phase.plot_phase_segment_one_beam(
98+
phase_x=sbs_phasex,
99+
phase_y=sbs_phasey,
100+
model=b2_model_tfs,
101+
ip=5,
102+
figsize=(9, 10),
103+
)
104+
plt.show()
105+
106+
107+
###############################################################################
108+
# Similarly to the coupling example, one can plot the results for both beams in
109+
# a single call with the `~.plotting.sbs.phase.plot_phase_segment_both_beams`
110+
# function, as demonstrated below.
111+
112+
phase.plot_phase_segment_both_beams(
113+
b1_phase_x=sbs_phasex,
114+
b1_phase_y=sbs_phasey,
115+
b2_phase_x=sbs_phasex,
116+
b2_phase_y=sbs_phasey,
117+
b1_model=b2_model_tfs,
118+
b2_model=b2_model_tfs,
119+
ip=5,
120+
figsize=(18, 9),
121+
bbox_to_anchor=(0.535, 0.94),
122+
)
123+
plt.show()
124+
125+
#############################################################################
126+
#
127+
# .. admonition:: References
128+
#
129+
# The use of the following functions, methods, classes and modules is shown
130+
# in this example:
131+
#
132+
# - `~.plotting.sbs.coupling`: `~.plotting.sbs.coupling.plot_rdt_component`, `~.plotting.sbs.coupling.plot_full_ip_rdt`
133+
# - `~.plotting.sbs.phase`: `~.plotting.sbs.phase.plot_phase_segment_one_beam`, `~.plotting.sbs.phase.plot_phase_segment_both_beams`

0 commit comments

Comments
 (0)