Beispiel #1
0
 def test4(self):
     directory_name = os.path.dirname(__file__)
     filename = os.path.join(directory_name, 'gassphere_littleendian.dat')
     x = gadget.GadgetFileFormatProcessor()
     result = io.read_set_from_file(filename, format='gadget')
     self.assertEqual(len(result[0]), 1472)
     self.assertEqual(len(result[1]), 0)
Beispiel #2
0
 def test3(self):
     directory_name = os.path.dirname(__file__)
     filename = os.path.join(directory_name, 'gadget_snapshot')
     x = gadget.GadgetFileFormatProcessor()
     result = io.read_set_from_file(filename, format='gadget')
     self.assertEqual(len(result[0]), 1000)
     self.assertEqual(len(result[1]), 10000)
Beispiel #3
0
 def test10(self):
     p = Particles(2)
     p[0].position = [1.0, 2.0, 3.0] | nbody_system.length
     p[1].position = [4.0, 5.0, 6.0] | nbody_system.length
     p[0].velocity = [7.0, 8.0, 10.0] | nbody_system.length / nbody_system.time
     p[1].velocity = [11.0, 12.0, 13.0] | nbody_system.length / nbody_system.time
     p.u = [3,4] | nbody_system.potential
     p.rho = [5,6] | nbody_system.density
     p.mass = [5,6] | nbody_system.mass
     x = gadget.GadgetFileFormatProcessor(set = p)
     file = BytesIO()
     x.store_body(file)
     input = BytesIO(file.getvalue())
     positions = x.read_fortran_block_float_vectors(input)
     self.assertEqual(positions[0] , [1.0, 2.0, 3.0])
     self.assertEqual(positions[1] , [4.0, 5.0, 6.0])
     velocities = x.read_fortran_block_float_vectors(input)
     self.assertEqual(velocities[0] , [7.0, 8.0, 10.0])
     self.assertEqual(velocities[1] , [11.0, 12.0, 13.0])
     ids = x.read_fortran_block_ulongs(input)
     self.assertEqual(ids[0], p[0].key)
     self.assertEqual(ids[1], p[1].key)
     masses = x.read_fortran_block_floats(input)
     self.assertEqual(masses[0], 5)
     self.assertEqual(masses[1], 6)
     u = x.read_fortran_block_floats(input)
     self.assertEqual(u[0], 3)
     self.assertEqual(u[1], 4)
Beispiel #4
0
    def test9(self):
        class FakeList(object):
            def __init__(self, _len):
                self._len = _len

            def __len__(self):
                return self._len

        set = (FakeList(20000), FakeList(500000), FakeList(20000), (), (), ())
        x = gadget.GadgetFileFormatProcessor(set=set)
        x.equal_mass_array = (0.0, 4.291150104743886e-07, 2.5e-07, 0.0, 0.0,
                              0.0) | nbody_system.mass
        file = BytesIO()
        x.store_header(file)
        print x.header_struct
        self.assertEquals(x.header_struct.Npart[0], 20000)
        self.assertEquals(x.header_struct.Npart[1], 500000)
        self.assertEquals(x.header_struct.Npart[2], 20000)
        self.assertEquals(x.header_struct.Npart[3], 0)
        self.assertEquals(x.header_struct.Npart[4], 0)
        self.assertEquals(x.header_struct.Npart[5], 0)

        print repr(file.getvalue())
        print repr(b''.join(self.header_parts))
        self.assertEquals(repr(file.getvalue()[0:30]),
                          repr(b''.join(self.header_parts)[0:30]))
Beispiel #5
0
 def test2(self):
     directory_name = os.path.dirname(__file__)
     filename = os.path.join(directory_name, 'gadget_snapshot')
     x = gadget.GadgetFileFormatProcessor()
     file = open(filename,'rb')
     result = x.load_file(file)
     file.close()
     self.assertEqual(len(result[0]), 1000)
     self.assertEqual(len(result[1]), 10000)
Beispiel #6
0
 def test6(self):
     directory_name = os.path.dirname(__file__)
     filename = os.path.join(directory_name, 'gassphere_littleendian.dat')
     x = gadget.GadgetFileFormatProcessor()
     gas, halo, disk, bulge, stars, bndry =  io.read_set_from_file(filename, format='gadget')
     self.assertEqual(len(gas), 1472)
     self.assertEqual(len(halo), 0)
     self.assertEqual(gas[0].key,1)
     self.assertEqual(gas[1].key,2)
     self.assertEqual(gas[2].key,3)
     self.assertEqual(gas[1471].key,1472)
Beispiel #7
0
 def test1(self):
     header = b''.join(self.header_parts)
     x = gadget.GadgetFileFormatProcessor()
     file = BytesIO(header)
     x.load_header(file)
     print(x.header_struct)
     self.assertEqual(x.header_struct.Npart[0], 20000)
     self.assertEqual(x.header_struct.Npart[1], 500000)
     self.assertEqual(x.header_struct.Npart[2], 20000)
     self.assertEqual(x.header_struct.Npart[3], 0)
     self.assertEqual(x.header_struct.Npart[4], 0)
     self.assertEqual(x.header_struct.Npart[5], 0)
     
     self.assertEqual(x.header_struct.Massarr[0], 0.0)
     self.assertAlmostRelativeEqual(x.header_struct.Massarr[1], 4.2911501e-07, 8)
     print(x.header_struct.Massarr[2])
     self.assertAlmostRelativeEqual(x.header_struct.Massarr[2], 2.5000000e-07, 8)
     
     self.assertEqual(x.header_struct.FlagSfr, 0)
     self.assertEqual(x.header_struct.FlagFeedback, 0)
     self.assertEqual(x.header_struct.FlagAge, 0)
     self.assertEqual(x.header_struct.HubbleParam, 0)