0
# ncempy
1
2
A comprehensive Python library for electron microscopy data analysis and simulation. ncempy provides algorithms and routines for image processing, file I/O with various microscopy formats, visualization tools, data evaluation, and specialized EDS tomography reconstruction capabilities for electron microscopy research.
3
4
## Package Information
5
6
- **Package Name**: ncempy
7
- **Language**: Python
8
- **Installation**: `pip install ncempy`
9
10
## Core Imports
11
12
```python
13
import ncempy
14
```
15
16
Common usage patterns:
17
18
```python
19
import ncempy.io
20
import ncempy.algo
21
import ncempy.viz
22
import ncempy.eval
23
24
# Direct access to main functions
25
from ncempy import read, plot
26
```
27
28
## Basic Usage
29
30
```python
31
import ncempy
32
import matplotlib.pyplot as plt
33
34
# Read electron microscopy data files
35
data = ncempy.read('microscopy_data.dm3')
36
print(f"Data shape: {data['data'].shape}")
37
print(f"Pixel size: {data['pixelSize']}")
38
39
# Display the data
40
ncempy.plot(data)
41
plt.show()
42
43
# Perform image correlation alignment
44
import ncempy.algo as algo
45
aligned = algo.image_correlate(data['data'], reference_image)
46
47
# Visualize with calibrated axes
48
ncempy.viz.im_calibrated(aligned, data['pixelSize'])
49
plt.show()
50
```
51
52
## Architecture
53
54
ncempy is organized into modular components for maximum reusability:
55
56
- **I/O Module**: Universal file reader supporting multiple microscopy formats (SER, DM3/DM4, EMD, MRC, SMV)
57
- **Algorithm Module**: Core image processing, correlation, peak finding, and mathematical functions
58
- **Visualization Module**: Plotting utilities optimized for microscopy data with calibrated axes
59
- **Evaluation Module**: Analysis tools for stack alignment, line profiles, and ring diffraction
60
- **EDS Tomography Module**: Specialized tools for energy-dispersive X-ray spectroscopy tomography reconstruction
61
62
## Capabilities
63
64
### File Input/Output
65
66
Universal file reading and format conversion for multiple electron microscopy file formats including Digital Micrograph, SER, EMD/HDF5, MRC, and SMV files.
67
68
```python { .api }
69
def read(filename: str) -> dict: ...
70
```
71
72
[File I/O Operations](./file-io.md)
73
74
### Image Processing Algorithms
75
76
Comprehensive image processing capabilities including correlation-based alignment, peak detection, Fourier operations, distortion correction, and mathematical fitting functions.
77
78
```python { .api }
79
def image_correlate(image1, image2, **kwargs): ...
80
def stack_align(image_stack, **kwargs): ...
81
def peakFind2D(image, **kwargs): ...
82
def rebin(array, shape_out, **kwargs): ...
83
```
84
85
[Image Processing Algorithms](./algorithms.md)
86
87
### Data Visualization
88
89
Specialized plotting functions for electron microscopy data with calibrated axes, FFT displays, interactive stack viewing, and scientific visualization tools.
90
91
```python { .api }
92
def plot(data_dict, **kwargs): ...
93
def im_calibrated(image, pixel_size, **kwargs): ...
94
def imfft(image, **kwargs): ...
95
class stack_view: ...
96
```
97
98
[Visualization Tools](./visualization.md)
99
100
### Data Evaluation
101
102
Analysis tools for extracting quantitative information from microscopy data including line profiles, ring diffraction analysis, and multi-correlation techniques.
103
104
```python { .api }
105
def line_profile(image, start, end, **kwargs): ...
106
def multicorr(image_stack, **kwargs): ...
107
```
108
109
[Data Evaluation](./evaluation.md)
110
111
### EDS Tomography
112
113
Specialized functionality for energy-dispersive X-ray spectroscopy tomography including preprocessing, reconstruction interface with GENFIRE, and postprocessing tools.
114
115
```python { .api }
116
def ExtractSignalsFromEMD(emd_file, **kwargs): ...
117
def WriteSignalsToGENFIRE(signals, **kwargs): ...
118
def ReadGENFIRESignals(results_file, **kwargs): ...
119
```
120
121
[EDS Tomography](./eds-tomography.md)
122
123
### Command Line Tools
124
125
CLI utilities for common tasks including file format conversion and batch processing operations.
126
127
```python { .api }
128
# Console script: ncem2png
129
def main(): ...
130
```
131
132
[Command Line Tools](./command-line.md)
133
134
## Supported File Formats
135
136
- **SER files** (`.ser`) - FEI/Thermo Fisher TIA format
137
- **Digital Micrograph files** (`.dm3`, `.dm4`) - Gatan format
138
- **EMD/HDF5 files** (`.emd`, `.h5`, `.hdf5`) - Electron Microscopy Dataset format
139
- **MRC files** (`.mrc`, `.rec`, `.st`, `.ali`) - Medical Research Council format
140
- **SMV files** (`.smv`, `.img`) - Single-image format
141
142
## Dependencies
143
144
- **Core**: numpy>=2, scipy, matplotlib, h5py>=3
145
- **Optional**: glob2, genfire, hyperspy, scikit-image, ipyvolume (for EDS tomography)