Skip to content

Commit

Permalink
Merge pull request #129 from pycroscopy/nsid_reader_fn
Browse files Browse the repository at this point in the history
Nsid reader fn
  • Loading branch information
ramav87 authored Jun 5, 2024
2 parents 5be2e64 + bc71032 commit b17a435
Show file tree
Hide file tree
Showing 3 changed files with 540 additions and 7 deletions.
15 changes: 15 additions & 0 deletions SciFiReaders/readers/SID/Nsid_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ def read(self, h5_object=None):
return read_h5py_dataset(h5_object)
else:
return self.read_all(parent=h5_object)

#TODO: We need to add the ability to read functions in any sidpy datasets.
# We will assume that fitting functions are contained within a dictionary of the same name.
#They will have been saved with dill and encoded. To decode them, use:

'''
fit_fn_packed = fit_data.metadata['fitting_functions']
loaded_dict = {}
fit_fns = []
for key in fit_fn_packed.keys():
encoded_value = fit_fn_packed['my_function']
serialized_value = base64.b64decode(encoded_value)
loaded_dict[key] = dill.loads(serialized_value)
fit_fns.append(loaded_dict[key]) #retrieve the function
'''

def __validate_obj_in_same_file(self, h5_object):
"""
Expand Down
31 changes: 24 additions & 7 deletions SciFiReaders/readers/microscopy/spm/afm/bruker_nano.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _read_image_stack(self):
#Here are teh dimension details
num_samps_line = layer_info['Samps/line']
num_lines = layer_info['Number of lines']

#Read through and write to sidpy dataset objects
datasets = []
for class_name in self.meta_data.keys():
Expand All @@ -162,10 +162,21 @@ def _read_image_stack(self):
quantity = layer_info.pop('Image Data_2')
title = quantity.split("\"")[1]
data = self._read_image_layer(layer_info)
num_cols, num_rows = data.shape
data_set = sid.Dataset.from_array(data, name=title)
data_set.data_type = 'Image'
traces = None
if len(data.shape)==2:
num_cols, num_rows = data.shape

elif len(data.shape)==3:
num_cols, num_rows, traces = data.shape
else:
raise ValueError("data is shape {}, too few/many for image stack".format(data.shape))

data_set = sid.Dataset.from_array(data, name=title)
if traces is None:
data_set.data_type = 'Image'
else:
data_set.data_type='Image_Stack'

#Add quantity and units
data_set.units = 'nm' #check this one
data_set.quantity = quantity
Expand All @@ -179,10 +190,11 @@ def _read_image_stack(self):
name = 'y',
units='nm', quantity='y',
dimension_type='spatial'))

if traces is not None:
data_set.set_dimension(2, sid.Dimension(np.arange(traces), name = 'trace #', units ='#', quantity = 'none', dimension_type = 'frame'))

# append metadata
data_set.original_metadata = self.meta_data[class_name]
data_set.data_type = 'image'

datasets.append(data_set)

Expand Down Expand Up @@ -335,7 +347,11 @@ def _read_image_layer(self, layer_info):
2D array representing the requested channel of information
"""
data_vec = self._read_data_vector(layer_info)
data_mat = data_vec.reshape(layer_info['Number of lines'], layer_info['Samps/line'])
if np.size(data_vec)==layer_info['Number of lines']*layer_info['Samps/line']:
data_mat = data_vec.reshape(layer_info['Number of lines'], layer_info['Samps/line'])
elif np.size(data_vec)==layer_info['Number of lines']*layer_info['Samps/line']*2:
print('detected trace and retrace, attempting to reshape')
data_mat = data_vec.reshape(layer_info['Number of lines'], layer_info['Samps/line'],2)
return data_mat

def can_read(self):
Expand All @@ -348,3 +364,4 @@ def can_read(self):
"""
return super(BrukerAFMReader, self).can_read(extension='')


Loading

0 comments on commit b17a435

Please sign in to comment.