Skip to content

Commit 60b9e0e

Browse files
committed
numpy style
1 parent 4d45868 commit 60b9e0e

File tree

1 file changed

+102
-62
lines changed

1 file changed

+102
-62
lines changed

pyhdtoolkit/plotting/crossing.py

Lines changed: 102 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,55 @@ def plot_two_lhc_ips_crossings(
2828
"""
2929
.. versionadded:: 1.0.0
3030
31-
Creates a plot representing the crossing schemes at the two provided IPs. One can find an example
32-
use of this function in the :ref:`LHC crossing schemes <demo-crossing-schemes>` example gallery.
33-
34-
.. note::
35-
This function has some heavy logic behind it, especially in how it needs to order several axes. The
36-
easiest way to go about using it is to manually create and empty figure with the desired properties
37-
(size, etc) then call this function. See the example below or the gallery for more details.
38-
39-
.. note::
40-
This assumes the appropriate LHC sequence and opticsfile have been loaded, and both
41-
``lhcb1`` and ``lhcb2`` beams are defined. It is very recommended to first re-cycle the
42-
sequences so that the desired IPs do not happen at beginning or end of the lattice.
43-
44-
.. warning::
45-
This function will get ``TWISS`` tables for both beams, which means it will ``USE`` both the
46-
``lhcb1`` and ``lhcb2`` sequences, erasing previously defined errors or orbit corrections. The
47-
second sequence ``USE`` will be called on is ``lhcb2``, which may not be the one you were using
48-
before. Please re-``use`` your wanted sequence after calling this function!
49-
50-
Args:
51-
madx (cpymad.madx.Madx): an instanciated `~cpymad.madx.Madx` object. Positional only.
52-
first_ip (int): the first of the two IPs to plot crossing schemes for.
53-
second_ip (int): the second of the two IPs to plot crossing schemes for.
54-
ir_limit (float): the amount of meters to keep left and right of the IP point. Will also
55-
determine the ``xlimits`` of the plots. Defaults to 275.
56-
highlight_mqx_and_mbx (bool): if `True`, will add patches highlighting the zones corresponding
57-
to ``MBX`` and ``MQX`` elements. Defaults to `True`.
58-
**kwargs: If either `ax` or `axis` is found in the kwargs, the corresponding value is used as the
59-
axis object to plot on.
60-
61-
Examples:
31+
Creates a plot representing the crossing schemes at the two provided
32+
IPs. One can find an example use of this function in the :ref:`LHC
33+
crossing schemes <demo-crossing-schemes>` example gallery.
34+
35+
Note
36+
----
37+
This function has some heavy logic behind it, especially in how it
38+
needs to order several axes. The easiest way to go about using it
39+
is to manually create and empty figure with the desired properties
40+
(size, etc) then call this function. See the example below or the
41+
gallery for more details.
42+
43+
Note
44+
----
45+
This assumes the appropriate LHC sequence and opticsfile have been
46+
loaded, and both ``lhcb1`` and ``lhcb2`` beams are defined. It is
47+
very recommended to first re-cycle the sequences so that the desired
48+
IPs do not happen at beginning or end of the lattice.
49+
50+
Warning
51+
-------
52+
This function will get ``TWISS`` tables for both beams, which means
53+
it will ``USE`` both the ``lhcb1`` and ``lhcb2`` sequences, erasing
54+
previously defined errors or orbit corrections. The second sequence
55+
``USE`` will be called on is ``lhcb2``, which may not be the one you
56+
were using before. Please re-``use`` your wanted sequence after you
57+
have called this function!
58+
59+
Parameters
60+
----------
61+
madx : cpymad.madx.Madx
62+
An instanciated `~cpymad.madx.Madx` object. Positional only.
63+
first_ip : int
64+
The first of the two IPs to plot crossing schemes for.
65+
second_ip : int
66+
The second of the two IPs to plot crossing schemes for.
67+
ir_limit : float
68+
The amount of meters to keep left and right of the IP point. Will
69+
also determine the ``xlimits`` of the plots. Defaults to 275.
70+
highlight_mqx_and_mbx : bool
71+
If `True`, will add patches highlighting the zones corresponding
72+
to ``MBX`` and ``MQX`` elements. Defaults to `True`.
73+
**kwargs
74+
If either `ax` or `axis` is found in the kwargs, the corresponding
75+
value is used as the axis object to plot on.
76+
77+
Examples
78+
--------
79+
6280
.. code-block:: python
6381
6482
plt.figure(figsize=(18, 12))
@@ -148,32 +166,46 @@ def plot_single_ir_crossing(
148166
plot_df_b2: DataFrame,
149167
plot_column: str,
150168
scaling: float = 1,
151-
ylabel: str | None = None,
152169
xlabel: str | None = None,
170+
ylabel: str | None = None,
153171
title: str | None = None,
154172
) -> None:
155173
"""
156174
.. versionadded:: 1.0.0
157175
158176
Plots the X or Y orbit for the IR on the given axis.
159177
160-
.. warning::
161-
This function assumes the provided the *plot_df_b1* and *plot_df_b2* are already centered
162-
at 0 on the IP point!
163-
164-
Args:
165-
axis (matplotlib.axes.Axes): the `~matplotlib.axes.Axes` on which to plot.
166-
plot_df_b1 (Union[pd.DataFrame, tfs.TfsDataFrame]): ``TWISS`` dataframe of the IR zone for beam 1
167-
of the LHC, centered on 0 at IP position (simply done with ``df.s = df.s - ip_s``).
168-
plot_df_b2 (Union[pd.DataFrame, tfs.TfsDataFrame]): ``TWISS`` dataframe of the IR zone for beam 2
169-
of the LHC, centered on 0 at IP position (simply done with ``df.s = df.s - ip_s``).
170-
plot_column (str): which column (should be ``x`` or ``y``) to plot for the orbit.
171-
scaling (float): scaling factor to apply to the plotted data. Defaults to 1 (no change of data).
172-
xlabel (str): if given, will be used for the ``xlabel`` of the axis. Defaults to `None`.
173-
ylabel (str): if given, will be used for the ``ylabel`` of the axis. Defaults to `None`.
174-
title (str): if given, will be used for the ``title`` of the axis. Defaults to `None`.
175-
176-
Example:
178+
Warning
179+
-------
180+
This function assumes the provided the *plot_df_b1* and
181+
*plot_df_b2* are already centered at 0 on the IP point!
182+
183+
Parameters
184+
----------
185+
axis : matplotlib.axes.Axes
186+
The `~matplotlib.axes.Axes` on which to plot.
187+
plot_df_b1 : pd.DataFrame | tfs.TfsDataFrame
188+
The ``TWISS`` dataframe of the IR zone for beam 1 of the LHC,
189+
centered on 0 at IP position (this can be achieved very simply
190+
with ``df.s = df.s - ip_s``).
191+
plot_df_b2 : pd.DataFrame | tfs.TfsDataFrame
192+
The ``TWISS`` dataframe of the IR zone for beam 2 of the LHC,
193+
centered on 0 at IP position (this can be achieved very simply
194+
with ``df.s = df.s - ip_s``).
195+
plot_column : str
196+
Which column (should be ``x`` or ``y``) to plot for the orbit.
197+
scaling : float
198+
Scaling factor to apply to the plotted data. Defaults to 1 (no
199+
change of data).
200+
xlabel : str, optional
201+
If given, will be used for the ``xlabel`` of the axis.
202+
ylabel : str, optional
203+
If given, will be used for the ``ylabel`` of the axis.
204+
title : str, optional
205+
If given, will be used for the ``title`` of the axis.
206+
207+
Example
208+
-------
177209
.. code-block:: python
178210
179211
plot_single_ir_crossing(
@@ -201,19 +233,27 @@ def _highlight_mbx_and_mqx(axis: Axes, plot_df: DataFrame | TfsDataFrame, ip: in
201233
"""
202234
.. versionadded:: 1.0.0
203235
204-
Plots colored pacthes highlighting zones with ``MBX`` and ``MQX`` elements in a twin
205-
of the given axis.
206-
207-
.. warning::
208-
This function assumes the provided *plot_df* is already centered at 0 on the IP point!
209-
210-
Args:
211-
axis (matplotlib.axes.Axes): the `~matplotlib.axes.Axes` to twin and then on which to add patches.
212-
plot_df (Union[pd.DataFrame, tfs.TfsDataFrame]): ``TWISS`` dataframe of the IR zone, centered on 0
213-
at the IP position (simply done with ``df.s = df.s - ip_s``).
214-
ip (int): the IP number of the wanted IR in which to highlight elements positions.
215-
**kwargs: any keyword argument is given to the `~matplotlib.axes.Axes.axvspan` method called for
216-
each patch.
236+
Plots colored pacthes highlighting zones with ``MBX`` and ``MQX``
237+
elements in a twin of the given axis.
238+
239+
Warning
240+
-------
241+
This function assumes the provided *plot_df* is already
242+
centered at 0 on the IP point!
243+
244+
Parameters
245+
----------
246+
axis : matplotlib.axes.Axes
247+
The `~matplotlib.axes.Axes` to twin before adding patches.
248+
plot_df : pd.DataFrame | tfs.TfsDataFrame
249+
The ``TWISS`` dataframe of the IR zone, centered on 0 at
250+
the IP position (simply done with ``df.s = df.s - ip_s``).
251+
ip : int
252+
The IP number of the wanted IR in which to highlight elements
253+
positions.
254+
**kwargs
255+
Any keyword argument is given to the `~matplotlib.axes.Axes.axvspan`
256+
method called for each patch.
217257
"""
218258
left_ir = plot_df.query("s < 0") # no need to copy, we don't touch data
219259
right_ir = plot_df.query("s > 0") # no need to copy, we don't touch data

0 commit comments

Comments
 (0)