Skip to content

Commit

Permalink
gwyddion reader update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rama Vasudevan committed Jun 14, 2024
1 parent bc71032 commit 1a6d71a
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions SciFiReaders/readers/microscopy/spm/afm/gwyddion.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ def gsf_read(self):

# fix known metadata types from .gsf file specs
# first the mandatory ones...
metadata['XRes'] = np.int(metadata['XRes'])
metadata['YRes'] = np.int(metadata['YRes'])
metadata['XRes'] = int(metadata['XRes'])
metadata['YRes'] = int(metadata['YRes'])

# now check for the optional ones
if 'XReal' in metadata:
metadata['XReal'] = np.float(metadata['XReal'])
metadata['XReal'] = float(metadata['XReal'])

if 'YReal' in metadata:
metadata['YReal'] = np.float(metadata['YReal'])
metadata['YReal'] = float(metadata['YReal'])

if 'XOffset' in metadata:
metadata['XOffset'] = np.float(metadata['XOffset'])
metadata['XOffset'] = float(metadata['XOffset'])

if 'YOffset' in metadata:
metadata['YOffset'] = np.float(metadata['YOffset'])
metadata['YOffset'] = float(metadata['YOffset'])

datasets = []

Expand Down Expand Up @@ -197,8 +197,8 @@ def gwy_read(self):
obj)
elif gwy_key[1] == 'xyz':

channels = self._translate_xyz(gwy_data,
obj)
channels = self._translate_xyz(gwy_data,obj)

return channels


Expand All @@ -208,7 +208,7 @@ def _translate_image_stack(self, gwy_data, obj):
Returns
-------
"""

if obj.endswith('data'):
data = gwy_data[obj].data
title = gwy_data[obj+'/title']
Expand All @@ -228,23 +228,48 @@ def _translate_image_stack(self, gwy_data, obj):
data_set.data_type = 'Image'

#Add quantity and units
data_set.units = gwy_data[obj]['si_unit_z']['unitstr']
if 'si_unit_z' in gwy_data[obj].keys():
data_set.units = gwy_data[obj]['si_unit_z']['unitstr']
else:
data_set.units = 'a.u.'

data_set.quantity = title


if 'si_unit_xy' in gwy_data[obj].keys():
x_unit = y_unit = gwy_data[obj]['si_unit_xy']['unitstr']
else:
x_unit=y_unit='a.u.'

#Add dimension info
data_set.set_dimension(0, sid.Dimension(x_vals,
name = 'x',
units=gwy_data[obj]['si_unit_xy']['unitstr'], quantity = 'x',
dimension_type='spatial'))
data_set.set_dimension(1, sid.Dimension(y_vals,
name = 'y',
units=gwy_data[obj]['si_unit_xy']['unitstr'], quantity = 'y',
dimension_type='spatial'))
dataset_is_transposed = False
if data_set.shape[0] != len(x_vals):
dataset_is_transposed = True

if not dataset_is_transposed:

data_set.set_dimension(0, sid.Dimension(x_vals,
name = 'x',
units=x_unit, quantity = 'x',
dimension_type='spatial'))
data_set.set_dimension(1, sid.Dimension(y_vals,
name = 'y',
units=y_unit, quantity = 'y',
dimension_type='spatial'))
else:
data_set.set_dimension(0, sid.Dimension(y_vals,
name = 'y',
units=y_unit, quantity = 'y',
dimension_type='spatial'))

data_set.set_dimension(1, sid.Dimension(x_vals,
name = 'x',
units=x_unit, quantity = 'x',
dimension_type='spatial'))

# append metadata
data_set.original_metadata = meta_data
data_set.data_type = 'image'

return data_set


Expand Down

0 comments on commit 1a6d71a

Please sign in to comment.