Ejemplo n.º 1
0
def test_linear_analysis(engine, ml_lattice, py_lattice, dp, refpts,
                         func_data):
    """N.B. a 'mu' comparison is left out for twiss data as the values for 'mu'
        returned by 'twissring' in Matlab are inconsistent with those from
        'get_twiss' and 'linopt' in Python as well as those returned from
        'atlinopt' in Matlab.
    """
    nelems = len(py_lattice)
    refpts = range(nelems + 1) if refpts is None else refpts

    # Python call
    if func_data[0] == 'twissring':
        py_data0, py_tune, py_chrom, py_data = physics.get_twiss(py_lattice,
                                                                 dp,
                                                                 refpts,
                                                                 True,
                                                                 ddp=1.E-6)
    else:
        py_data0, py_tune, py_chrom, py_data = physics.linopt(py_lattice,
                                                              dp,
                                                              refpts,
                                                              True,
                                                              ddp=1.E-6)
    # Matlab call
    ml_data, ml_tune, ml_chrom = engine.pyproxy(func_data[0],
                                                ml_lattice,
                                                dp,
                                                _ml_refs(refpts, nelems),
                                                nargout=3)
    ml_data0 = engine.pyproxy(func_data[0],
                              ml_lattice,
                              dp,
                              _ml_refs(nelems, nelems),
                              nargout=3)[0]
    # Comparison
    numpy.testing.assert_almost_equal(py_tune, _py_data(ml_tune), decimal=6)
    numpy.testing.assert_almost_equal(py_chrom, _py_data(ml_chrom), decimal=4)
    _compare_physdata(numpy.expand_dims(py_data0, 0),
                      ml_data0,
                      func_data[1],
                      decimal=5)
    _compare_physdata(py_data, ml_data, func_data[1], decimal=6)
Ejemplo n.º 2
0
def test_get_twiss(dba_lattice, refpts):
    twiss0, tune, chrom, twiss = physics.get_twiss(dba_lattice,
                                                   DP,
                                                   refpts,
                                                   get_chrom=True)
    numpy.testing.assert_allclose(twiss['s_pos'][-1], 56.209377216, atol=1e-9)
    numpy.testing.assert_allclose(twiss['closed_orbit'][0][:5],
                                  [1.0916359e-7, 0, 0, 0, DP],
                                  atol=1e-12)
    numpy.testing.assert_allclose(twiss['m44'][-1, :, :],
                                  M44_MATLAB,
                                  rtol=1e-5,
                                  atol=1e-7)
    numpy.testing.assert_almost_equal(twiss['beta'][-1, :], [2.9872, 6.6381],
                                      decimal=4)
    numpy.testing.assert_allclose(tune, [0.3655291, 0.4937126],
                                  rtol=1e-5,
                                  atol=1e-7)
    numpy.testing.assert_allclose(chrom, [-0.30903657, -0.4418593],
                                  rtol=1e-5,
                                  atol=1e-7)
Ejemplo n.º 3
0
def test_get_twiss(ring, refpts):
    twiss, tune, chrom = physics.get_twiss(ring, DP, refpts, get_chrom=True)
    numpy.testing.assert_allclose(twiss['s_pos'][-1], 56.209377216)
    numpy.testing.assert_allclose(twiss['closed_orbit'][0][:5],
                                  [1.0916359e-7, 0, 0, 0, DP],
                                  atol=1e-12)
    numpy.testing.assert_allclose(twiss['m44'][-1, :, :],
                                  M44_MATLAB,
                                  rtol=1e-5,
                                  atol=1e-7)
    numpy.testing.assert_almost_equal(twiss['beta'][-1, :], (2.9872, 6.6381),
                                      decimal=4)
    # Why is the tune different for these two cases?
    if refpts == [145]:
        # These are not especially accurate at present.
        numpy.testing.assert_allclose(tune, (-0.1344708, -0.00628742),
                                      rtol=1e-5,
                                      atol=1e-12)
        numpy.testing.assert_allclose(chrom, (-0.3090409, -0.44186077),
                                      rtol=1e-4)
    else:
        numpy.testing.assert_almost_equal(tune, (0.36553, 0.49371), decimal=5)
Ejemplo n.º 4
0
def test_get_twiss_no_refpts(dba_lattice):
    twiss0, tune, chrom, twiss = physics.get_twiss(dba_lattice,
                                                   DP,
                                                   get_chrom=True)
    assert list(twiss) == []
    assert len(physics.get_twiss(dba_lattice, DP, get_chrom=True)) is 4