Skip to content

Commit

Permalink
Updated gwyddion.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BlytheDumerer committed Jun 17, 2024
1 parent 0534e26 commit 6bed5b3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions SciFiReaders/readers/microscopy/spm/afm/gwyddion.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,31 @@ def gsf_read(self):
data_set.data_type = 'Image'

#Add quantity and units
data_set.units = "a.u" #metadata['ZUnits']

try:
data_set.units = metadata['ZUnits']
except Exception as e:
# If an error occurs, fall back to using "a.u"
data_set.units = "a.u"
data_set.quantity = metadata['Title']

#Add dimension info
data_set.set_dimension(0, sid.Dimension(np.linspace(0, metadata['XReal'], num_cols),
name = 'x',
units= "a.u", #metadata['XYUnits'],
try:
units = metadata['XYUnits'],
except Exception as e:
# If an error occurs, fall back to using "a.u"
units= "a.u",
quantity = 'x',
dimension_type='spatial'))
data_set.set_dimension(1, sid.Dimension(np.linspace(0, metadata['YReal'], num_rows),
name = 'y',
units="a.u", #metadata['XYUnits'],
try:
units = metadata['XYUnits'],
except Exception as e:
# If an error occurs, fall back to using "a.u"
units= "a.u",
quantity = 'y',
dimension_type='spatial'))

Expand Down

1 comment on commit 6bed5b3

@ramav87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of try/except, here you should check to see if the dictionary contains the relevant key. This is because if there is some other bug, such as the units not being in the correct format but the key does not exist, then we would not be aware of it.

Please sign in to comment.