Ejemplo n.º 1
0
    def test_returns_empty_when_dims_is_point(self):
        x = np.linspace(0, 1, 11)
        y = np.linspace(0, 1, 11)
        points = detector_points(x=x, y=y)

        msg = "Cannot get extent for detector_points"
        self.assertRaisesRegex(ValueError, msg, get_extents, points)
Ejemplo n.º 2
0
    def test_z_defaults_to_zero_when_xy_passed(self):
        np.random.seed(70)
        npts = 21
        x = np.random.randn(npts)
        y = np.random.randn(npts)
        points = detector_points(x=x, y=y)

        self.assertTrue(np.all(points.z == 0))
Ejemplo n.º 3
0
    def test_r_defaults_to_inf_when_thetaphi_passed(self):
        np.random.seed(70)
        npts = 21
        theta = np.random.randn(npts) % np.pi
        phi = np.random.randn(npts) % (2 * np.pi)

        points = detector_points(theta=theta, phi=phi)

        self.assertTrue(np.all(np.isinf(points.r)))
        self.assertEqual(points.r.size, npts)
Ejemplo n.º 4
0
    def test_stores_xyz_as_correct_shape_when_xyz_passed(self):
        np.random.seed(70)
        npts = 21
        x = np.random.randn(npts)
        y = np.random.randn(npts)
        z = np.random.randn(npts)

        points = detector_points(x=x, y=y, z=z)
        self.assertEqual(points.x.size, npts)
        self.assertEqual(points.y.size, npts)
        self.assertEqual(points.z.size, npts)
Ejemplo n.º 5
0
def make_points(seed=1):
    np.random.seed(seed)
    npts = 21
    x = np.random.randn(npts)
    y = np.random.randn(npts)
    z = np.random.randn(npts)

    points = detector_points(x=x, y=y, z=z)
    data_values = np.random.randn(npts)
    points.values[:] = data_values
    return points
Ejemplo n.º 6
0
    def test_stores_rthetaphi_correct_values_when_rthetaphi_passed(self):
        np.random.seed(70)
        npts = 21
        r = np.random.randn(npts)
        theta = np.random.randn(npts) % np.pi
        phi = np.random.randn(npts) % (2 * np.pi)

        points = detector_points(r=r, theta=theta, phi=phi)
        self.assertTrue(np.all(points.r == r))
        self.assertTrue(np.all(points.theta == theta))
        self.assertTrue(np.all(points.phi == phi))
Ejemplo n.º 7
0
    def test_stores_rthetaphi_as_correct_shape_when_rthetaphi_passed(self):
        np.random.seed(70)
        npts = 21
        r = np.random.randn(npts)
        theta = np.random.randn(npts) % np.pi
        phi = np.random.randn(npts) % (2 * np.pi)

        points = detector_points(r=r, theta=theta, phi=phi)
        self.assertEqual(points.r.size, npts)
        self.assertEqual(points.theta.size, npts)
        self.assertEqual(points.phi.size, npts)
Ejemplo n.º 8
0
    def test_stores_r_as_array_when_scalar_r_passed(self):
        np.random.seed(70)
        npts = 21
        theta = np.random.randn(npts) % np.pi
        phi = np.random.randn(npts) % (2 * np.pi)
        # Then we pick a scalar r:
        r = np.random.randn(1).squeeze()

        points = detector_points(r=r, theta=theta, phi=phi)

        self.assertTrue(np.all(points.r == r))
        self.assertEqual(points.r.size, npts)
Ejemplo n.º 9
0
    def test_stores_z_as_array_when_scalar_z_passed(self):
        np.random.seed(70)
        npts = 21
        x = np.random.randn(npts)
        y = np.random.randn(npts)
        # Then we pick a scalar z:
        z = np.random.randn(1).squeeze()

        points = detector_points(x=x, y=y, z=z)

        self.assertTrue(np.all(points.z == z))
        self.assertEqual(points.z.size, npts)
Ejemplo n.º 10
0
    def test_stores_xyz_correct_values_when_xyz_passed(self):
        np.random.seed(70)
        npts = 21
        x = np.random.randn(npts)
        y = np.random.randn(npts)
        z = np.random.randn(npts)

        points = detector_points(x=x, y=y, z=z)

        self.assertTrue(np.all(points.x == x))
        self.assertTrue(np.all(points.y == y))
        self.assertTrue(np.all(points.z == z))
Ejemplo n.º 11
0
def test_farfield():
    schema = detector_points(theta=np.linspace(0, np.pi / 2), phi=np.zeros(50))
    n = 1.59 + 0.01j
    r = 0.5

    cluster = Spheres([
        Sphere(n=n, r=r, center=[0., 0., r]),
        Sphere(n=n, r=r, center=[0., 0., -r])
    ])

    matr = calc_scat_matrix(schema,
                            cluster,
                            illum_wavelen=.66,
                            medium_index=index,
                            theory=Multisphere)
Ejemplo n.º 12
0
def test_farfield_matr():
    schema = detector_points(theta = np.linspace(0, np.pi/2), phi = np.linspace(0, 1))
    sphere = Sphere(r = .5, n = 1.59+0.1j)

    matr = calc_scat_matrix(schema, sphere, index, .66)
    verify(matr, 'farfield_matricies', rtol = 1e-6)
Ejemplo n.º 13
0
    def test_raises_error_when_yspacing_is_unequal(self):
        x = np.linspace(0, 1, 11)
        y = np.linspace(0, 1, 11)**2  # non-uniform spacing

        detector = detector_points(x=x, y=y)
        self.assertRaises(ValueError, get_spacing, detector)
Ejemplo n.º 14
0
 def test_name_is_stored(self):
     x, y, z = np.random.randn(3, 10)
     name = 'this-is-a-test'
     points = detector_points(x=x, y=y, z=z, name=name)
     self.assertEqual(points.name, name)
Ejemplo n.º 15
0
 def test_name_defaults_to_data(self):
     x, y, z = np.random.randn(3, 10)
     points = detector_points(x=x, y=y, z=z)
     self.assertEqual(points.name, 'data')
Ejemplo n.º 16
0
 def test_data_is_stored_as_zeros_of_corect_size(self):
     npts = 23
     x, y, z = np.random.randn(3, npts)
     points = detector_points(x=x, y=y, z=z)
     self.assertEqual(points.size, npts)
     self.assertTrue(np.all(points.values == 0))