示例#1
0
def test_monitor(rin):
    mon = elements.Monitor('monitor')
    assert mon.Length == 0
    rin = numpy.array(numpy.random.rand(*rin.shape), order='F')
    rin_orig = rin.copy()
    element_pass(mon, rin)
    numpy.testing.assert_equal(rin, rin_orig)
示例#2
0
def test_monitor(rin):
    mon = elements.Monitor('monitor')
    assert mon.Length == 0
    lattice = [mon]
    rin = numpy.array(numpy.random.rand(*rin.shape), order='F')
    rin_orig = numpy.array(rin, copy=True, order='F')
    atpass(lattice, rin, 1)
    numpy.testing.assert_equal(rin, rin_orig)
示例#3
0
def test_setitem(simple_lattice):
    new = elements.Monitor('M2')
    old = simple_lattice[5]
    simple_lattice[5] = new
    assert simple_lattice[5] != old
    assert simple_lattice[5] == new
    bool_refs = numpy.array([False, False, False, False, False, True])
    simple_lattice[bool_refs] = old
    assert simple_lattice[5] != new
    assert simple_lattice[5] == old
示例#4
0
def test_delitem(simple_lattice, simple_ring):
    mon = elements.Monitor('M2')
    simple_lattice.append(mon)
    assert len(simple_lattice) == 7
    del simple_lattice[-1]
    assert simple_lattice[:] == simple_ring
    bool_refs = numpy.array([False, False, False, False, False, False, True])
    simple_lattice.append(mon)
    assert len(simple_lattice) == 7
    del simple_lattice[bool_refs]
    assert simple_lattice[:] == simple_ring
示例#5
0
def test_insert_into_drift():
    # Create elements
    drift = elements.Drift('drift', 1)
    monitor = elements.Monitor('bpm')
    quad = elements.Quadrupole('quad', 0.3)
    # Test None splitting behaviour
    el_list = drift.insert([(0., None), (0.3, None), (0.7, None), (1., None)])
    assert len(el_list) == 3
    numpy.testing.assert_almost_equal([e.Length for e in el_list],
                                      [0.3, 0.4, 0.3])
    # Test normal insertion
    el_list = drift.insert([(0.3, monitor), (0.7, quad)])
    assert len(el_list) == 5
    numpy.testing.assert_almost_equal([e.Length for e in el_list],
                                      [0.3, 0.0, 0.25, 0.3, 0.15])
    # Test insertion at either end produces -ve length drifts
    el_list = drift.insert([(0.0, quad), (1.0, quad)])
    assert len(el_list) == 5
    numpy.testing.assert_almost_equal([e.Length for e in el_list],
                                      [-0.15, 0.3, 0.7, 0.3, -0.15])