Skip to main content

Reading and writing of data on regular grids in Python

Project description

The gridDataFormats package provides classes to unify reading and writing n-dimensional datasets. One can read grid data from files, make them available as a Grid object, and allows one to write out the data again.

The Grid class

A 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.

This is equivalent to knowing

  1. The origin of the coordinate system (i.e. which data cell corresponds to (0,0,…,0)

  2. The spacing of the grid in each dimension.

  3. The data on a grid.

Grid objects have some convenient properties:

  • The data is represented as a numpy.array and thus shares all the advantages coming with this sophisticated and powerful library.

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

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

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

Supported file formats

The package can be easily extended. The OpenDX format is widely understood by many molecular viewers and is sufficient for many applications that were encountered so far. Hence, at the moment only a small number of file formats is directly supported.

format

extension

read

write

remarks

OpenDX

dx

x

x

subset of OpenDX implemented

gOpenMol

plt

x

pickle

pickle

x

x

standard Python pickle of the Grid class

Examples

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

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 numpy.histogramdd:

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 gridData.Grid

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 Grid objects:

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GridDataFormats-0.2.3.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

GridDataFormats-0.2.3-py2.7.egg (52.3 kB view details)

Uploaded Egg

File details

Details for the file GridDataFormats-0.2.3.tar.gz.

File metadata

File hashes

Hashes for GridDataFormats-0.2.3.tar.gz
Algorithm Hash digest
SHA256 2064d05005ffed0165b687b652e60796706ab0babe7ae93ca62cc666984711f0
MD5 3f3a7f8d539eccf43aa77279e6c17b49
BLAKE2b-256 ab57f5db1992f19c35c2ec18e9db5e20e0b77b2ee7806ca2582835e10481d7da

See more details on using hashes here.

File details

Details for the file GridDataFormats-0.2.3-py2.7.egg.

File metadata

File hashes

Hashes for GridDataFormats-0.2.3-py2.7.egg
Algorithm Hash digest
SHA256 99b5d1b3178fa85fd39247cbc1988f05306d67f218ec41791b7da0d3c4ef93a7
MD5 d19a680635368935bb94862db8be88fc
BLAKE2b-256 ec904546a1c9e6cf6a81a6be1a60291ab3efc2566dfaca0d7d15c13a43f65bef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page