def test_random_cube(self):
     numpy.random.seed(1232367)
     gen = stellar_wind.PositionGenerator('random')
     cube = gen.cube_generator(1000)
     self.assertEqual(cube.shape, (1000, 3))
     self.assertAlmostEqual(cube.min(), -0.99970440813)
     self.assertAlmostEqual(cube.max(), 0.997978975085)
    def test_regular_hollow_sphere(self):
        numpy.random.seed(1232367)
        gen = stellar_wind.PositionGenerator(grid_type="regular")
        points = gen.uniform_hollow_sphere(2, 0.6)
        self.assertEqual(len(points), 2)

        points = gen.uniform_hollow_sphere(1000, 0.1)
        self.assertEqual(len(points), 1000)
 def test_regular_cube(self):
     numpy.random.seed(1232367)
     gen = stellar_wind.PositionGenerator(grid_type="regular")
     cube = gen.cube_generator(25)
     print cube
     self.assertEqual(cube.shape, (25, 3))
     self.assertAlmostEqual(cube.min(), -2. / 3.)
     self.assertAlmostEqual(cube.max(), 2. / 3.)
 def test_rotate_positions(self):
     gen = stellar_wind.PositionGenerator()
     axis = [0, 1, 0]
     angle = numpy.pi
     positions = [[0.5, 0.5, 0.5], [0.2, -0.5, 1.3]]
     rotated = gen.rotate_positions(positions, axis, angle)
     print rotated
     expected = [[-0.5, 0.5, -0.5], [-0.2, -0.5, -1.3]]
     self.assertAlmostEqual(rotated, expected)
    def test_rotation_matrix(self):
        gen = stellar_wind.PositionGenerator()
        axis = [0, 0, 1]
        angle = numpy.pi
        matrix = gen.rotation_matrix(axis, angle)
        print numpy.rint(matrix)

        expected = [[-1, 0, 0], [0, -1, 0], [0, 0, 1]]
        self.assertAlmostEqual(matrix, expected)
 def test_random_rotation(self):
     numpy.random.seed(1232367)
     gen = stellar_wind.PositionGenerator()
     axis, angle = gen.random_rotation()
     print axis
     print angle
     self.assertEqual(len(axis), 3)
     self.assertAlmostEqual((axis**2).sum(), 1.)
     self.assertGreaterEqual(angle, 0.)
     self.assertLessEqual(angle, 2. * numpy.pi)
    def test_cutout_sphere(self):
        points = [
            [0., 0., 0.],
            [1., 1., 1.],
            [-1., -1., -1.],
            [-0., 0., -.99],
            [0., .5, 0.],
        ]
        points = numpy.array(points)

        gen = stellar_wind.PositionGenerator()
        remaining = gen.cutout_sphere(points, 0.1)

        self.assertEqual(len(remaining), 2)
        self.assertEqual(remaining, points[-2:])
    def test_density_distribution(self):
        numpy.random.seed(1234567)
        N = 100000
        rmin = 1 | units.RSun
        rmax = 10 | units.RSun
        gen = stellar_wind.PositionGenerator()
        p, _ = gen.generate_positions(N, rmin, rmax)
        r = p.lengths()

        print 'rmin', r.min()
        print 'rmax', r.max()
        print r.mean()
        self.assertEquals(len(r), N)
        self.assertGreaterEqual(r.min(), rmin)
        self.assertLessEqual(r.max(), rmax)
        self.assertAlmostEquals(r.mean(), 5.49955427602 | units.RSun)

        return

        r = r.value_in(units.RSun)
        n_bins = 50
        n, bins = numpy.histogram(r, n_bins, range=(1, 10))
        bin_volume = 4. / 3. * numpy.pi * (bins[1:]**3 - bins[:-1]**3)
        dens = n / bin_volume
        bin_means = (bins[1:] + bins[:-1]) / 2.

        s = p[abs(p[:, 2]) < (0.1 | units.RSun)]
        from matplotlib import pyplot
        from amuse import plot as aplot
        aplot.plot(s[:, 0], s[:, 1], '.')
        pyplot.axis('equal')
        pyplot.savefig("scatter.pdf")
        pyplot.clf()

        x = numpy.linspace(1, 10, num=200)
        y = 300. / x**2
        # y = 0. * x + dens.mean()

        from matplotlib import pyplot
        # pyplot.plot(x, y)
        pyplot.loglog(x, y)
        pyplot.plot(bin_means, dens, '*')
        pyplot.savefig("dens.pdf")
    def test_alternate_radius_function(self):
        numpy.random.seed(123)
        gen = stellar_wind.PositionGenerator()
        # func = stellar_wind.LogisticVelocityAcceleration().radius_from_number
        func = stellar_wind.ConstantVelocityAcceleration().radius_from_number

        N = 100000
        rmin = 2 | units.RSun
        rmax = 6 | units.RSun
        star = Particle()
        star.radius = rmin
        star.acc_cutoff = 10 | units.RSun
        star.initial_wind_velocity = 4 | units.kms
        star.terminal_wind_velocity = 12 | units.kms

        p, _ = gen.generate_positions(N, rmin, rmax, func, star)
        r = p.lengths()

        self.assertEquals(len(r), N)
        self.assertGreaterEqual(r.min(), rmin)
        self.assertLessEqual(r.max(), rmax)
        print r.mean()
        self.assertAlmostEquals(r.mean(), 4.00196447056 | units.RSun)

        return

        r = r.value_in(units.RSun)
        n_bins = 50
        n, bins = numpy.histogram(r, n_bins)
        bin_volume = 4. / 3. * numpy.pi * (bins[1:]**3 - bins[:-1]**3)
        dens = n / bin_volume
        bin_means = (bins[1:] + bins[:-1]) / 2.

        from matplotlib import pyplot
        pyplot.plot(bin_means, dens, '*')
        pyplot.savefig("dens.pdf")