Skip to content
Snippets Groups Projects
Commit 58689f59 authored by Watanyu Foosang's avatar Watanyu Foosang
Browse files

Edit plot_optics

- ring has been removed from the input.
- for loop has been removed and replaced by linspace function
parent c165102f
Branches
Tags
No related merge requests found
...@@ -245,20 +245,21 @@ class Optics: ...@@ -245,20 +245,21 @@ class Optics:
self.dispY(position), self.disppY(position)] self.dispY(position), self.disppY(position)]
return np.array(dispersion) return np.array(dispersion)
def plot_optics(self, ring, var, option): def plot_optics(self, var, option, n_points=1000):
""" """
Plotting optical variables. Plotting optical variables.
Parameters Parameters
---------- ----------
ring : Synchrotron object
var : {"beta", "alpha", "gamma", "dispersion"} var : {"beta", "alpha", "gamma", "dispersion"}
Optical variable to be plotted Optical variable to be plotted.
option : str option : str
If var = "beta", "alpha" and "gamma", option = {"x","y"} specifying If var = "beta", "alpha" and "gamma", option = {"x","y"} specifying
the axis of interest. the axis of interest.
If var = "dispersion", option = {"x","px","y","py"} specifying the If var = "dispersion", option = {"x","px","y","py"} specifying the
axis of interest for the dispersion function or its derivative. axis of interest for the dispersion function or its derivative.
n_points : int
Number of points on the plot. The default value is 1000.
""" """
...@@ -271,6 +272,7 @@ class Optics: ...@@ -271,6 +272,7 @@ class Optics:
label = ["D$_{x}$ (m)", "D'$_{x}$", "D$_{y}$ (m)", "D'$_{y}$"] label = ["D$_{x}$ (m)", "D'$_{x}$", "D$_{y}$ (m)", "D'$_{y}$"]
plt.ylabel(label[option_dict[option]]) plt.ylabel(label[option_dict[option]])
elif var=="beta" or var=="alpha" or var=="gamma": elif var=="beta" or var=="alpha" or var=="gamma":
option_dict = {"x":0, "y":1} option_dict = {"x":0, "y":1}
...@@ -283,17 +285,15 @@ class Optics: ...@@ -283,17 +285,15 @@ class Optics:
unit = {"beta":" (m)", "alpha":"", "gamma":" (m$^{-1}$)"} unit = {"beta":" (m)", "alpha":"", "gamma":" (m$^{-1}$)"}
plt.ylabel(label_dict[var] + label_sup + unit[var]) plt.ylabel(label_dict[var] + label_sup + unit[var])
else: else:
raise ValueError("Variable name is not found.") raise ValueError("Variable name is not found.")
var_list = [] position = np.linspace(0, self.lattice.circumference, int(n_points))
position_list = [] var_list = var_dict[var](position)[option_dict[option]]
for i in range (int(ring.L)): plt.plot(position,var_list)
var_list.append(var_dict[var](i)[option_dict[option]])
position_list.append(i)
plt.plot(position_list, var_list)
plt.xlabel("position (m)") plt.xlabel("position (m)")
...@@ -566,3 +566,4 @@ class PhyisicalModel: ...@@ -566,3 +566,4 @@ class PhyisicalModel:
axs[1].set(xlabel="Longitudinal position [m]", axs[1].set(xlabel="Longitudinal position [m]",
ylabel="Vertical aperture [mm]") ylabel="Vertical aperture [mm]")
axs[1].legend(["Top","Bottom"]) axs[1].legend(["Top","Bottom"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment