Skip to main content

A Digital Micrograph 4 (DM4) file reader.

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

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.tar.gz (9.5 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-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: dm4-1.0.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for dm4-1.0.3.tar.gz
Algorithm Hash digest
SHA256 855c2a7b991cdaac39221081e239c74a6feac4a220785f03e5e3941c768d7c76
MD5 d79b828445f98ca5f866e32ef513d906
BLAKE2b-256 227a0162251ce3220e76007be251c74709c62bdbc3f666d4f5827e508997932c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dm4-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for dm4-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 027049b105d1ff5f66b2671b90df3b378b32cd0dbab17fa2ac491389ca27a663
MD5 6fcaf9569e7185c90d86b6a615f76254
BLAKE2b-256 bf1609f7355ebcd5053c181c5629582f094832974ec336bfb5611a64666d02d2

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