Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init_arrays(self):
"""Testing initialising Arrays object."""
file_handle = h5py.File(TEST_FILE, mode='r')
arrays = plonk.core.particles.Arrays(
file_handle=file_handle, arrays_label='particles'
)
self.assertEqual(arrays.dimensions, dimensions)
self.assertEqual(arrays.dtype, dtype)
self.assertEqual(arrays.number, number)
self.assertEqual(arrays.fields, fields)
self.assertEqual(arrays.shape, shape)
file_handle.close()
def test_extra_quantities(self):
"""Testing calculating extra quantities."""
file_handle = h5py.File(TEST_FILE, mode='r')
arrays = plonk.core.particles.Arrays(
file_handle=file_handle, arrays_label='particles'
)
for quantity in {'L', 'R', 'l', 'p', 'r', '|L|', '|l|', '|p|', '|v|'}:
self.assertEqual(
arrays.extra_quantity(quantity, mass=np.array([1.0]))[0].mean(),
extra_quantities[quantity],
)
file_handle.close()
def test_to_structured_array(self):
"""Testing Arrays object to numpy structured array."""
file_handle = h5py.File(TEST_FILE, mode='r')
arrays = plonk.core.particles.Arrays(
file_handle=file_handle, arrays_label='particles'
)
self.assertEqual(arrays.to_structured_array().dtype, structured_array_dtype)
file_handle.close()
if cache_arrays is None:
self._cache_arrays = False
else:
if not isinstance(cache_arrays, bool):
raise TypeError('cache_array must be bool')
self._cache_arrays = cache_arrays
self.particles = Arrays(
arrays_label='particles',
file_handle=self.file_handle,
particle_type='fluid',
cache_arrays=cache_arrays,
)
self.sinks = Arrays(arrays_label='sinks', file_handle=self.file_handle)
def __init__(self, filename, cache_arrays=None):
super().__init__(filename)
self._header = {key: val[()] for key, val in self.file_handle['header'].items()}
if cache_arrays is None:
self._cache_arrays = False
else:
if not isinstance(cache_arrays, bool):
raise TypeError('cache_array must be bool')
self._cache_arrays = cache_arrays
self.particles = Arrays(
arrays_label='particles',
file_handle=self.file_handle,
particle_type='fluid',
cache_arrays=cache_arrays,
)
self.sinks = Arrays(arrays_label='sinks', file_handle=self.file_handle)