A comprehensive collection of algorithms and routines for electron microscopy data analysis and simulation.
—
Universal file reading and format conversion for multiple electron microscopy file formats. The I/O module provides a unified interface for accessing data from various proprietary microscopy formats while preserving metadata and calibration information.
Main entry point for reading electron microscopy files. Automatically detects file format and returns structured data with metadata.
def read(filename: str) -> dict:
"""
Universal file reader for electron microscopy formats.
Parameters:
- filename: str, path to the microscopy data file
Returns:
dict: Dictionary containing:
- 'data': numpy array of image/spectrum data
- 'pixelSize': list of pixel sizes for each dimension
- 'pixelUnit': list of units for each dimension
- 'pixelOrigin': list of origins for each dimension
- Additional format-specific metadata
"""Support for Gatan Digital Micrograph DM3 and DM4 files with complete tag structure parsing.
class fileDM:
"""
Digital Micrograph file handler.
Attributes:
- filename: str, path to DM file
- tags: dict, parsed tag structure
- numObjects: int, number of data objects
"""
def __init__(self, filename: str): ...
def getDataset(self, index: int) -> dict: ...
def getSlice(self, slice_obj, mem_map: bool = False): ...
def dmReader(filename: str) -> dict:
"""
Read Digital Micrograph files.
Parameters:
- filename: str, path to .dm3 or .dm4 file
Returns:
dict: Data dictionary with image arrays and metadata
"""Support for FEI/Thermo Fisher TIA SER files and associated EMI metadata.
class fileSER:
"""
SER file handler for TIA format.
Attributes:
- filename: str, path to SER file
- head: dict, file header information
- numObjects: int, number of data objects
"""
def __init__(self, filename: str): ...
def getDataset(self, index: int) -> dict: ...
def getSlice(self, slice_obj, mem_map: bool = False): ...
def serReader(filename: str) -> dict:
"""
Read SER files with EMI metadata.
Parameters:
- filename: str, path to .ser file
Returns:
dict: Data dictionary with series data and metadata
"""
def read_emi(filename: str) -> dict:
"""
Read EMI metadata file associated with SER.
Parameters:
- filename: str, path to .emi file
Returns:
dict: Parsed EMI metadata
"""
class NotSERError(Exception):
"""Exception raised when file is not a valid SER file."""Support for Electron Microscopy Dataset (EMD) HDF5-based files.
class fileEMD:
"""
EMD file handler for HDF5-based format.
Attributes:
- filename: str, path to EMD file
- file_hdl: h5py.File, HDF5 file handle
- version: tuple, EMD format version
"""
def __init__(self, filename: str, readonly: bool = True): ...
def get_emdgroup(self, group_number: int): ...
def list_emds(self) -> list: ...
def put_emdgroup(self, group_name: str, data, **kwargs): ...
def emdReader(filename: str, dset_name: str = None) -> dict:
"""
Read EMD files.
Parameters:
- filename: str, path to .emd file
- dset_name: str, specific dataset name to read
Returns:
dict: Data dictionary with arrays and metadata
"""
def emdWriter(filename: str, data_dict: dict, **kwargs):
"""
Write EMD files.
Parameters:
- filename: str, output EMD file path
- data_dict: dict, data to write with metadata
"""
class NoEmdDataSets(Exception):
"""Exception raised when no EMD datasets found."""
class UnsupportedEmdVersion(Exception):
"""Exception raised for unsupported EMD versions."""Support for FEI Velox EMD format files.
class fileEMDVelox:
"""
EMD Velox file handler.
Attributes:
- filename: str, path to Velox EMD file
- file_hdl: h5py.File, HDF5 file handle
"""
def __init__(self, filename: str): ...
def get_dataset(self, index: int) -> dict: ...
def list_datasets(self) -> list: ...
def emdVeloxReader(filename: str) -> dict:
"""
Read EMD Velox files.
Parameters:
- filename: str, path to Velox EMD file
Returns:
dict: Data dictionary with detector data and metadata
"""Support for Medical Research Council (MRC) format files commonly used in cryo-EM.
class fileMRC:
"""
MRC file handler.
Attributes:
- filename: str, path to MRC file
- header: dict, MRC header information
"""
def __init__(self, filename: str): ...
def getSlice(self, slice_obj, mem_map: bool = False): ...
def mrcReader(filename: str) -> dict:
"""
Read MRC files.
Parameters:
- filename: str, path to .mrc file
Returns:
dict: Volume data with header metadata
"""
def mrcWriter(filename: str, data_dict: dict):
"""
Write MRC files.
Parameters:
- filename: str, output MRC file path
- data_dict: dict, volume data and metadata
"""
def mrc2emd(mrc_file: str, emd_file: str):
"""
Convert MRC file to EMD format.
Parameters:
- mrc_file: str, input MRC file path
- emd_file: str, output EMD file path
"""
def emd2mrc(emd_file: str, mrc_file: str):
"""
Convert EMD file to MRC format.
Parameters:
- emd_file: str, input EMD file path
- mrc_file: str, output MRC file path
"""Support for Single-image (SMV) format files used in crystallography.
class fileSMV:
"""
SMV file handler.
Attributes:
- filename: str, path to SMV file
- header: dict, SMV header information
"""
def __init__(self, filename: str): ...
def getSlice(self, slice_obj): ...
def smvReader(filename: str) -> dict:
"""
Read SMV files.
Parameters:
- filename: str, path to .smv file
Returns:
dict: Image data with header metadata
"""
def smvWriter(filename: str, data_dict: dict):
"""
Write SMV files.
Parameters:
- filename: str, output SMV file path
- data_dict: dict, image data and metadata
"""Support for DECTRIS detector format files.
class fileDECTRIS:
"""
DECTRIS file handler.
Attributes:
- filename: str, path to DECTRIS file
"""
def __init__(self, filename: str): ...import ncempy.io
# Universal reader - automatically detects format
data = ncempy.io.read('image.dm4')
print(f"Data shape: {data['data'].shape}")
print(f"Pixel size: {data['pixelSize']}")
# Read SER file series
ser_data = ncempy.io.read('series.ser')
for i, frame in enumerate(ser_data['data']):
print(f"Frame {i}: {frame.shape}")
# Read EMD with specific dataset
emd_data = ncempy.io.emdReader('volume.emd', dset_name='data')import ncempy.io
# Convert MRC to EMD
ncempy.io.mrc2emd('volume.mrc', 'volume.emd')
# Convert EMD to MRC
ncempy.io.emd2mrc('volume.emd', 'volume.mrc')
# Write new EMD file
data_dict = {
'data': image_array,
'pixelSize': [1.0, 1.0],
'pixelUnit': ['nm', 'nm']
}
ncempy.io.emdWriter('output.emd', data_dict)Install with Tessl CLI
npx tessl i tessl/pypi-ncempy