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

Plotting function improvements

Fix error on plot_beamdata.
Add option to specify ylim to streak_bunchspectrum and to streak_beamspectrum.
parent 5cc38f55
No related branches found
No related tags found
No related merge requests found
...@@ -100,7 +100,7 @@ def plot_beamdata(filenames, dataset="mean", dimension="tau", stat_var="mean", ...@@ -100,7 +100,7 @@ def plot_beamdata(filenames, dataset="mean", dimension="tau", stat_var="mean",
if turn is None: if turn is None:
idx = -1 idx = -1
else: else:
idx = np.where(time == int(turn)) idx = np.where(time == int(turn))[0]
if (idx.size == 0): if (idx.size == 0):
raise ValueError("Turn is not valid.") raise ValueError("Turn is not valid.")
...@@ -748,7 +748,7 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau", ...@@ -748,7 +748,7 @@ def plot_bunchspectrum(filenames, bunch_number, dataset="incoherent", dim="tau",
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, dim="tau", fs=None, log_scale=True, fmin=None,
fmax=None, turns=None, norm=False): fmax=None, turns=None, norm=False, ylim=None):
""" """
Plot 3D data recorded by the BunchSpectrumMonitor. Plot 3D data recorded by the BunchSpectrumMonitor.
...@@ -779,6 +779,10 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent", ...@@ -779,6 +779,10 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent",
norm : bool, optional norm : bool, optional
If True, normalise the data of each spectrum by its geometric mean. If True, normalise the data of each spectrum by its geometric mean.
The default is False. The default is False.
ylim : array, optional
If not None, should be array like in the form [ymin, ymax] where ymin
and ymax are the minimum and maxmimum values used in the y axis.
Returns Returns
------- -------
...@@ -795,8 +799,12 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent", ...@@ -795,8 +799,12 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent",
if turns is None: if turns is None:
turn_index = np.where(time == time)[0] turn_index = np.where(time == time)[0]
tmin = time.min() if ylim is None:
tmax = time.max() tmin = time.min()
tmax = time.max()
else:
tmin = ylim[0]
tmax = ylim[1]
else: else:
tmin = turns.min() tmin = turns.min()
tmax = turns.max() tmax = turns.max()
...@@ -831,8 +839,11 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent", ...@@ -831,8 +839,11 @@ def streak_bunchspectrum(filename, bunch_number, dataset="incoherent",
if norm is True: if norm is True:
data = data/gmean(data) data = data/gmean(data)
ylabel = "Turn number" if ylim is None:
ylabel = "Turn number"
else:
ylabel = ""
fig, ax = plt.subplots() fig, ax = plt.subplots()
if dataset == "incoherent": if dataset == "incoherent":
...@@ -937,7 +948,7 @@ def plot_beamspectrum(filenames, dim="tau", turns=None, f0=None, ...@@ -937,7 +948,7 @@ def plot_beamspectrum(filenames, dim="tau", turns=None, f0=None,
return fig return fig
def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None, def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None,
fmax=None, turns=None, norm=False): fmax=None, turns=None, norm=False, ylim=None):
""" """
Plot 3D data recorded by the BeamSpectrumMonitor. Plot 3D data recorded by the BeamSpectrumMonitor.
...@@ -962,6 +973,9 @@ def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None, ...@@ -962,6 +973,9 @@ def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None,
norm : bool, optional norm : bool, optional
If True, normalise the data of each spectrum by its geometric mean. If True, normalise the data of each spectrum by its geometric mean.
The default is False. The default is False.
ylim : array, optional
If not None, should be array like in the form [ymin, ymax] where ymin
and ymax are the minimum and maxmimum values used in the y axis.
Returns Returns
------- -------
...@@ -978,8 +992,12 @@ def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None, ...@@ -978,8 +992,12 @@ def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None,
if turns is None: if turns is None:
turn_index = np.where(time == time)[0] turn_index = np.where(time == time)[0]
tmin = time.min() if ylim is None:
tmax = time.max() tmin = time.min()
tmax = time.max()
else:
tmin = ylim[0]
tmax = ylim[1]
else: else:
tmin = turns.min() tmin = turns.min()
tmax = turns.max() tmax = turns.max()
...@@ -1015,7 +1033,10 @@ def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None, ...@@ -1015,7 +1033,10 @@ def streak_beamspectrum(filename, dim="tau", f0=None, log_scale=True, fmin=None,
if norm is True: if norm is True:
data = data/gmean(data) data = data/gmean(data)
ylabel = "Turn number" if ylim is None:
ylabel = "Turn number"
else:
ylabel = ""
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.set_title("Beam coherent spectrum") ax.set_title("Beam coherent spectrum")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment