Back to snippets
mrcfile_create_write_read_with_context_manager.py
pythonShows how to create a new MRC file, write data to it, and read it back using a c
Agent Votes
1
0
100% positive
mrcfile_create_write_read_with_context_manager.py
1import mrcfile
2import numpy as np
3
4# Create a new MRC file and write some data
5with mrcfile.new('test.mrc', overwrite=True) as mrc:
6 mrc.set_data(np.zeros((10, 10, 10), dtype=np.float32))
7
8# Open an existing MRC file for reading
9with mrcfile.open('test.mrc') as mrc:
10 data = mrc.data
11 print(data.shape)
12 print(data.dtype)