Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

GridDataFormats provides the Python package 'gridData'. It contains a class ('Grid') to handle data on a regular grid --- basically NumPy n-dimensional arrays. It supports reading from and writing to some common formats (such as OpenDX). A version of the package is hosted on PyPi so that it should be possible to simply install with 'easy_install…

branch: master

fix release 0.2.4: include missing SUMMARY.txt in distribution

Apparently, 0.2.3 pip install was broken (see http://code.google.com/p/mdanalysis/issues/detail?id=168)
due to missing SUMMARY.txt.

The file is now included (via MANIFEST.in) together with README.rst.

The version number was increased to make automatic updates cleaner.

The only functional change in this release is the addition of the
top-level gridData.__version__ atttribute.
latest commit 27f66f774f
Oliver Beckstein authored March 03, 2014
Octocat-spinner-32 gridData fix release 0.2.4: include missing SUMMARY.txt in distribution March 03, 2014
Octocat-spinner-32 .gitignore renamed for testing and added stuff to install September 07, 2010
Octocat-spinner-32 AUTHORS renamed for testing and added stuff to install September 07, 2010
Octocat-spinner-32 COPYING copied gridDataFormats from hop, including setup.py etc September 07, 2010
Octocat-spinner-32 COPYING.LESSER copied gridDataFormats from hop, including setup.py etc September 07, 2010
Octocat-spinner-32 INSTALL removed scipy from install requirements February 09, 2014
Octocat-spinner-32 MANIFEST.in fix release 0.2.4: include missing SUMMARY.txt in distribution March 03, 2014
Octocat-spinner-32 README.rst added sphinx def of Grid class to README.rst July 03, 2013
Octocat-spinner-32 SUMMARY.txt minor meta doc fixes> July 03, 2013
Octocat-spinner-32 ez_setup.py copied gridDataFormats from hop, including setup.py etc September 07, 2010
Octocat-spinner-32 setup.py fix release 0.2.4: include missing SUMMARY.txt in distribution March 03, 2014
README.rst

README for gridDataFormats

The package reads grid data from files, makes them available as a :class:`Grid` object, and allows one to write out the data again.

System Message: ERROR/3 (<string>, line 5); backlink

Unknown interpreted text role "class".

A :class:`Grid` consists of a rectangular, regular, N-dimensional array of data. It contains (1) The position of the array cell edges. (2) The array data itself.

System Message: ERROR/3 (<string>, line 8); backlink

Unknown interpreted text role "class".

This is equivalent to knowing (1) The origin of the coordinate system (i.e. which data cell

System Message: ERROR/3 (<string>, line 15)

Unexpected indentation.
corresponds to (0,0,...,0)
  1. The spacing of the grid in each dimension.
  2. The data on a grid.

:class:`Grid` objects have some convenient properties:

System Message: ERROR/3 (<string>, line 19); backlink

Unknown interpreted text role "class".
  • The data is represented as a :class:`numpy.array` and thus shares all the advantages coming with this sophisticated and powerful library.

    System Message: ERROR/3 (<string>, line 21); backlink

    Unknown interpreted text role "class".

  • They 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 :mod:`numpy` documentation for details) and that only grids defined on the same cell edges can be combined.

    System Message: ERROR/3 (<string>, line 25); backlink

    Unknown interpreted text role "mod".

  • A :class:`Grid` object can also be created from within python code e.g. from the output of the :func:`numpy.histogramdd` function.

    System Message: ERROR/3 (<string>, line 31); backlink

    Unknown interpreted text role "class".

    System Message: ERROR/3 (<string>, line 31); backlink

    Unknown interpreted text role "func".

  • 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 or PyMOL.

Examples

In most cases, only one class is important, the :class:`gridData.Grid`, so we just load this right away:

System Message: ERROR/3 (<string>, line 45); backlink

Unknown interpreted text role "class".
from gridData import Grid

Loading data

From a OpenDX file:

g = Grid("density.dx")

From a gOpenMol PLT file:

g = Grid("density.plt")

From the output of :func:`numpy.histogramdd`:

System Message: ERROR/3 (<string>, line 62); backlink

Unknown interpreted text role "func".
import numpy
r = numpy.random.randn(100,3)
H, edges = numpy.histogramdd(r, bins = (5, 8, 4))
g = Grid(H, edges=edges)

For other ways to load data, see the docs for :class:`gridData.Grid`.

System Message: ERROR/3 (<string>, line 69); backlink

Unknown interpreted text role "class".

Subtracting two densities

Assuming one has two densities that were generated on the same grid positions, stored in files A.dx and B.dx, one first reads the data into two :class:`Grid` objects:

System Message: ERROR/3 (<string>, line 76); backlink

Unknown interpreted text role "class".
A = Grid('A.dx')
B = Grid('B.dx')

Subtract A from B:

C = B - A

and write out as a dx file:

C.export('C.dx')

The resulting file C.dx can be visualized with any OpenDX-capable viewer, or later read-in again.

Resampling

Load data:

A = Grid('A.dx')

Interpolate with a cubic spline to twice the sample density:

A2 = A.resample_factor(2)

Downsample to half of the bins in each dimension:

Ahalf = A.resample_factor(0.5)

Resample to the grid of another density, B:

B = Grid('B.dx')
A_on_B = A.resample(B.edges)

or even simpler

A_on_B = A.resample(B)

Note

The cubic spline generates region with values that did not occur in the original data; in particular if the original data's lowest value was 0 then the spline interpolation will probably produce some values <0 near regions where the density changed abruptly.

Classes

Class to manage a multidimensional grid object.

A grid is a n-dimensional array and data indicating the dimensions of the edges, i.e. the positions of all grid cells in cartesian coordinates.

:class:`Grid` objects can be multiplied by scalars in order to scale the values (but not the dimensions) and like :class:`Grid` objects (i.e. corresponding grid points are located at the same coordinates) can be used in basic arithmetic operations (addition, subtraction, multiplication, division, exponentiation). Basic arithmetic is left and right associative, i.e. Grid1 + Grid2 == Grid2 + Grid1 and also 3 * Grid and Grid/0.5 work.

System Message: ERROR/3 (<string>, line 137); backlink

Unknown interpreted text role "class".

System Message: ERROR/3 (<string>, line 137); backlink

Unknown interpreted text role "class".

System Message: ERROR/3 (<string>, line 145)

Unknown directive type "method".

.. method:: load(filename)

   Load saved (pickled or dx) grid and edges from *filename*.

System Message: ERROR/3 (<string>, line 149)

Unknown directive type "method".

.. method:: export(filename[, format])

   Export to file using the given *format*.

   The format can also be deduced from the suffix of the filename
   though the *format* keyword takes precedence.

   The default format 'dx'.

   Implemented formats:

    ========== =================================================
    suffix     description
    ========== =================================================
     dx        OpenDX

     pickle    Python pickle (use :meth:`load` to restore);
               :meth:`save` is a short cut for
               ``export(format='python')``
    ========== =================================================

System Message: ERROR/3 (<string>, line 170)

Unknown directive type "method".

.. method:: save(filename)

   Save a grid object to *filename*.pickle.


System Message: ERROR/3 (<string>, line 175)

Unknown directive type "method".

.. method:: resample(edges)

   Resample data to a new grid with edges *edges*.  The order of
   the interpolation is set by
   :attr:`interpolation_spline_order`. Returns a new :class:`Grid`.

System Message: ERROR/3 (<string>, line 181)

Unknown directive type "attribute".

.. attribute:: interpolation_spline_order

   Order of the B-spline interpolation of the data. 3 = cubic; 4 &
   5 are also supported. Only choose values that are acceptable to
   :func:`scipy.ndimage.spline_filter`!

System Message: ERROR/3 (<string>, line 187)

Unknown directive type "method".

.. method:: resample_factor(factor)

   Resample to a new regular grid with *factor* * oldN cells along each
   dimension. Returns a new :class:`Grid`.

System Message: ERROR/3 (<string>, line 192)

Unknown directive type "method".

.. method:: centers()

   Returns the coordinates of the centers of all grid cells as an
   iterator.

System Message: ERROR/3 (<string>, line 197)

Unknown directive type "method".

.. method:: check_compatible(other)

     Check if *other* can be used in an arithmetic operation.

     1) *other* is a scalar
     2) *other* is a grid defined on the same edges

     Raises :exc:`TypeError` if not compatible.
Something went wrong with that request. Please try again.