Skip to content

Commit

Permalink
pixelSize now takes into account binning. Return all metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ercius committed Mar 2, 2024
1 parent 5b020a4 commit 3f75be5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions ncempy/io/smv.py
Original file line number Diff line number Diff line change
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
alpha = (f1.heaer_info['BIN'] * 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,
extra_metadata = {'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
im1.update(extra_metadata)
return im1
3 changes: 2 additions & 1 deletion ncempy/test/test_io_smv.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def test_newline_windows(self, temp_file):
assert vals[1] == ord('\r')
assert vals[2] == ord('\n')

def test_smvReader(self, temp_file):
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

0 comments on commit 3f75be5

Please sign in to comment.