Skip to main content

MRC file I/O library

Project description

Build Status Python Package Index Python Versions Documentation

mrcfile.py is a Python implementation of the MRC2014 file format, which is used in structural biology to store image and volume data.

It allows MRC files to be created and opened easily using a very simple API, which exposes the file’s header and data as numpy arrays. The code runs in Python 2 and 3 and is fully unit-tested.

The intent of this library is to allow users and developers to read and write standard-compliant MRC files in Python as easily as possible, and with no dependencies on any compiled libraries except numpy. You can use it interactively to inspect files, correct headers and so on, or in scripts and larger software packages to provide basic MRC file I/O functions.

Key Features

  • Clean, simple API for access to MRC files

  • Easy to install and use

  • Seamless support for gzip files

  • Memory-mapped file option for fast random access to very large files

  • Runs in Python 2 & 3

Installation

The mrcfile library is available from the Python package index:

pip install mrcfile

The source code (including the full test suite) can be found on GitHub: https://github.com/ccpem/mrcfile

Basic usage

The easiest way to open a file is with the mrcfile.open and mrcfile.new functions. These return an MrcFile object which represents an MRC file on disk.

To open an MRC file and read a slice of data:

>>> import mrcfile
>>> with mrcfile.open('tests/test_data/EMD-3197.map') as mrc:
...     mrc.data[10,10]
...
array([ 2.58179283,  3.1406002 ,  3.64495397,  3.63812137,  3.61837363,
        4.0115056 ,  3.66981959,  2.07317996,  0.1251585 , -0.87975615,
        0.12517013,  2.07319379,  3.66982722,  4.0115037 ,  3.61837196,
        3.6381247 ,  3.64495087,  3.14059472,  2.58178973,  1.92690361], dtype=float32)

To create a new file with a 2D data array, and change some values:

>>> with mrcfile.new('tmp.mrc') as mrc:
...     mrc.set_data(np.zeros((5, 5), dtype=np.int8))
...     mrc.data[1:4,1:4] = 10
...     mrc.data
...
array([[ 0,  0,  0,  0,  0],
       [ 0, 10, 10, 10,  0],
       [ 0, 10, 10, 10,  0],
       [ 0, 10, 10, 10,  0],
       [ 0,  0,  0,  0,  0]], dtype=int8)

Close the file after use by calling close() which will save the data to disk when the file is closed. You can also call flush() manually to flush the data to disk and keep the file open. If you open a file using Python’s with keyword (as in the examples above), it will be closed automatically at the end of the with block, like a normal Python file object.

Documentation

Full documentation is available at http://mrcfile.readthedocs.org

Contributing

Please use the GitHub issue tracker for bug reports and feature requests: https://github.com/ccpem/mrcfile/issues

Code contributions are also welcome, please submit pull requests to the GitHub repository.

To run the test suite, from the directory which contains the mrcfile and tests packages, run python -m unittest tests. (Or, if you have tox, Python 2.7 and Python 3.5 installed, run tox.)

Licence

The project is released under the BSD licence.

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

mrcfile-0.2.4.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

mrcfile-0.2.4-py2.py3-none-any.whl (28.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mrcfile-0.2.4.tar.gz.

File metadata

  • Download URL: mrcfile-0.2.4.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mrcfile-0.2.4.tar.gz
Algorithm Hash digest
SHA256 8d26e9c57af6c2fb5b760ea586662ca4ea8d25975cf50d42262a1f3138efed11
MD5 8e84b4347682aa22c65f7ced9f6f6892
BLAKE2b-256 90f9c01b3ea0ffb1b52c1b90a8c9b20c9031452b948ce0f427101d9fc00281e5

See more details on using hashes here.

Provenance

File details

Details for the file mrcfile-0.2.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for mrcfile-0.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2a9c3756a8ea300d16a6077f4be81ab70543e1a325f9a9c09126404f698beb5c
MD5 e0798a3ed2e090abfc1869cefc1fbfee
BLAKE2b-256 be542a76d4708940bdc15f7680ec3ddd77e1395b67c89246cd803f1a06a1f03c

See more details on using hashes here.

Provenance

Supported by

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