Example: RingMultiBunch
[1]:
from opal.opal import load_dataset
ds = load_dataset('./RingMultiBunch/', fname='RingMultiBunch.h5')
[2]:
print ( ds )
H5 dataset.
Number of steps: 4
Available step attributes (42):
#sigma
#varepsilon
#varepsilon-geom
AZIMUTH
B-head
B-ref
B-tail
CHARGE
E-head
E-ref
E-tail
ELEVATION
ENERGY
GlobalTrackStep
LOCAL
LocalTrackStep
MASS
NumBunch
OPAL_flavour
REFPR
REFPT
REFPZ
REFR
REFTHETA
REFZ
RMSP
RMSX
RefPartP
RefPartR
SPOS
Step
SteptoLastInj
TIME
centroid
dE
maxP
maxX
minP
minX
spos-head
spos-ref
spos-tail
Available step datasets (10):
bin
id
mass
px
py
pz
q
x
y
z
[3]:
from opal.visualization.styles import load_style
load_style('jupyter')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[3], line 3
1 from opal.visualization.styles import load_style
----> 3 load_style('jupyter')
File ~/pyOPALTools/opal/visualization/styles/load_style.py:31, in load_style(use)
29 from opal.utilities.logger import opal_logger
30 opal_logger.info("Loading '" + use + "' plotting style")
---> 31 eval(use + '()')
File <string>:1
File ~/pyOPALTools/opal/visualization/styles/jupyter.py:31, in jupyter()
29 # reset
30 from opal.visualization.styles.default import default
---> 31 default()
33 if mpl.__version__ < '2':
34 opal_logger.error('jupyter style not available for matplotlib version ' + mpl.__version__)
File ~/pyOPALTools/opal/visualization/styles/default.py:38, in default()
36 mpl.rcParams['lines.linestyle'] = '-' # solid line
37 mpl.rcParams['lines.color'] = 'C0' # has no affect on plot(); see axes.prop_cycle
---> 38 mpl.rcParams['lines.marker'] = None # the default marker
39 mpl.rcParams['lines.markeredgewidth'] = 1.0 # the line width around the marker symbol
40 mpl.rcParams['lines.markersize'] = 6 # markersize, in points
File /usr/local/lib/python3.8/dist-packages/matplotlib/__init__.py:722, in RcParams.__setitem__(self, key, val)
720 cval = self.validate[key](val)
721 except ValueError as ve:
--> 722 raise ValueError(f"Key {key}: {ve}") from None
723 self._set(key, cval)
724 except KeyError as err:
ValueError: Key lines.marker: Could not convert None to str
[4]:
plt = ds.plot_phase_space('x', 'y', xsci=True, ysci=True, step=3, bins=[0, 1])
plt.legend(['bin 0', 'bin 1'], markerscale=10)
plt.show()
[5]:
plt = ds.plot_phase_space('x', 'z', xsci=True, ysci=True, step=3, bins=[0, 1])
plt.legend(['bin 0', 'bin 1'], markerscale=10)
plt.show()
[6]:
try:
print ( "Central moment: " + str(ds.moment('x', k=1, bunch=1, step=3)) )
print ( "Arithmetic mean: " + str(ds.mean('x', bunch=1, step=3)) )
print ( "Skewness: " + str(ds.skew('x', bunch=1, step=3)) )
print ( "Kurtosis: " + str(ds.kurtosis('x', bunch=1, step=3)) )
print ( "Halo: " + str(ds.halo_ellipsoidal_beam('x', bunch=1, step=3)) )
print ( "Halo (2D): " + str(ds.halo_2d_ellipsoidal_beam('x', bunch=1, step=3)) )
print ( "Radial halo: " + str(ds.radial_halo_ellipsoidal_beam(bunch=1, step=3)) )
print ( "Radial halo (2D): " + str(ds.radial_halo_2d_ellipsoidal_beam(azimuth=110, bunch=1, step=3)) )
except Exception as e:
print ( e )
Central moment: 0.0
Arithmetic mean: 2.1856373634845316
Skewness: 0.056635976870648995
Kurtosis: -1.446404768615836
Halo: -0.5892619114729787
Halo (2D): 0.4246858053662188
Radial halo: -0.5896525325693598
Radial halo (2D): 0.09139639984105807
[7]:
minima = ds.find_beams('x', step=3)[0]
print ( minima )
[30 68]
[8]:
kde = ds.gaussian_kde('x', step=3)
import numpy as np
points = np.linspace(2.1, 2.3, 500)
pdf = kde.pdf(points)
plt.plot(points, pdf)
plt.xlabel('x [m]')
plt.ylabel('evaluated kde')
plt.show()
[9]:
plt = ds.plot_histogram('x', step=3, bins=600)
plt.show()
[10]:
plt = ds.plot_joint(xvar='x', yvar='y', join='contour', step=3)
plt.show()
2024-09-26 23:06:51,112 - opal - ERROR - __init__() got an unexpected keyword argument 'size'
Traceback (most recent call last):
File "/home/opalci/pyOPALTools/opal/visualization/H5Plotter.py", line 309, in plot_joint
plt = impl_plots.plot_joint(xdata, xlabel,
File "/home/opalci/pyOPALTools/opal/visualization/statistics/impl_plots.py", line 108, in plot_joint
g = sns.JointGrid(x=xdata, y=ydata, size=size)
TypeError: __init__() got an unexpected keyword argument 'size'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/pyOPALTools/opal/visualization/H5Plotter.py:309, in H5Plotter.plot_joint(self, xvar, yvar, join, **kwargs)
307 ylabel = self.ds.getLabelWithUnit(yvar)
--> 309 plt = impl_plots.plot_joint(xdata, xlabel,
310 ydata, ylabel,
311 join, **kwargs)
313 return plt
File ~/pyOPALTools/opal/visualization/statistics/impl_plots.py:108, in plot_joint(xdata, xlab, ydata, ylab, join, **kwargs)
106 cmap = kwargs.pop('cmap', 'Blues_d')
--> 108 g = sns.JointGrid(x=xdata, y=ydata, size=size)
110 hasJoin = False
TypeError: __init__() got an unexpected keyword argument 'size'
During handling of the above exception, another exception occurred:
UnboundLocalError Traceback (most recent call last)
Cell In[10], line 1
----> 1 plt = ds.plot_joint(xvar='x', yvar='y', join='contour', step=3)
3 plt.show()
File ~/pyOPALTools/opal/visualization/H5Plotter.py:316, in H5Plotter.plot_joint(self, xvar, yvar, join, **kwargs)
314 except Exception as ex:
315 opal_logger.exception(ex)
--> 316 return plt.figure()
UnboundLocalError: local variable 'plt' referenced before assignment
[11]:
plt = ds.plot_joint(xvar='x', yvar='y', join='scatter', marginals='kde', step=3)
plt.show()
2024-09-26 23:06:51,268 - opal - ERROR - __init__() got an unexpected keyword argument 'size'
Traceback (most recent call last):
File "/home/opalci/pyOPALTools/opal/visualization/H5Plotter.py", line 309, in plot_joint
plt = impl_plots.plot_joint(xdata, xlabel,
File "/home/opalci/pyOPALTools/opal/visualization/statistics/impl_plots.py", line 108, in plot_joint
g = sns.JointGrid(x=xdata, y=ydata, size=size)
TypeError: __init__() got an unexpected keyword argument 'size'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/pyOPALTools/opal/visualization/H5Plotter.py:309, in H5Plotter.plot_joint(self, xvar, yvar, join, **kwargs)
307 ylabel = self.ds.getLabelWithUnit(yvar)
--> 309 plt = impl_plots.plot_joint(xdata, xlabel,
310 ydata, ylabel,
311 join, **kwargs)
313 return plt
File ~/pyOPALTools/opal/visualization/statistics/impl_plots.py:108, in plot_joint(xdata, xlab, ydata, ylab, join, **kwargs)
106 cmap = kwargs.pop('cmap', 'Blues_d')
--> 108 g = sns.JointGrid(x=xdata, y=ydata, size=size)
110 hasJoin = False
TypeError: __init__() got an unexpected keyword argument 'size'
During handling of the above exception, another exception occurred:
UnboundLocalError Traceback (most recent call last)
Cell In[11], line 1
----> 1 plt = ds.plot_joint(xvar='x', yvar='y', join='scatter', marginals='kde', step=3)
3 plt.show()
File ~/pyOPALTools/opal/visualization/H5Plotter.py:316, in H5Plotter.plot_joint(self, xvar, yvar, join, **kwargs)
314 except Exception as ex:
315 opal_logger.exception(ex)
--> 316 return plt.figure()
UnboundLocalError: local variable 'plt' referenced before assignment
[12]:
help(ds.plot_joint)
Help on method plot_joint in module opal.visualization.H5Plotter:
plot_joint(xvar, yvar, join, **kwargs) method of opal.datasets.H5Dataset.H5Dataset instance
Do a joint plot (marginals + contour / scatter)
Parameters
----------
xvar : str
x-axis variable to consider
yvar : str
y-axis variable to consider
join : str
'all', 'contour' or 'scatter'
step : int, optional
Step of dataset
See Also
--------
visualization.statistics.impl_plots.plot_joint
Returns
-------
matplotlib.pyplot
Plot handle
[13]:
plt = ds.plot_joint(xvar='x', yvar='y', join='all', marginals='kde+hist', step=3)
plt.show()
2024-09-26 23:06:51,355 - opal - ERROR - __init__() got an unexpected keyword argument 'size'
Traceback (most recent call last):
File "/home/opalci/pyOPALTools/opal/visualization/H5Plotter.py", line 309, in plot_joint
plt = impl_plots.plot_joint(xdata, xlabel,
File "/home/opalci/pyOPALTools/opal/visualization/statistics/impl_plots.py", line 108, in plot_joint
g = sns.JointGrid(x=xdata, y=ydata, size=size)
TypeError: __init__() got an unexpected keyword argument 'size'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/pyOPALTools/opal/visualization/H5Plotter.py:309, in H5Plotter.plot_joint(self, xvar, yvar, join, **kwargs)
307 ylabel = self.ds.getLabelWithUnit(yvar)
--> 309 plt = impl_plots.plot_joint(xdata, xlabel,
310 ydata, ylabel,
311 join, **kwargs)
313 return plt
File ~/pyOPALTools/opal/visualization/statistics/impl_plots.py:108, in plot_joint(xdata, xlab, ydata, ylab, join, **kwargs)
106 cmap = kwargs.pop('cmap', 'Blues_d')
--> 108 g = sns.JointGrid(x=xdata, y=ydata, size=size)
110 hasJoin = False
TypeError: __init__() got an unexpected keyword argument 'size'
During handling of the above exception, another exception occurred:
UnboundLocalError Traceback (most recent call last)
Cell In[13], line 1
----> 1 plt = ds.plot_joint(xvar='x', yvar='y', join='all', marginals='kde+hist', step=3)
3 plt.show()
File ~/pyOPALTools/opal/visualization/H5Plotter.py:316, in H5Plotter.plot_joint(self, xvar, yvar, join, **kwargs)
314 except Exception as ex:
315 opal_logger.exception(ex)
--> 316 return plt.figure()
UnboundLocalError: local variable 'plt' referenced before assignment
[14]:
plt = ds.plot_density_scipy(xvar='x', yvar='y', step=3)
plt.show()
2024-09-26 23:07:13,301 - opal - ERROR - Dimensions of C (300, 300) should be one smaller than X(300) and Y(300) while using shading='flat' see help(pcolormesh)
Traceback (most recent call last):
File "/home/opalci/pyOPALTools/opal/visualization/H5Plotter.py", line 397, in plot_density_scipy
pc = plt.pcolormesh(xi, yi, zi.reshape(xi.shape),
File "/usr/local/lib/python3.8/dist-packages/matplotlib/pyplot.py", line 2773, in pcolormesh
__ret = gca().pcolormesh(
File "/usr/local/lib/python3.8/dist-packages/matplotlib/__init__.py", line 1446, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/usr/local/lib/python3.8/dist-packages/matplotlib/axes/_axes.py", line 6218, in pcolormesh
X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
File "/usr/local/lib/python3.8/dist-packages/matplotlib/axes/_axes.py", line 5749, in _pcolorargs
raise TypeError(f"Dimensions of C {C.shape} should"
TypeError: Dimensions of C (300, 300) should be one smaller than X(300) and Y(300) while using shading='flat' see help(pcolormesh)
<Figure size 614.4x460.8 with 0 Axes>
[15]:
plt = ds.plot_density(xvar='x', yvar='y', step=3)
plt.show()