CBF is a simple Python package (Python 3.x) for reading and writing cbf (Crystallographic Binary Format) files.
pip install cbf
- Read CBF file
import cbf
content = cbf.read('example.cbf')
numpy_array_with_data = content.data
header_metadata = content.metadata
# Plot image with matplot lib
from matplotlib import pyplot as plt
plt.imshow(numpy_array_with_data, cmap='gray', vmax=50)
plt.show()
- Write CBF file
import cbf
cbf.write('example.cbf', numpy_array)