hyperion.grid.AMRGrid#
- class hyperion.grid.AMRGrid(amr_grid=None)#
An AMR grid.
Levels are stored in the
levels
attribute, which is a list ofhyperion.grid.amr_grid.Level
objects, which in turn contain agrids
attribute which is a list ofGrid
objects.Levels can be added with:
level = amr.add_level()
And grids can be added to a level with:
grid = level.add_grid()
Grid objects have the following attributes which should be set:
xmin
- lower x position of the gridxmax
- upper x position of the gridymin
- lower y position of the gridymax
- upper y position of the gridzmin
- lower z position of the gridzmax
- upper z position of the gridnx
- number of cells in x directionny
- number of cells in y directionnz
- number of cells in z directionquantities
- a dictionary containing physical quantities (see below)
AMRGrid
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 an
AMRGrid
object, but aAMRGridView
object. When setting this for the first time, this can be set either to anotherAMRGridView
object, an external h5py link, or an empty list. For example, the following should work:>>> grid['density_new'] = grid['density']
AMRGridView
objects allow the specific dust population to be selected as an index:>>> grid['density'][0]
Which is also an
AMRGridView
object.Methods
read
(group[, quantities])Read the geometry and physical quantities from an AMR grid
read_geometry
(group)Read in geometry information from an AMR grid
read_quantities
(group[, quantities])Read in physical quantities from an AMR grid
write
(group[, quantities, copy, ...])Write out the AMR grid
write_single_array
(group, name, amr_grid[, ...])Write out a single quantity, checking for consistency with geometry
add_derived_quantity
(name, function)to_yt
([dust_id])Convert AMR grid to a yt object (requires yt)
from_yt
(ds[, quantity_mapping])Convert a yt dataset to a Hyperion AMRGrid object
Methods (detail)
- read(group, quantities='all')#
Read the geometry and physical quantities from an AMR 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 an AMR grid
- Parameters:
- grouph5py.Group
The HDF5 group to read the geometry from
- read_quantities(group, quantities='all')#
Read in physical quantities from an AMR 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 AMR 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
- physics_dtypetype
The datatype to use to write the physical quantities
- write_single_array(group, name, amr_grid, 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
- amr_gridAMRGridView
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)#
- to_yt(dust_id=0)#
Convert AMR grid to a yt object (requires yt)
- Parameters:
- dust_idint, optional
The ID of the dust population to extract. If not set, this defaults to 0 (the first dust population).
- classmethod from_yt(ds, quantity_mapping={})#
Convert a yt dataset to a Hyperion AMRGrid object
Note
This method requires yt 3.0 or later
- Parameters:
- dsyt Dataset
The yt dataset
- quantity_mappingdict
A dictionary mapping the name of the quantity to use in Hyperion (the key) to the name of the field to extract in yt (the value).
Notes
The domain is always re-centered so that the position at ds.domain_center in yt becomes the origin in Hyperion.
Examples
Assuming that your dust opacities are defined per unit gas mass, and the simulation density is given in gas densities, converting is straightfoward (in this case we assume the density field is called
('gas', 'density')
):>>> from yt import load >>> from hyperion.grid import AMRGrid >>> ds = load('DD0010/moving7_0010') >>> amr = AMRGrid.from_yt(ds, quantity_mapping={'density':('gas', 'density')})
However, you will need to take care if your dust opacities are defined in dust mass units. If the yt dataset does not contain dust densities, you can add a field yourself, for example:
>>> from yt import load >>> from hyperion.grid import AMRGrid >>> ds = load('DD0010/moving7_0010') >>> def _dust_density(field, data): ... return data[('gas', 'density')].in_units('g/cm**3') * 0.01 >>> ds.add_field(('gas', 'dust_density'), function=_dust_density, units='g/cm**3', sampling_type='cell') >>> amr = AMRGrid.from_yt(ds, quantity_mapping={'density':('gas', 'dust_density')})
- class hyperion.grid.AMRGridView(amr_grid, quantity)#
Methods
append
(amr_grid_view)Used to append quantities from another grid
add
(amr_grid_view)Used to add quantities from another grid
Methods (detail)
- append(amr_grid_view)#
Used to append quantities from another grid
- Parameters:
- amr_gridAMRGridView instance
The grid to copy the quantity from
- add(amr_grid_view)#
Used to add quantities from another grid
- Parameters:
- amr_gridAMRGridView instance
The grid to copy the quantity from