def test11(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test11" + self.store_version() + ".hdf5") if os.path.exists(output_file): os.remove(output_file) number_of_particles = 10 p = Particles(number_of_particles) p.mass = [x * 2.0 for x in range(number_of_particles)] | units.kg p.model_time = 2.0 | units.s io.write_set_to_file(p.savepoint(timestamp=2 | units.Myr, scale=1 | units.kg), output_file, "hdf5", version=self.store_version()) loaded_particles = io.read_set_from_file(output_file, "hdf5", version=self.store_version()) loaded_particles = self.get_version_in_store(loaded_particles) a = loaded_particles.collection_attributes self.assertAlmostRelativeEquals(a.timestamp, 2 | units.Myr) self.assertAlmostRelativeEquals(a.scale, 1 | units.kg)
def test9(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test9"+self.store_version()+".hdf5") if os.path.exists(output_file): os.remove(output_file) number_of_particles = 10 p = Particles(number_of_particles) p.mass = [x * 2.0 for x in range(number_of_particles)] | units.kg p.model_time = 2.0 | units.s io.write_set_to_file( p, output_file, "hdf5", timestamp = 2 | units.Myr, scale = 1 | units.kg, version = self.store_version(), close_file = True ) loaded_particles = io.read_set_from_file( output_file, "hdf5", version = self.store_version() ) loaded_particles = self.get_version_in_store(loaded_particles) a = loaded_particles.collection_attributes self.assertAlmostRelativeEquals(a.timestamp, 2 | units.Myr) self.assertAlmostRelativeEquals(a.scale, 1 | units.kg)
def test7(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test7" + self.store_version() + ".hdf5") if os.path.exists(output_file): os.remove(output_file) instance = self.store_factory()(output_file) number_of_particles = 10 p = Particles(number_of_particles) p.mass = [x * 2.0 for x in range(number_of_particles)] | units.kg p.model_time = 2.0 | units.s instance.store(p) instance.close() instance = self.store_factory()(output_file) loaded_particles = self.get_version_in_store(instance.load()) loaded_particles.mass = [x * 3.0 for x in range(number_of_particles) ] | units.kg previous_mass_in_kg = [x * 3.0 for x in range(number_of_particles)] instance.close() instance = self.store_factory()(output_file) loaded_particles = instance.load() loaded_mass_in_kg = loaded_particles.mass.value_in(units.kg) for expected, actual in zip(previous_mass_in_kg, loaded_mass_in_kg): self.assertEqual(expected, actual) instance.close() instance = self.store_factory()(output_file) loaded_particles = self.get_version_in_store(instance.load()) loaded_particles[2].mass = 44 | units.kg instance.close() instance = self.store_factory()(output_file) loaded_particles = self.get_version_in_store(instance.load()) self.assertEqual(44 | units.kg, loaded_particles[2].mass) instance.close()
def test1(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test1."+self.store_version()+".hdf5") if os.path.exists(output_file): os.remove(output_file) instance = self.store_factory()(output_file) number_of_particles = 10 p = Particles(number_of_particles) p.mass = [x * 2.0 for x in range(number_of_particles)] | units.kg p.model_time = 2.0 | units.s instance.store(p) loaded_particles = instance.load() loaded_mass_in_kg = loaded_particles.mass.value_in(units.kg) previous_mass_in_kg = p.mass.value_in(units.kg) for expected, actual in zip(previous_mass_in_kg, loaded_mass_in_kg): self.assertEquals(expected, actual) instance.close()
def test56(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test26" + self.store_version() + ".hdf5") if os.path.exists(output_file): os.remove(output_file) number_of_particles = 10 p = Particles(number_of_particles) p.mass = [x * 2.0 for x in range(number_of_particles)] | units.kg p.model_time = 2.0 | units.s gas = Grid(2, 3) gas.y = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]] | units.km io.write_set_to_file(p, output_file, "hdf5", particle=p[1], particles=p, gridpoint=gas[0][0], grid=gas, version=self.store_version()) loaded_particles = io.read_set_from_file(output_file, "hdf5", version=self.store_version(), copy_history=False, close_file=False) attributes = loaded_particles.collection_attributes self.assertAlmostRelativeEquals(attributes.particle.mass, loaded_particles[1].mass) self.assertEquals(attributes.particle.key, loaded_particles[1].key) self.assertEquals(id(attributes.particles), id(loaded_particles)) self.assertAlmostRelativeEquals(attributes.gridpoint.y, 1.0 | units.km) self.assertAlmostRelativeEquals(attributes.grid[0][0].y, 1.0 | units.km)
def test56(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test26"+self.store_version()+".hdf5") if os.path.exists(output_file): os.remove(output_file) number_of_particles = 10 p = Particles(number_of_particles) p.mass = [x * 2.0 for x in range(number_of_particles)] | units.kg p.model_time = 2.0 | units.s gas = Grid(2,3) gas.y = [[1.0, 2.0, 3.0], [4.0,5.0,6.0]] | units.km io.write_set_to_file( p, output_file, "hdf5", particle = p[1], particles = p, gridpoint = gas[0][0], grid = gas, version = self.store_version() ) loaded_particles = io.read_set_from_file( output_file, "hdf5", version = self.store_version() ) attributes = loaded_particles.collection_attributes self.assertAlmostRelativeEquals(attributes.particle.mass, loaded_particles[1].mass) self.assertAlmostRelativeEquals(attributes.particle.key, loaded_particles[1].key) self.assertEquals(id(attributes.particles), id(loaded_particles)) self.assertAlmostRelativeEquals(attributes.gridpoint.y, 1.0 | units.km) self.assertAlmostRelativeEquals(attributes.grid[0][0].y, 1.0 | units.km)