Skip to content

Commit

Permalink
Version 0.19.0 bulk (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoubelet committed Jun 20, 2022
1 parent dca2933 commit dff5b5c
Show file tree
Hide file tree
Showing 37 changed files with 47,779 additions and 331 deletions.
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ Temporary Items
/.idea/PyhDToolkit.iml

# Sphinx build directory and sphinx-gallery generated documents
.doc_build
.doc_build/
.docs/gallery
.docs/gallery/
.docs/gen_modules
.docs/gen_modules/
doc_build/
docs/gallery/
docs/gen_modules/
9 changes: 9 additions & 0 deletions docs/api/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
Plotting
========

.. automodule:: pyhdtoolkit.plotting.sbs.coupling
:members:

.. automodule:: pyhdtoolkit.plotting.sbs.phase
:members:

.. automodule:: pyhdtoolkit.plotting.sbs.utils
:members:

.. automodule:: pyhdtoolkit.plotting.helpers
:members:
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,5 @@ def __call__(self, *args, **kwargs):
"tfs-pandas": ("https://pylhc.github.io/tfs/", None),
"tfs": ("https://pylhc.github.io/tfs/", None),
"cpymad": ("https://hibtc.github.io/cpymad/", None),
"optics_functions": ("https://pylhc.github.io/optics_functions/", None),
}
23 changes: 23 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ Release Notes

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

.. _release_0.19.0:

0.19.0
------

Enhancements
~~~~~~~~~~~~

* 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.
* The `pyhdtoolkit.plotting.sbs` package has a new utility module, `~pyhdtoolkit.plotting.sbs.utils`, with helpful functions for plotting.
* 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.

Maintenance
~~~~~~~~~~~

* A new dependency, the `optics_functions` package, was added.
* The documentation for the `~pyhdtoolkit.maths.plotting` module has been extended.
* Tests were added for the new functionality.
* A new gallery was added showcasing the plotting of segment-by-segment coupling and phase results.

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>`_.


.. _release_0.18.0:

0.18.0
Expand Down
133 changes: 133 additions & 0 deletions examples/demo_sbs_plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""
.. _demo-sbs-plotting:
==========================
Segment-by-Segment Results
==========================
This example shows how to use the modules in `pyhdtoolkit.plotting.sbs` and their various functions
to easily visualize results of segment-by-segment runs.
"""
# sphinx_gallery_thumbnail_number = 2
import matplotlib.pyplot as plt
import tfs

from pyhdtoolkit.plotting.sbs import coupling, phase
from pyhdtoolkit.utils import defaults

defaults.config_logger(level="warning")
plt.rcParams.update(defaults._SPHINX_GALLERY_PARAMS) # for readability of this tutorial
plt.rcParams.update({"text.usetex": True, "legend.fontsize": 16}) # for these specific plots

###############################################################################
# The functions in `pyhdtoolkit.plotting.sbs` modules usually need to be provided
# different dataframes corresponding to specific components of segment-by-segment
# results, which can be obtained by directly loading the output **TFS** files.
# Let's load below the coupling results of a segment-by-segment run and related
# model files.

b1_model_tfs = tfs.read("sbs/b1_twiss_elements.dat")
b2_model_tfs = tfs.read("sbs/b2_twiss_elements.dat")

couple_b1_tfs = tfs.read("sbs/b1_sbscouple_IP1.out")
couple_b2_tfs = tfs.read("sbs/b2_sbscouple_IP1.out")

###############################################################################
# One can now easily plot these results in a few lines with functions from the
# `~.plotting.sbs.coupling` module. Here we will plot a single component of a
# given coupling RDT through the segment.
#
# .. tip::
# Providing a dataframe with the model information is optional. If it is given, it is
# used to determine the position of the IP point in the segment, and this position
# will then be highlighted in the plot.

# Here we plot the real part of the f1001 coupling resonance driving term (default rdt plotted)
coupling.plot_rdt_component(
couple_b1_tfs,
couple_b2_tfs,
b1_model_tfs,
b2_model_tfs,
ip=1,
component="RE",
figsize=(8, 8),
b1_ylabel=r"$\mathrm{Beam\ 1}$ $\Re f_{1001}$",
b2_ylabel=r"$\mathrm{Beam\ 2}$ $\Re f_{1001}$",
)
# We can set specific limits to the axes by accessing them through the returned Figure
for ax in plt.gcf().axes:
ax.set_ylim(-0.1, 0.1)
plt.show()

###############################################################################
# One can plot all components of a given coupling RDT for both beams with the
# `~.plotting.sbs.coupling.plot_full_ip_rdt` function.
#
# .. tip::
# Specific limits can be provided for different components of the RDT. At the
# moment, these limits apply to the plots of both beams as they share their y
# axis. Keyword arguments can be used to specify properties of the figure and
# set the position of the legend.


coupling.plot_full_ip_rdt(
couple_b1_tfs,
couple_b2_tfs,
b1_model_tfs,
b2_model_tfs,
ip=1,
figsize=(18, 9),
abs_ylimits=(5e-3, 6.5e-2),
real_ylimits=(-1e-1, 1e-1),
imag_ylimits=(-1e-1, 1e-1),
bbox_to_anchor=(0.535, 0.945),
)
plt.show()

###############################################################################
# Similarly, one can plot the phase results of a segment-by-segment run with the
# functions in `~.plotting.sbs.phase`. The plotting logic is the same as above,
# with the simplification that no component has to be chosen. Let's load data for
# this example: one dataframe for each plane for Beam 2.

sbs_phasex = tfs.read("sbs/b2sbsphasext_IP5.out")
sbs_phasey = tfs.read("sbs/b2sbsphaseyt_IP5.out")

phase.plot_phase_segment_one_beam(
phase_x=sbs_phasex,
phase_y=sbs_phasey,
model=b2_model_tfs,
ip=5,
figsize=(9, 10),
)
plt.show()


###############################################################################
# Similarly to the coupling example, one can plot the results for both beams in
# a single call with the `~.plotting.sbs.phase.plot_phase_segment_both_beams`
# function, as demonstrated below.

phase.plot_phase_segment_both_beams(
b1_phase_x=sbs_phasex,
b1_phase_y=sbs_phasey,
b2_phase_x=sbs_phasex,
b2_phase_y=sbs_phasey,
b1_model=b2_model_tfs,
b2_model=b2_model_tfs,
ip=5,
figsize=(18, 9),
bbox_to_anchor=(0.535, 0.94),
)
plt.show()

#############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `~.plotting.sbs.coupling`: `~.plotting.sbs.coupling.plot_rdt_component`, `~.plotting.sbs.coupling.plot_full_ip_rdt`
# - `~.plotting.sbs.phase`: `~.plotting.sbs.phase.plot_phase_segment_one_beam`, `~.plotting.sbs.phase.plot_phase_segment_both_beams`
Loading

0 comments on commit dff5b5c

Please sign in to comment.