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)
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))
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)
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)
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
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))
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)
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)
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)
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))
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)
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)
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)
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)
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')
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))