Esempio n. 1
0
def draw_patch(ax, position, length, style):
    at = to_ui('s', position)
    if length != 0:
        patch_w = to_ui('l', length)
        return ax.axvspan(at, at + patch_w, **style)
    else:
        return ax.axvline(at, **style)
Esempio n. 2
0
def draw_patch(ax, position, length, style):
    at = to_ui('s', position)
    if length != 0:
        patch_w = to_ui('l', length)
        return ax.axvspan(at, at + patch_w, **style)
    else:
        return ax.axvline(at, **style)
Esempio n. 3
0
def plot_constraint(ax, scene, constraint):
    """Draw one constraint representation in the graph."""
    elem, pos, axis, val = constraint
    style = scene.config['constraint_style']
    return LineBundle(
        ax.plot(to_ui('s', pos), to_ui(axis, val), **style) if axis in
        ax.y_name else ())
Esempio n. 4
0
def plot_constraint(ax, scene, constraint):
    """Draw one constraint representation in the graph."""
    elem, pos, axis, val = constraint
    style = scene.config['constraint_style']
    return LineBundle(ax.plot(
        to_ui('s', pos),
        to_ui(axis, val),
        **style) if axis in ax.y_name else ())
Esempio n. 5
0
    def update(self, elem_index=0):
        self.figure.clf()
        axx = self.figure.add_subplot(121)
        axy = self.figure.add_subplot(122)

        def ellipse(ax, alfa, beta, gamma, eps):
            phi = atan2(2*alfa, gamma-beta) / 2

            # See: ELLIPTICAL TRANSFORMATIONS FOR BEAM OPTICS, R.B. Moore, 2004
            # http://www.physics.mcgill.ca/~moore/Notes/Ellipses.pdf
            H = (beta + gamma) / 2
            w = sqrt(eps/2) * (sqrt(H+1) - sqrt(H-1))
            h = sqrt(eps/2) * (sqrt(H+1) + sqrt(H-1))

            # Same as:
            # c, s = cos(phi), sin(phi)
            # R = np.array([[c, -s], [s, c]])
            # M = np.array([[beta, -alfa], [-alfa, gamma]])
            # T = R.T.dot(M).dot(R)
            # w = sqrt(eps*T[0,0])
            # h = sqrt(eps*T[1,1])

            dx = sqrt(eps*beta)
            dy = sqrt(eps*gamma)
            ax.set_xlim(-dx*1.2, dx*1.2)
            ax.set_ylim(-dy*1.2, dy*1.2)

            # zorder needed to draw on top of grid:
            ax.add_patch(Ellipse((0, 0), 2*w, 2*h, phi/pi*180,
                                 fill=False, zorder=5))
            ax.grid(True)

        # FIXME: gui_units
        twiss = to_ui(self.model.get_elem_twiss(elem_index))
        ellipse(axx, twiss.alfx, twiss.betx, twiss.gamx, twiss.ex)
        ellipse(axy, twiss.alfy, twiss.bety, twiss.gamy, twiss.ey)

        axx.set_xlabel("x [{}]".format(ui_units.label('x')))
        axy.set_xlabel("y [{}]".format(ui_units.label('y')))
        axx.set_ylabel("px | py")

        self.figure.tight_layout()
        self.canvas.draw()
Esempio n. 6
0
 def get_ui_value(self):
     return to_ui(self.name, self.value)
Esempio n. 7
0
def _get_curve_data(data, name):
    try:
        return to_ui(name, data[name])
    except KeyError:
        logging.debug("Missing curve data {!r}, we only know: {}"
                      .format(name, ','.join(data)))
Esempio n. 8
0
def _get_curve_data(data, name):
    try:
        return to_ui(name, data[name])
    except KeyError:
        logging.debug("Missing curve data {!r}, we only know: {}".format(
            name, ','.join(data)))