ncempy.io.smv module¶
This module provides an interface to SMV files which often end in the IMG format. These are commonly used in microED.
See https://wiki.uni-konstanz.de/ccp4/index.php/SMV_file_format for more details.
Note
- General users:
Use the simplified smv.smvReader() function to load the data and meta data as a python dictionary.
- Advanced users and developers:
Access the file internals through the smv.fileSMV() class.
- class ncempy.io.smv.fileSMV(filename, verbose=False)[source]¶
Bases:
objectClass to represent SMV files.
- Variables:
file_name (str) – The name of the file
file_path (pathlib.Path) – A pathlib.Path object for the open file
fid (file) – The file handle to the opened MRC file.
dataType (np.dtype) – The numpy dtype of the data.
dataSize (np.ndarray) – The number of pixels along each dimension. Corresponds to the shape attribute of a np.ndarray
num_header_bytes – The number of bytes in the header. Usually 512.
header_info (dict) – A dictionary containing typical header meta data. See _expected_keys for a list.
custom_info (dict) – A dictionary containing extra header meta data. All meta data not in _expected_keys.
binned_by=1 (camera_length=110, lamda=0.0197, pixel_size=0.01, beam_center=None,)
- getDataset()[source]¶
Read the data from the file
- Returns:
dict
A dictionary containng the data in a dictionary with the key ‘data’
- getMetadata()[source]¶
Reads the metadata from the file
- Returns:
dict
A dicitons contained useful experimental metadata.
- ncempy.io.smv.smvReader(file_name, verbose=False)[source]¶
A simple function to read open a SMV, parse the header, and read the data and meta data.
- Parameters:
file_name (str or pathlib.Path) – The path to the file to load.
- Returns:
out – A dictionary containing the data and interesting metadata.
- Return type:
Note
The returned dictionary has an entry called pixelSize. This is the calibrated distance in angstroms. It is not the physical size of a detector pixel.
Example
Simply read in all data from disk into memory. This assumes the dataset is 3 dimensional: >> from ncempy.io.smv import smvReader >> import matplotlib.pyplot as plt >> mrc1 = smvReader.(‘filename.mrc’) >> plt.imshow(mrc1[‘data’][0, :, :]) #show the first image in the data set
- ncempy.io.smv.smvWriter(out_path, dp, camera_length=110, lamda=0.0197, pixel_size=0.01, beam_center=None, binned_by=1, newline=None, custom_header=None)[source]¶
Write out data as a SMV (.img) formatted file Header is 512 bytes of zeros and then filled with ASCII.
Note: - only little endian is supported - only uint16 is supported - ony 2D data is supported - some other meta data (PHI, DATE, etc.) is populated with hard coded values - Header size is hard coded to 512 bytes
- Parameters:
camera_length (float) – The calibrated camera length (not the label) in mm. Default is 110 mm.
lamda (float) – The wavelength of the radiation in Ansgroms. Default is 0.0197 for 300 kV electrons
pixel_size (float) – Physical detector pixel size in mm. Default is 0.01 mm (10 microns)
beam_center (tuple) – The location of the center beam in column, row format in mm (not pixels!)
binned_by (int) – The binning applied to the original data. This is necessary for proper calibrations of detector distances and beam center. Default is 1.
newline (str (optional)) – Allow the user to specify the newline character. For data written on Windows computers some processing programs in Linux are not able to load SMV files with Windows carriage return and newline characters. Use ‘n’ on Windows machines to enforce Linux line endings. The default None will use the system default.
custom_header (dict) – This allows the user to input custom header lines using a dictionary. Each key/value pair is saved as KEY = value in the header. The users is not allowed to create a header larger than 512 bytes. An AssertionError is raised if the header is too large.