This module contains classes that allow importing and exporting of simple gridded data, A grid is an N-dimensional array that represents a discrete mesh over a region of space. The array axes are taken to be parallel to the cartesian axes of this space. Together with this array we also store the edges, which are are (essentially) the cartesian coordinates of the intersections of the grid (mesh) lines on the axes. In this way the grid is anchored in space.
The package reads grid data from files, makes them available as a
Grid object, and allows one to write out the data again.
Grid consists of a rectangular, regular, N-dimensional
array of data. It contains
- The position of the array cell edges.
- The array data itself.
This is equivalent to knowing
- The origin of the coordinate system (i.e. which data cell corresponds to (0,0,…,0)
- The spacing of the grid in each dimension.
- The data on a grid.
Grid objects have some convenient properties:
- The data is represented as a
Grid.gridand thus can be directly manipulated with all the tools available in NumPy.
Gridinstances can be manipulated arithmetically, e.g. one can simply add or subtract two of them and get another one, or multiply by a constant. Note that all operations are defined point-wise (see the
numpydocumentation for details) and that only grids defined on the same cell edges can be combined.
Gridobject can also be created from within python code e.g. from the output of the
- The representation of the data is abstracted from the format that the files are saved in. This makes it straightforward to add additional readers for new formats.
- The data can be written out again in formats that are understood by other programs such as VMD, ChimeraX or PyMOL.
Reading grid data files¶
Some Formats can be read directly from a file on disk:
g = Grid(filename)
filename could be, for instance, “density.dx”.
Constructing a Grid¶
g = Grid(ndarray, edges=edges) # from histogramdd g = Grid(ndarray, origin=origin, delta=delta) # from arbitrary data g.export(filename, format) # export to the desire format
See the doc string for
Grid for details.