Skip to content

Commit 10c5f49

Browse files
committed
Docstrings
1 parent 7282982 commit 10c5f49

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

xplt/line.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ def order(knl):
4545

4646

4747
class KnlPlot(XManifoldPlot):
48+
"""A plot for knl values along line"""
49+
4850
def __init__(
4951
self, line=None, *, knl=None, filled=True, resolution=1000, line_length=None, **kwargs
5052
):
5153
"""
52-
A plot for knl values along line
5354
5455
Args:
5556
line (xtrack.Line): Line of elements.
@@ -183,6 +184,8 @@ def label_for(self, *pp, unit=True, description=True):
183184

184185

185186
class FloorPlot(XPlot):
187+
"""A floor plan of the line based on survey data"""
188+
186189
def __init__(
187190
self,
188191
survey=None,
@@ -195,7 +198,6 @@ def __init__(
195198
**kwargs,
196199
):
197200
"""
198-
A floor plan of the line based on survey data
199201
200202
Args:
201203
survey (Any): Survey data.

xplt/particles.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121

2222

2323
class ParticlePlotMixin:
24+
"""Mixin for plotting of particle data
25+
26+
.. automethod:: _init_particle_mixin
27+
"""
28+
2429
def _init_particle_mixin(
2530
self, *, twiss=None, beta=None, frev=None, circumference=None, **kwargs
2631
):
27-
r"""Mixin for plotting of particle data
32+
r"""Initializes the mixin by providing associated information
2833
29-
In addition to the inherent particle properties (like ``x``, ``y``, ``px``, ``py``, ``zeta``, ``delta``, ...)
30-
the following derived properties are supported (but may require passing of twiss etc.):
34+
For a given particle object with inherent properties like ``x``, ``y``, ``px``, ``py``, ``zeta``, ``delta``, etc.
35+
this mixin allows determination of the following derived properties:
3136
3237
- Normalized coordinates: ``X``, ``Y``, ``Px``, ``Py``
3338
| :math:`X = x/\sqrt{\beta_x} = \sqrt{2J_x} \cos(\Theta_x)`
@@ -43,7 +48,7 @@ def _init_particle_mixin(
4348
4449
Args:
4550
twiss (dict | None): Twiss parameters (alfx, alfy, betx and bety) to use for conversion to normalized phase space coordinates.
46-
beta (float | None): Relativistic beta of particles. Defaults to particles.beta0.
51+
beta (float | None): Relativistic beta of particles. Defaults to `beta0` property of particles.
4752
frev (float | None): Revolution frequency of circular line for calculation of particle time.
4853
circumference (float | None): Path length of circular line if frev is not given.
4954
kwargs: Keyword arguments for :class:`~.base.XPlot`
@@ -90,6 +95,7 @@ def _init_particle_mixin(
9095

9196
@property
9297
def circumference(self):
98+
"""Circumference of circular accelerator"""
9399
if self._circumference is not None:
94100
return self._circumference
95101
if self.twiss is not None:
@@ -167,6 +173,7 @@ def _particle_time(self, turn, zeta, particles=None):
167173
def get_property(self, name):
168174
# Note: this method is not used by the library, but it's handy for standalone use
169175
"""Public method to get a particle property by key
176+
170177
Args:
171178
name (str): Key
172179
Returns:
@@ -177,6 +184,8 @@ def get_property(self, name):
177184

178185

179186
class ParticlesPlot(XManifoldPlot, ParticlePlotMixin):
187+
"""A plot of particle properties as function of another property"""
188+
180189
def __init__(
181190
self,
182191
particles=None,
@@ -189,7 +198,6 @@ def __init__(
189198
**kwargs,
190199
):
191200
"""
192-
A plot of particle properties as function of another property.
193201
194202
Args:
195203
particles (Any): Particles data to plot.

xplt/phasespace.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
class PhaseSpacePlot(XPlot, ParticlePlotMixin):
27+
"""A plot for phase space distributions"""
28+
2729
def __init__(
2830
self,
2931
particles=None,
@@ -53,7 +55,6 @@ def __init__(
5355
**kwargs,
5456
):
5557
"""
56-
A plot for phase space distributions
5758
5859
Args:
5960
particles (Any): A dictionary with particle information
@@ -64,22 +65,22 @@ def __init__(
6465
In addition, abbreviations for x-y-parameter pairs are supported (e.g. 'x' for 'x-px').
6566
For normalized coordinates, use uppercase letters (e.g. 'X' for 'X-Px').
6667
plot (str): Defines the type of plot. Can be 'auto', 'scatter' or 'hist'. Default is 'auto' for which the plot type is chosen automatically based on the number of particles.
67-
scatter_kwargs (dict): Additional kwargs for scatter plot
68-
hist_kwargs (dist): Additional kwargs for 2D histogram plot (see :meth:`matplotlib.pyplot.hexbin`)
68+
scatter_kwargs (dict): Additional kwargs for scatter plot, see :meth:`matplotlib.axes.Axes.scatter`.
69+
hist_kwargs (dist): Additional kwargs for 2D histogram plot, see :meth:`matplotlib.axes.Axes.hexbin`.
6970
mask (Any): An index mask to select particles to plot. If None, all particles are plotted.
7071
masks (list[mask]): List of masks for each subplot.
7172
color (str | list[str]): Properties defining the color of points for the scatter plot(s). Implies plot='scatter'. Pass a list of properties to use different values for each subplot
7273
cmap (str): Colormap to use for the hist plot.
7374
cbar_loc (str): Location of the colorbar, such as 'auto', 'right', 'inside upper right', etc.
7475
Use None to disable colorbar.
7576
projections (bool | str | list): Add histogrammed projections onto axis. Can be True, False, "x", "y", "auto" or a list of these for each subplot
76-
projections_kwargs (dict): Additional kwargs for histogram projection (step plot)
77+
projections_kwargs (dict): Additional kwargs for histogram projection, see :meth:`matplotlib.axes.Axes.step`.
7778
mean (bool | list): Whether to indicate mean of distribution with a cross marker. Boolean or list of booleans for each subplot.
78-
mean_kwargs (dict): Additional kwargs for mean cross
79+
mean_kwargs (dict): Additional kwargs for marker, see :meth:`matplotlib.axes.Axes.plot`.
7980
std (bool | list): Whether to indicate standard deviation of distribution with an ellipse. Boolean or list of booleans for each subplot.
80-
std_kwargs (dict): Additional kwargs for std ellipses.
81+
std_kwargs (dict): Additional kwargs for std ellipses, see :class:`matplotlib.patches.Ellipse`.
8182
percentiles (list): List of percentiles (in percent) to indicate in the distribution with ellipses. Can also be a list of lists for each subplot.
82-
percentile_kwargs (dict): Additional kwargs for percentile ellipses.
83+
percentile_kwargs (dict): Additional kwargs for percentile ellipses, see :class:`matplotlib.patches.Ellipse`.
8384
ncols (int | None): Number of columns in subplot layout. If None, the layout is determined automatically.
8485
nrows (int | None): Number of columns in subplot layout. If None, the layout is determined automatically.
8586
titles (list[str]): List of titles for each subplot or 'auto' to automatically set titles based on plot kind.

xplt/timestructure.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def binned_timeseries(times, *, what=None, n=None, dt=None, t_range=None, moment
9595

9696

9797
class TimePlot(ParticlesPlot):
98+
"""A plot of particle properties as function of time"""
99+
98100
def __init__(self, particles=None, kind="x+y", **kwargs):
99101
"""
100102
A thin wrapper around the ParticlesPlot plotting data as function of time.
@@ -116,6 +118,8 @@ def __init__(self, particles=None, kind="x+y", **kwargs):
116118

117119

118120
class TimeBinPlot(XManifoldPlot, ParticlePlotMixin):
121+
"""A binned histogram plot of particles as function of times"""
122+
119123
def __init__(
120124
self,
121125
particles=None,
@@ -132,7 +136,6 @@ def __init__(
132136
**kwargs,
133137
):
134138
"""
135-
A binned histogram plot of particles as function of times.
136139
137140
The plot is based on the particle arrival time, which is:
138141
- For circular lines: at_turn / frev - zeta / beta / c0
@@ -309,6 +312,8 @@ def update(self, particles, mask=None, autoscale=False):
309312

310313

311314
class TimeFFTPlot(XManifoldPlot, ParticlePlotMixin):
315+
"""A frequency plot based on particle arrival times"""
316+
312317
def __init__(
313318
self,
314319
particles=None,
@@ -324,7 +329,6 @@ def __init__(
324329
**kwargs,
325330
):
326331
"""
327-
A frequency plot based on particle arrival times.
328332
329333
The particle arrival time is:
330334
- For circular lines: at_turn / frev - zeta / beta / c0
@@ -521,6 +525,8 @@ def plot_harmonics(self, f, df=0, *, n=20, **plot_kwargs):
521525

522526

523527
class TimeIntervalPlot(XManifoldPlot, ParticlePlotMixin):
528+
"""A histogram plot of particle arrival intervals (i.e. delay between consecutive particles)"""
529+
524530
def __init__(
525531
self,
526532
particles=None,
@@ -536,7 +542,6 @@ def __init__(
536542
**kwargs,
537543
):
538544
"""
539-
A histogram plot of particle arrival intervals (i.e. delay between consecutive particles).
540545
541546
The plot is based on the particle arrival time, which is:
542547
- For circular lines: at_turn / frev - zeta / beta / c0
@@ -819,6 +824,8 @@ def _format_metric_axes(self, add_compatible_twin_axes):
819824

820825

821826
class TimeVariationPlot(XManifoldPlot, ParticlePlotMixin, MetricesMixin):
827+
"""Plot variability of particle time on microscopic scale as function of time on macroscopic scale"""
828+
822829
def __init__(
823830
self,
824831
particles=None,
@@ -836,7 +843,6 @@ def __init__(
836843
**kwargs,
837844
):
838845
"""
839-
Plot variability of particle time on microscopic scale as function of time on macroscopic scale
840846
841847
The particle arrival times are histogramed into counting bins, the width of which
842848
corresponds to the time resolution of a detector (``counting_dt``).
@@ -979,6 +985,8 @@ def update(self, particles, mask=None, autoscale=False):
979985

980986

981987
class TimeVariationScalePlot(XManifoldPlot, ParticlePlotMixin, MetricesMixin):
988+
"""Plot variability of particle time as function of timescale"""
989+
982990
def __init__(
983991
self,
984992
particles=None,
@@ -996,7 +1004,7 @@ def __init__(
9961004
ignore_insufficient_statistics=False,
9971005
**kwargs,
9981006
):
999-
"""Plot variability of particle time as function of timescale
1007+
"""
10001008
10011009
The particle arrival times are histogramed into counting bins, the width of which
10021010
corresponds to the time resolution of a detector (``counting_dt``).
@@ -1200,8 +1208,10 @@ def update(
12001208

12011209

12021210
class TimeBinMetricHelper(ParticlePlotMixin, MetricesMixin):
1211+
"""Helper class for binning and evaluating metrices on timeseries data"""
1212+
12031213
def __init__(self, *, twiss=None, beta=None, frev=None, circumference=None):
1204-
"""Helper class for binning and evaluating metrices on timeseries data.
1214+
"""
12051215
12061216
Args:
12071217
twiss (dict | None): Twiss parameters (alfx, alfy, betx and bety) to use for conversion to normalized phase space coordinates.

xplt/twiss.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818

1919
class TwissPlot(XManifoldPlot):
20+
"""A plot for twiss parameters and closed orbit"""
21+
2022
def __init__(self, twiss=None, kind="bet-dx,x+y", *, line=None, line_kwargs={}, **kwargs):
2123
"""
22-
A plot for twiss parameters and closed orbit
2324
2425
Args:
2526
twiss (Any): Dictionary with twiss information

0 commit comments

Comments
 (0)