hyperion.grid.AMRGrid

class hyperion.grid.AMRGrid(amr_grid=None)

An AMR grid.

Levels are stored in the levels attribute, which is a list of hyperion.grid.amr_grid.Level objects, which in turn contain a grids attribute which is a list of Grid 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 grid

  • xmax - upper x position of the grid

  • ymin - lower y position of the grid

  • ymax - upper y position of the grid

  • zmin - lower z position of the grid

  • zmax - upper z position of the grid

  • nx - number of cells in x direction

  • ny - number of cells in y direction

  • nz - number of cells in z direction

  • quantities - 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 a AMRGridView object. When setting this for the first time, this can be set either to another AMRGridView 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(self, group[, quantities])

Read the geometry and physical quantities from an AMR grid

read_geometry(self, group)

Read in geometry information from an AMR grid

read_quantities(self, group[, quantities])

Read in physical quantities from an AMR grid

write(self, group[, quantities, copy, …])

Write out the AMR grid

write_single_array(self, group, name, amr_grid)

Write out a single quantity, checking for consistency with geometry

add_derived_quantity(self, name, function)

to_yt(self[, 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(self, 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(self, group)

Read in geometry information from an AMR grid

Parameters
grouph5py.Group

The HDF5 group to read the geometry from

read_quantities(self, 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(self, 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(self, 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(self, name, function)
to_yt(self, 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')

>>> amr = AMRGrid.from_yt(ds, quantity_mapping={'density':('gas', 'dust_density')})
class hyperion.grid.AMRGridView(amr_grid, quantity)

Methods

append(self, amr_grid_view)

Used to append quantities from another grid

add(self, amr_grid_view)

Used to add quantities from another grid

Methods (detail)

append(self, amr_grid_view)

Used to append quantities from another grid

Parameters
amr_gridAMRGridView instance

The grid to copy the quantity from

add(self, amr_grid_view)

Used to add quantities from another grid

Parameters
amr_gridAMRGridView instance

The grid to copy the quantity from