From 7ab381fa9eb6bc10dbe1d784ca12a4877a85c48f Mon Sep 17 00:00:00 2001
From: Gamelin Alexis <gamelin@synchrotron-soleil.fr>
Date: Fri, 23 Apr 2021 10:59:08 +0200
Subject: [PATCH] Fix monitor plotting

Fix plot_profiledata error due to change to center instead of bins
Fix plot_cavitydata legends and turn selection
---
 tracking/monitors/plotting.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tracking/monitors/plotting.py b/tracking/monitors/plotting.py
index d0826c9..9078150 100644
--- a/tracking/monitors/plotting.py
+++ b/tracking/monitors/plotting.py
@@ -328,7 +328,7 @@ def plot_profiledata(filename, bunch_number, dimension="tau", start=0,
         turn_index = start_index + i * step / save_every 
         turn_index_array[i] = turn_index
         # construct an array of bin mids
-        x_var[i,:] = 0.5*(l_bound[:-1,turn_index]+l_bound[1:,turn_index])
+        x_var[i,:] = l_bound[:,turn_index]
         
     if profile_plot is True:
         fig, ax = plt.subplots()
@@ -581,7 +581,7 @@ def plot_cavitydata(filename, cavity_name, phasor="cavity",
         data = [cavity_data["cavity_phasor_record"][bunch_number,:], 
                 cavity_data["beam_phasor_record"][bunch_number,:]]
 
-        ylabel1 = labels[ph[phasor]] + " voltage [V]"
+        ylabel1 = labels[ph[phasor]] + " voltage [MV]"
         ylabel2 = labels[ph[phasor]] + " phase [rad]"
         
         fig, ax = plt.subplots()
@@ -599,16 +599,18 @@ def plot_cavitydata(filename, cavity_name, phasor="cavity",
         twin.yaxis.label.set_color("b")
         
     if plot_type == "turn":
-    
+        
+        index = time == turn
+        
         ph = {"cavity":0, "beam":1}
-        data = [cavity_data["cavity_phasor_record"][:,turn], 
-                cavity_data["beam_phasor_record"][:,turn]]
+        data = [cavity_data["cavity_phasor_record"][:,index], 
+                cavity_data["beam_phasor_record"][:,index]]
         labels = ["Cavity", "Beam"]
         
         h=len(data[0])
         x=np.arange(h)
 
-        ylabel1 = labels[ph[phasor]] + " voltage [V]"
+        ylabel1 = labels[ph[phasor]] + " voltage [MV]"
         ylabel2 = labels[ph[phasor]] + " phase [rad]"
         
         fig, ax = plt.subplots()
@@ -629,7 +631,7 @@ def plot_cavitydata(filename, cavity_name, phasor="cavity",
         
         if plot_type == "streak_volt":
             data = np.transpose(np.abs(cavity_data["cavity_phasor_record"][:,:])*1e-6)
-            ylabel = labels[ph[phasor]] + " voltage [V]"
+            ylabel = labels[ph[phasor]] + " voltage [MV]"
         elif plot_type == "streak_phase":
             data = np.transpose(np.angle(cavity_data["cavity_phasor_record"][:,:]))
             ylabel = labels[ph[phasor]] + " phase [rad]"
-- 
GitLab