示例#1
0
 def test_get_all_parameters_with_get_coordinates_of(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     received_x_and_y = particles.get_default_coordinates_of("x", "y")
     assert np.allclose(received_x_and_y, array)
示例#2
0
 def test_get_matrix(self):
     k = np.array([1, 2, 1]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     array1 = particles.get_matrix()
     array1[0][0] = -1
     assert np.allclose(array1, particles.particles)
示例#3
0
 def test_filter_equals(self):
     k = np.array([1, 2, 1]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     particles_with_x_eq_1 = particles.filter_equals("x", 1)
     assert np.allclose(particles_with_x_eq_1.particles,
                        np.array([[1, 2], [1, 4]]))
示例#4
0
 def test_get_values_of(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     m = np.array([3, 4, 5]).reshape((-1, 1))
     n = np.array([4, 5, 6]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     self.assertTrue(np.allclose(particles.get_column("x"), k))
示例#5
0
 def test_get_values_of_should_return_copy_of_vector(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     cp = particles.get_column("x")
     cp[0][0] = 100
     self.assertFalse(np.allclose(particles.get_column("x"), cp))
示例#6
0
 def test_add_column(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     m = np.array([3, 4, 5]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     particles_with_m = particles.add_column("m", m)
     self.assertTrue(np.allclose(particles_with_m.get_column("m"), m))
示例#7
0
 def test_shift_parameter(self):
     k = np.array([1, 2, 1]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     l_shifted = l + 1
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     particles_with_shifted_y = particles.shift_parameter("y", 1)
     assert np.allclose(particles_with_shifted_y.get_column("y"), l_shifted)
示例#8
0
 def test_get_mapping(self):
     k = np.array([1, 2, 1]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     mapping1 = particles.get_mapping()
     mapping1["t"] = 1
     assert mapping1 == particles.mapping
示例#9
0
 def test_get_all_parameters_in_different_order_with_get_coordinates_of(
         self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     received_y_and_x = particles.get_default_coordinates_of("y", "x")
     l_and_k = np.append(l, k, axis=1)
     assert np.allclose(received_y_and_x, l_and_k)
示例#10
0
 def test_constructor_should_copy_particles(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     array[0][0] = 100
     self.assertFalse(
         np.allclose(particles.get_column("x"), array.T[0].reshape(
             (-1, 1))))
示例#11
0
 def test_add_zeros_column(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     m = np.array([0, 0, 0]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     particles_with_zeros_column = particles.add_zeros_column("z")
     array_with_zeros_column = np.append(array, m, axis=1)
     assert np.allclose(particles_with_zeros_column.particles,
                        array_with_zeros_column)
示例#12
0
def transport(particles, wanted_xa, configuration_madx_xa1, xa1,
              configuration_madx_xa2, xa2):
    segments_xa_1 = ptg.transport(configuration_madx_xa1, particles)
    segments_xa_2 = ptg.transport(configuration_madx_xa2, particles)

    new_places = {}
    for place in segments_xa_1.keys():
        # (X1 - X2) / (XA1 - XA2) * XA + X2
        # todo refactor, it break isolation of Particles object
        particles_xa_1 = segments_xa_1[place].get_matrix()
        particles_xa_2 = segments_xa_2[place].get_matrix()
        ax = (particles_xa_1 - particles_xa_2) / (xa1 - xa2) * (wanted_xa -
                                                                xa2)
        b = particles_xa_2
        particles_with_xa = ax + b
        new_places[place] = Particles(particles_with_xa,
                                      segments_xa_1[place].get_mapping())

    return new_places
示例#13
0
 def test_get_number_of_particles(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     self.assertTrue(particles.get_number_of_particles() == 3)
示例#14
0
 def test_constructor(self):
     k = np.array([1, 2, 3]).reshape((-1, 1))
     l = np.array([2, 3, 4]).reshape((-1, 1))
     array = np.append(k, l, axis=1)
     particles = Particles(array, {"x": 0, "y": 1})
     Particles(particles.particles, particles.mapping)