Skip to main content

Pure Python reader for Gatan Digital Micrograph 4 (DM4) files, providing access to image data and hierarchical metadata tags used in transmission electron microscopy.

Project description

dm4

A pure python file reader for Digital Micrograph’s DM4 file format

This package would not have been possible without the documentation provided by Dr Chris Boothroyd at http://www.er-c.org/cbb/info/dmformat/ Thank you.

Installation

Install using pip from the command line:

pip install dm4

Example

Below is a short example of reading the image data from a dm4 file. A more complete example can be found in the tests.:

import dm4
import PIL

input_path = "your_filename_here.dm4"

with dm4.DM4File.open(input_path) as dm4file:
    tags = dm4file.read_directory()

    image_data_tag = tags.named_subdirs['ImageList'].unnamed_subdirs[1].named_subdirs['ImageData']
    image_tag = image_data_tag.named_tags['Data']

    XDim = dm4file.read_tag_data(image_data_tag.named_subdirs['Dimensions'].unnamed_tags[0])
    YDim = dm4file.read_tag_data(image_data_tag.named_subdirs['Dimensions'].unnamed_tags[1])

    image_array = np.array(dm4file.read_tag_data(image_tag), dtype=np.uint16)
    image_array = np.reshape(image_array, (YDim, XDim))

    output_fullpath = "sample.tif"
    image = PIL.Image.fromarray(image_array, 'I;16')
    image.save(output_fullpath)

Script usage

The dm4 module can be invoked as a script to print a dm4 file’s full directory to the command line. This is helpful when determining the exact structure of a specific DM4 file:

python -m dm4 your_dm4_file.dm4

Helper Functions

Print all of the tags and directories contained in a dm4 file to the console:

dm4.print_tag_directory_tree(dmfile: DM4File, dir_obj: DM4TagDir, indent_level: int = 0)

Print data associated with a specific tag to the console, if it is printable:

dm4.print_tag_data(dmfile: DM4File, tag: Union[DM4TagHeader, DM4DirHeader], indent_level: int)

Todo

Reading arrays of groups has not been implemented.

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

dm4-1.0.3.post1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

dm4-1.0.3.post1-py2.py3-none-any.whl (9.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dm4-1.0.3.post1.tar.gz.

File metadata

  • Download URL: dm4-1.0.3.post1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dm4-1.0.3.post1.tar.gz
Algorithm Hash digest
SHA256 83ecc66b98d58143389e3e0b02773ddfb23027219aa2cb04db51f8458e49d55a
MD5 e6f6af8ea80644ec7806e7c4e26ea68b
BLAKE2b-256 70f7ca2e8bcf7033433156cc26392205458438261a69b3477896e4e90c8860c2

See more details on using hashes here.

File details

Details for the file dm4-1.0.3.post1-py2.py3-none-any.whl.

File metadata

  • Download URL: dm4-1.0.3.post1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dm4-1.0.3.post1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 eec63f6f78892414f4e8330a23303c6a4f19270cd0c156de0249dad89269e4a5
MD5 ff0fa1a86a7fe1cb82d562d2998a6671
BLAKE2b-256 514a8946bd1eaf7acb7e0c2ffb895fbc06242a059e13f61a87c16d9feee4702a

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