Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve io.smv #62

Merged
merged 6 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions ncempy/io/smv.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def smvWriter(out_path, dp, camera_length=110, lamda=0.0197, pixel_size=0.01, be
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 microED processing programs in Linux are not able to load SMV files with Windows
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 defauly None will use the system default.
line endings. The default `None` will use the system default.
"""
if dp.dtype != np.uint16:
raise TypeError("Only uint16 data type is supported.")
Expand Down Expand Up @@ -260,6 +260,11 @@ def smvReader(file_name, verbose=False):
-------
out : dict
A dictionary containing the data and interesting metadata.

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
-------
Expand All @@ -276,11 +281,10 @@ def smvReader(file_name, verbose=False):
im1 = f1.getDataset() # read in the dataset

# Calculate the pixel size in inverse angstroms according to the geometry in the header
alpha = f1.header_info['PIXEL_SIZE'] / f1.header_info['DISTANCE'] # angle across 1 pixel
BIN = [int(ii) for ii in f1.header_info['BIN'].split('x')]
alpha = (BIN[0] * f1.header_info['PIXEL_SIZE']) / f1.header_info['DISTANCE'] # angle across 1 pixel
dp_pixel_distance = alpha / f1.header_info['WAVELENGTH'] * 1e-10 # divide by wavelength to get distance in Angstroms
pixelSize = (dp_pixel_distance, dp_pixel_distance)
f1.dataOut = {'pixelSize': pixelSize, 'pixelUnit':'A', 'filename': f1.file_name,
'BIN':f1.header_info['BIN']}
print('Warning: pixelSize does not take binning into account.')

return im1 # return the data and metadata as a dictionary
extra_metadata = {'pixelSize': pixelSize, 'pixelUnit':'A', 'filename': f1.file_name}
im1.update(extra_metadata)
return im1
7 changes: 7 additions & 0 deletions ncempy/test/test_io_smv.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ def test_newline_windows(self, temp_file):
vals = f0.read(3)
assert vals[1] == ord('\r')
assert vals[2] == ord('\n')

def test_smvReader(self, data_location):
file_path = data_location / Path('biotin_smv.img')
dd = ncempy.io.smv.smvReader(file_path)
assert 'data' in dd
assert dd['data'].shape[0] == 2048