hyperion.grid.VoronoiGrid#
- class hyperion.grid.VoronoiGrid(*args, **kwargs)#
A voronoi mesh.
The mesh can be initialized by passing the x, y, and z coordinates of the points used to compute the mesh:
>>> grid = Voronoi(x, y, z)
where
x
,y
, andz
are 1-d sequences of point positions.VoronoiGrid
objects may contain multiple quantities (e.g. density, specific energy). To access these, you can specify the name of the quantity as an item:>>> grid['density']
which is no longer a
VoronoiGrid
object, but aVoronoiGridView
object. When setting this for the first time, this can be set either to anotherVoronoiGridView
object, an external h5py link, or an empty list. For example, the following should work:>>> grid['density_new'] = grid['density']
VoronoiGridView
objects allow the specific dust population to be selected as an index:>>> grid['density'][0]
Which is also a
VoronoiGridView
object. The data can then be accessed with thearray
attribute:>>> grid['density'][0].array
which is a 1-d array of the requested quantity.
Methods
read
(group[, quantities])Read the geometry and physical quantities from an voronoi grid
read_geometry
(group)Read in geometry information from a cartesian grid
read_quantities
(group[, quantities])Read in physical quantities from a cartesian grid
write
(group[, quantities, copy, ...])Write out the voronoi grid
write_single_array
(group, name, array[, ...])Write out a single quantity, checking for consistency with geometry
add_derived_quantity
(name, function)evaluate_function_average
(func[, n_samples, ...])Evaluate the average of a function inside each cell using randomly sampled points inside each cell.
Methods (detail)
- read(group, quantities='all')#
Read the geometry and physical quantities from an voronoi grid
- Parameters:
- grouph5py.Group
The HDF5 group to read the grid from. This group should contain groups named ‘Geometry’ and ‘Quantities’.
- quantities‘all’ or list
Which physical quantities to read in. Use ‘all’ to read in all quantities or a list of strings to read only specific quantities.
- read_geometry(group)#
Read in geometry information from a cartesian grid
- Parameters:
- grouph5py.Group
The HDF5 group to read the grid geometry from.
- read_quantities(group, quantities='all')#
Read in physical quantities from a cartesian grid
- Parameters:
- grouph5py.Group
The HDF5 group to read the grid quantities from
- quantities‘all’ or list
Which physical quantities to read in. Use ‘all’ to read in all quantities or a list of strings to read only specific quantities.
- write(group, quantities='all', copy=True, absolute_paths=False, compression=True, wall_dtype=<class 'float'>, physics_dtype=<class 'float'>)#
Write out the voronoi grid
- Parameters:
- grouph5py.Group
The HDF5 group to write the grid to
- quantities‘all’ or list
Which physical quantities to write out. Use ‘all’ to write out all quantities or a list of strings to write only specific quantities.
- copybool
Whether to copy external links, or leave them as links.
- absolute_pathsbool
If copy is False, then this indicates whether to use absolute or relative paths for links.
- compressionbool
Whether to compress the arrays in the HDF5 file
- wall_dtypetype
The datatype to use to write the wall positions (ignored for this kind of grid)
- physics_dtypetype
The datatype to use to write the physical quantities
- write_single_array(group, name, array, copy=True, absolute_paths=False, compression=True, physics_dtype=<class 'float'>)#
Write out a single quantity, checking for consistency with geometry
- Parameters:
- grouph5py.Group
The HDF5 group to write the grid to
- namestr
The name of the array in the group
- arraynp.ndarray
The array to write out
- copybool
Whether to copy external links, or leave them as links.
- absolute_pathsbool
If copy is False, then this indicates whether to use absolute or relative paths for links.
- compressionbool
Whether to compress the arrays in the HDF5 file
- wall_dtypetype
The datatype to use to write the wall positions
- physics_dtypetype
The datatype to use to write the physical quantities
- add_derived_quantity(name, function)#
- evaluate_function_average(func, n_samples=None, min_cell_samples=None)#
Evaluate the average of a function inside each cell using randomly sampled points inside each cell.
Note
This feature is still experimental, use with caution
- Parameters:
- funcfunction
The function to evaluate in each cell. This should take three 1-d arrays of
x
,y
, andz
and return a 1-d array of values.- n_samplesint
The total number of points to sample within the domain. Points will be uniformly sampled in each Voronoi cell so that at least
n_samples
total points will be produced. Each cell will contain a number of samples proportional to its volume (but at leastmin_cell_samples
points will always be sampled in each cell).- min_cell_samplesint
The minimum number of samples per cell.
- class hyperion.grid.VoronoiGridView(grid, quantity)#
Methods
append
(grid)Used to append quantities from another grid
add
(grid)Used to add quantities from another grid
Methods (detail)
- append(grid)#
Used to append quantities from another grid
- Parameters:
- grid1D Numpy array or VoronoiGridView instance
The grid to copy the quantity from
- add(grid)#
Used to add quantities from another grid
- Parameters:
- grid1D Numpy array or VoronoiGridView instance
The grid to copy the quantity from