# hyperion.grid.OctreeGrid¶

class `hyperion.grid.``OctreeGrid`(*args)

An octree grid.

To initialize an Octree object, use:

```>>> grid = OctreeGrid(x, y, z, dx, dy, dz, refined)
```

where `x`, `y`, and `z` are the cartesian coordinates of the center of the grid, `dx`, `dy`, and `dz` are the half-widths of the grid, and `refined` is a sequence of boolean values that indicate whether a given cell is refined.

The first value of the `refined` sequence indicates whether the parent cell is sub-divided. If it is, then the the second element indicates whether the first cell of the parent cell is sub-divided. If it isn’t, then the next value indicates whether the second cell of the parent cell is sub-divided. If it is, then we need to specify the booleans for all the children of that cell before we move to the third cell of the parent cell.

For example, the simplest grid is a single cell that is not sub-divided:

```refined = [False]
```

The next simplest grid is a single grid cell that is only sub-divided once:

```refined = [True, False, False, False, False, False, False, False, False]
```

It is easier to picture this as a hierarchy:

```refined = [True,
False,
False,
False,
False,
False,
False,
False,
False,
]
```

If we sub-divide the third sub-cell in the parent cell into cells that are themselves not sub-divided, we get:

```refined = [True,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
]
```

and so on. The order of the sub-cells is first along x, then along y, then along z.

`OctreeGrid` 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 `OctreeGrid` object, but a `OctreeGridView` object. When setting this for the first time, this can be set either to another `OctreeGridView` object, an external h5py link, or an empty list. For example, the following should work:

```>>> grid['density_new'] = grid['density']
```

`OctreeGridView` objects allow the specific dust population to be selected as an index:

```>>> grid['density']
```

Which is also an `OctreeGridView` object.

Methods

 `set_walls`(x, y, z, dx, dy, dz, refined) `read`(group[, quantities]) Read the geometry and physical quantities from an octree 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 octree grid `write_single_array`(group, name, array[, …]) 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)

Methods (detail)

`set_walls`(x, y, z, dx, dy, dz, refined)
`read`(group, quantities='all')

Read the geometry and physical quantities from an octree grid

Parameters: group : h5py.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: group : h5py.Group The HDF5 group to read the grid geometry from.
`read_quantities`(group, quantities='all')

Read in physical quantities from a cartesian grid

Parameters: group : h5py.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 octree grid

Parameters: group : h5py.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. copy : bool Whether to copy external links, or leave them as links. absolute_paths : bool If copy is False, then this indicates whether to use absolute or relative paths for links. compression : bool Whether to compress the arrays in the HDF5 file wall_dtype : type The datatype to use to write the wall positions (ignored for this kind of grid) physics_dtype : type 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: group : h5py.Group The HDF5 group to write the grid to name : str The name of the array in the group array : np.ndarray The array to write out copy : bool Whether to copy external links, or leave them as links. absolute_paths : bool If copy is False, then this indicates whether to use absolute or relative paths for links. compression : bool Whether to compress the arrays in the HDF5 file wall_dtype : type The datatype to use to write the wall positions physics_dtype : type 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_id : int, optional The ID of the dust population to extract. If not set, this defaults to 0 (the first dust population).
class `hyperion.grid.``OctreeGridView`(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: grid : 1D Numpy array or OctreeGridView instance The grid to copy the quantity from
`add`(grid)

Used to add quantities from another grid

Parameters: grid : 1D Numpy array or OctreeGridView instance The grid to copy the quantity from