Skip to content
Snippets Groups Projects
Commit 6862d27c authored by Alexis GAMELIN's avatar Alexis GAMELIN
Browse files

Add option to Plot/Streak BunchSpectrum to normalise the spectrum data

parent d9f2c4be
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ import matplotlib as mpl ...@@ -13,6 +13,7 @@ import matplotlib as mpl
import seaborn as sns import seaborn as sns
import h5py as hp import h5py as hp
import random import random
from scipy.stats import gmean
def plot_beamdata(filenames, dataset="mean", dimension="tau", stat_var="mean", def plot_beamdata(filenames, dataset="mean", dimension="tau", stat_var="mean",
x_var="time", turn=None, legend=None): x_var="time", turn=None, legend=None):
...@@ -629,7 +630,8 @@ def plot_wakedata(filename, bunch_number, wake_type="Wlong", start=0, ...@@ -629,7 +630,8 @@ def plot_wakedata(filename, bunch_number, wake_type="Wlong", start=0,
return fig2 return fig2
def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau", def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau",
turns=None, fs=None, log_scale=True, legend=None): turns=None, fs=None, log_scale=True, legend=None,
norm=False):
""" """
Plot coherent and incoherent spectrum data. Plot coherent and incoherent spectrum data.
...@@ -659,6 +661,9 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau", ...@@ -659,6 +661,9 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau",
legend : list of str, optional legend : list of str, optional
Legend to add for each file. Legend to add for each file.
The default is None. The default is None.
norm : bool, optional
If True, normalise the data of each spectrum by its geometric mean.
The default is False.
Return Return
------ ------
...@@ -711,6 +716,8 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau", ...@@ -711,6 +716,8 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau",
for idx in turn_index: for idx in turn_index:
y_var = group[dataset][dim_dict[dim],:,idx] y_var = group[dataset][dim_dict[dim],:,idx]
if norm is True:
y_var = y_var/gmean(y_var)
ax.plot(x_var, y_var) ax.plot(x_var, y_var)
if log_scale is True: if log_scale is True:
...@@ -731,7 +738,8 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau", ...@@ -731,7 +738,8 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau",
return fig return fig
def streak_bunchspectrum(filename, bunch_number, dataset="incoherent", def streak_bunchspectrum(filename, bunch_number, dataset="incoherent",
dim="tau", fs=None, log_scale=True, fmin=None, fmax=None, turns=None): dim="tau", fs=None, log_scale=True, fmin=None,
fmax=None, turns=None, norm=False):
""" """
Plot 3D data recorded by the BunchSpectrumMonitor. Plot 3D data recorded by the BunchSpectrumMonitor.
...@@ -759,6 +767,9 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent", ...@@ -759,6 +767,9 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent",
If not None, the plot is limitted to values smaller than fmax. If not None, the plot is limitted to values smaller than fmax.
turns : array, optional turns : array, optional
If not None, only the turn numbers in the turns array are plotted. If not None, only the turn numbers in the turns array are plotted.
norm : bool, optional
If True, normalise the data of each spectrum by its geometric mean.
The default is False.
Returns Returns
------- -------
...@@ -808,6 +819,9 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent", ...@@ -808,6 +819,9 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent",
ind = (x_var > fmin) & (x_var < fmax) ind = (x_var > fmin) & (x_var < fmax)
x_var=x_var[ind] x_var=x_var[ind]
data = data[ind,:] data = data[ind,:]
if norm is True:
data = data/gmean(data)
ylabel = "Turn number" ylabel = "Turn number"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment