Commit 48d3e342 authored by Tong Zhang's avatar Tong Zhang
Browse files

ENH: Support trajectory drawing.

parent 54faa8c6
...@@ -100,15 +100,9 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow): ...@@ -100,15 +100,9 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
# initial elemlist_cbb # initial elemlist_cbb
self.init_elemlist() self.init_elemlist()
# envelope curves # envelope and trajectory
o = self.envelope_plot self.__init_envelope_plot()
o.add_curve() self.__init_trajectory_plot()
o.setLineID(0) # X
o.setLineColor(QColor('#0000FF'))
o.setLineLabel("$\sigma_x$")
o.setLineID(1) # Y
o.setLineColor(QColor('#FF0000'))
o.setLineLabel("$\sigma_y$")
# ellipse drawing figure configuration # ellipse drawing figure configuration
for o in (self.xlim_x1_lineEdit, self.xlim_x2_lineEdit, ): for o in (self.xlim_x1_lineEdit, self.xlim_x2_lineEdit, ):
...@@ -137,6 +131,30 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow): ...@@ -137,6 +131,30 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
self.on_auto_xlim() self.on_auto_xlim()
self.on_auto_ylim() self.on_auto_ylim()
def __init_envelope_plot(self):
"""Initialize plot area for beam envelope.
"""
o = self.envelope_plot
o.add_curve()
o.setLineID(0) # X
o.setLineColor(QColor('#0000FF'))
o.setLineLabel("$\sigma_x$")
o.setLineID(1) # Y
o.setLineColor(QColor('#FF0000'))
o.setLineLabel("$\sigma_y$")
def __init_trajectory_plot(self):
"""Initialize plot area for beam trajectory.
"""
o = self.trajectory_plot
o.add_curve()
o.setLineID(0) # X
o.setLineColor(QColor('#0000FF'))
o.setLineLabel("$x_0$")
o.setLineID(1) # Y
o.setLineColor(QColor('#FF0000'))
o.setLineLabel("$y_0$")
@pyqtSlot('QString') @pyqtSlot('QString')
def on_quad1_name_changed(self, name: str) -> None: def on_quad1_name_changed(self, name: str) -> None:
"""When the current selected quad name is changed, do: """When the current selected quad name is changed, do:
...@@ -185,26 +203,31 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow): ...@@ -185,26 +203,31 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
Here I'm drawing the beam envelop along the entire beamline, try to Here I'm drawing the beam envelop along the entire beamline, try to
replace with your routine for beam ellipse drawing. replace with your routine for beam ellipse drawing.
""" """
self.draw_envelope()
self.draw_ellipse() self.draw_ellipse()
self.draw_envelope()
self.draw_trajectory()
def draw_envelope(self): def draw_envelope(self):
"""Draw beam envelop onto the figure area. """Draw beam envelop onto the figure area.
""" """
results_dict = self.fm.collect_data(self.results, 'pos', 'xrms', results_dict = self.fm.collect_data(self.results, 'pos', 'xrms', 'yrms')
'yrms')
pos = results_dict['pos'] pos = results_dict['pos']
xrms = results_dict['xrms'] xrms = results_dict['xrms']
yrms = results_dict['yrms'] yrms = results_dict['yrms']
# update drawing for line_id, urms in zip((0, 1), (xrms, yrms)):
# Note: matplotlibbaseWidget is used here for generic drawing, self.envelope_plot.setLineID(line_id)
# for curve visualization, matplotlibCurveWidget is a better choice. self.envelope_plot.update_curve(pos, urms)
# x
self.envelope_plot.setLineID(0) def draw_trajectory(self):
self.envelope_plot.update_curve(pos, xrms) """Draw beam centroid trajectory onto the figure area.
# y """
self.envelope_plot.setLineID(1) results_dict = self.fm.collect_data(self.results, 'pos', 'xcen', 'ycen')
self.envelope_plot.update_curve(pos, yrms) pos = results_dict['pos']
xcen = results_dict['xcen']
ycen = results_dict['ycen']
for line_id, ucen in zip((0, 1), (xcen, ycen)):
self.trajectory_plot.setLineID(line_id)
self.trajectory_plot.update_curve(pos, ucen)
@pyqtSlot() @pyqtSlot()
def draw_ellipse(self): def draw_ellipse(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment