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.
Metadata
Release files for dm4 1.0.3.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dm4-1.0.3.post1.tar.gz | 9.8 kB | Without provenance | Details for dm4-1.0.3.post1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dm4-1.0.3.post1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for dm4-1.0.3.post1-py2.py3-none-any.whl |
Total release size: 19.1 kB
Release files / dm4-1.0.3.post1.tar.gz
| Download URL | dm4-1.0.3.post1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83ecc66b98d58143389e3e0b02773ddfb23027219aa2cb04db51f8458e49d55a
|
|
BLAKE2b-256 checksum How to use checksums |
70f7ca2e8bcf7033433156cc26392205458438261a69b3477896e4e90c8860c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / dm4-1.0.3.post1-py2.py3-none-any.whl
| Download URL | dm4-1.0.3.post1-py2.py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
eec63f6f78892414f4e8330a23303c6a4f19270cd0c156de0249dad89269e4a5
|
|
BLAKE2b-256 checksum How to use checksums |
514a8946bd1eaf7acb7e0c2ffb895fbc06242a059e13f61a87c16d9feee4702a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for dm4 1.0.3.post1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.