Exemplo n.º 1
0
def _measBetaQuad(elem, **kwargs):
    dqk1 = abs(kwargs.get("dqk1", 0.01))
    num_points = kwargs.get("num_points", 5)
    minwait = kwargs.get("minwait", 3)

    qk10 = elem.k1
    qk1 = qk10 + np.linspace(-dqk1, dqk1, num_points)
    nu = np.zeros((num_points, 2), "d")
    for i, k1 in enumerate(qk1):
        v0 = getOrbit()
        elem.k1 = k1
        waitStableOrbit(v0, minwait=minwait, maxwait=15)
        nu[i, :] = getTunes()

    elem.k1 = qk10
    return qk1, nu
Exemplo n.º 2
0
def measDispersion(
    elem, dfmax=5e-7, alphac=3.6261976841792413e-04, gamma=5.870841487279844e3, num_points=5, full=False, verbose=0
):
    """measure dispersion at BPMs

    Parameters
    -----------
    elem : BPM name, list or pattern
    dfmax : float. frequency change (check the unit)
    alphac : float. momentum compaction factor.
    gamma : float. beam energy.
    num_points : int. points to fit line
    full : reserved.

    Returns
    --------
    eta : numpy.array. (nelem, 3) with columns etax, etay and s

    Examples
    ---------
    >>> eta = measDispersion('p*c0[1-4]*')

    """

    eta = alphac - 1.0 / gamma / gamma

    bpmobj = [b for b in getElements(elem) if b.family == "BPM"]
    bpmnames = [b.name for b in bpmobj]
    nbpm = len(bpmnames)

    _logger.info("measure dispersions at %d elements '%s'" % (len(bpmnames), str(elem)))

    f0 = getRfFrequency(handle="setpoint")
    dflst = np.linspace(-abs(dfmax), abs(dfmax), num_points)

    # incase RF does not allow large step change, ramp down first
    for df in np.linspace(0, abs(dfmax), num_points)[1:-1]:
        putRfFrequency(f0 - df)
        time.sleep(2.0 / num_points)

    # avoid a bug in virtac
    obt0 = getOrbit(bpmnames)

    cod = np.zeros((len(dflst), 2 * nbpm), "d")
    for i, df in enumerate(dflst):
        v0 = getOrbit()
        putRfFrequency(f0 + df)
        if verbose > 0:
            print(i, "df=", df, " f=", f0)
        waitStableOrbit(v0)

        # repeat the put/get in case simulator did not response latest results
        obt = getOrbit(bpmnames)
        # print i, obt[0,:2], obt0[0,:2], np.shape(obt), np.shape(obt0)

        cod[i, :nbpm] = obt[:, 0] - obt0[:, 0]
        cod[i, nbpm:] = obt[:, 1] - obt0[:, 1]

    # restore
    for df in np.linspace(0, abs(dfmax), num_points):
        putRfFrequency(f0 + abs(dfmax) - df)
        time.sleep(2.0 / num_points)

    # fitting
    p = np.polyfit(dflst, cod, deg=1)
    disp = -p[0, :] * f0 * eta
    s = np.array([e.sb for e in bpmobj], "d")
    ret = np.zeros((len(bpmobj), 3), "d")
    ret[:, 0] = disp[:nbpm]
    ret[:, 1] = disp[nbpm:]
    ret[:, 2] = s
    if verbose > 0:
        for i, bpm in enumerate(bpmobj):
            print(i, bpm.name, bpm.sb, ret[i, 0], ret[i, 1])
    return ret
Exemplo n.º 3
0
def measDispersion(elem,
                   dfmax=5e-7,
                   alphac=3.6261976841792413e-04,
                   gamma=5.870841487279844e3,
                   num_points=5,
                   full=False,
                   verbose=0):
    """measure dispersion at BPMs

    Parameters
    -----------
    elem : BPM name, list or pattern
    dfmax : float. frequency change (check the unit)
    alphac : float. momentum compaction factor.
    gamma : float. beam energy.
    num_points : int. points to fit line
    full : reserved.

    Returns
    --------
    eta : numpy.array. (nelem, 3) with columns etax, etay and s

    Examples
    ---------
    >>> eta = measDispersion('p*c0[1-4]*')

    """

    eta = alphac - 1.0 / gamma / gamma

    bpmobj = [b for b in getElements(elem) if b.family == 'BPM']
    bpmnames = [b.name for b in bpmobj]
    nbpm = len(bpmnames)

    _logger.info("measure dispersions at %d elements '%s'" %
                 (len(bpmnames), str(elem)))

    f0 = getRfFrequency(handle="setpoint")
    dflst = np.linspace(-abs(dfmax), abs(dfmax), num_points)

    # incase RF does not allow large step change, ramp down first
    for df in np.linspace(0, abs(dfmax), num_points)[1:-1]:
        putRfFrequency(f0 - df)
        time.sleep(2.0 / num_points)

    # avoid a bug in virtac
    obt0 = getOrbit(bpmnames)

    cod = np.zeros((len(dflst), 2 * nbpm), 'd')
    for i, df in enumerate(dflst):
        v0 = getOrbit()
        putRfFrequency(f0 + df)
        if verbose > 0:
            print(i, "df=", df, " f=", f0)
        waitStableOrbit(v0)

        # repeat the put/get in case simulator did not response latest results
        obt = getOrbit(bpmnames)
        #print i, obt[0,:2], obt0[0,:2], np.shape(obt), np.shape(obt0)

        cod[i, :nbpm] = obt[:, 0] - obt0[:, 0]
        cod[i, nbpm:] = obt[:, 1] - obt0[:, 1]

    # restore
    for df in np.linspace(0, abs(dfmax), num_points):
        putRfFrequency(f0 + abs(dfmax) - df)
        time.sleep(2.0 / num_points)

    # fitting
    p = np.polyfit(dflst, cod, deg=1)
    disp = -p[0, :] * f0 * eta
    s = np.array([e.sb for e in bpmobj], 'd')
    ret = np.zeros((len(bpmobj), 3), 'd')
    ret[:, 0] = disp[:nbpm]
    ret[:, 1] = disp[nbpm:]
    ret[:, 2] = s
    if verbose > 0:
        for i, bpm in enumerate(bpmobj):
            print(i, bpm.name, bpm.sb, ret[i, 0], ret[i, 1])
    return ret