def _translate_gwy(self, file_path, meas_grp): """ Parameters ---------- file_path meas_grp For more information on the .gwy file format visit the link below - http://gwyddion.net/documentation/user-guide-en/gwyfile-format.html """ # Need to build a set of channels to test against and a function-level variable to write to channels = {} # Read the data in from the specified file gwy_data = gwyfile.load(file_path) for obj in gwy_data: gwy_key = obj.split('/') try: # if the second index of the gwy_key can be cast into an int then # it needs to be processed either as an image or a graph int(gwy_key[1]) if gwy_key[2] == 'graph': # graph processing self.global_parms['data_type'] = 'GwyddionGWY_' + 'Graph' channels = self._translate_graph(meas_grp, gwy_data, obj, channels) elif obj.endswith('data'): self.global_parms['data_type'] = 'GwyddionGWY_' + 'Image' channels = self._translate_image_stack( meas_grp, gwy_data, obj, channels) else: continue except ValueError: # if the second index of the gwy_key cannot be cast into an int # then it needs to be processed wither as a spectra, volume or xyz if gwy_key[1] == 'sps': self.global_parms['data_type'] = 'GwyddionGWY_' + 'Spectra' channels = self._translate_spectra(meas_grp, gwy_data, obj, channels) elif gwy_key[1] == 'brick': self.global_parms['data_type'] = 'GwyddionGWY_' + 'Volume' channels = self._translate_volume(meas_grp, gwy_data, obj, channels) elif gwy_key[1] == 'xyz': self.global_parms['data_type'] = 'GwyddionGWY_' + 'XYZ' channels = self._translate_xyz(meas_grp, gwy_data, obj, channels) write_simple_attrs(meas_grp.parent, self.global_parms)
def load_image(image_path): ''' Load the image from image_path. Return the leveled height data and the extents of the image in nanometers ''' gwyobj = gwyfile.load(image_path) channels = gwyfile.util.get_datafields(gwyobj) topography = channels['Topography'] data = topography.data * 1e9 # Convert to nm assert data.shape == (IMAGE_SIZE,IMAGE_SIZE) data_leveled = level_image(data) extent = topography.xreal * 1e9 # Convert to nm return data_leveled, extent
def _translate_gwy(self, file_path, meas_grp): """ Parameters ---------- file_path meas_grp For more information on the .gwy file format visit the link below - http://gwyddion.net/documentation/user-guide-en/gwyfile-format.html """ # Need to build a set of channels to test against and a function-level variable to write to channels = {} # Read the data in from the specified file gwy_data = gwyfile.load(file_path) for obj in gwy_data: gwy_key = obj.split('/') try: # if the second index of the gwy_key can be cast into an int then # it needs to be processed either as an image or a graph int(gwy_key[1]) if gwy_key[2] == 'graph': # graph processing self.global_parms['data_type'] = 'GwyddionGWY_' + 'Graph' channels = self._translate_graph(meas_grp, gwy_data, obj, channels) elif obj.endswith('data'): self.global_parms['data_type'] = 'GwyddionGWY_' + 'Image' channels = self._translate_image_stack(meas_grp, gwy_data, obj, channels) else: continue except ValueError: # if the second index of the gwy_key cannot be cast into an int # then it needs to be processed wither as a spectra, volume or xyz if gwy_key[1] == 'sps': self.global_parms['data_type'] = 'GwyddionGWY_' + 'Spectra' channels = self._translate_spectra(meas_grp, gwy_data, obj, channels) elif gwy_key[1] == 'brick': self.global_parms['data_type'] = 'GwyddionGWY_' + 'Volume' channels = self._translate_volume(meas_grp, gwy_data, obj, channels) elif gwy_key[1] == 'xyz': self.global_parms['data_type'] = 'GwyddionGWY_' + 'XYZ' channels = self._translate_xyz(meas_grp, gwy_data, obj, channels) write_simple_attrs(meas_grp.parent, self.global_parms)
def gwy_read(self): """ Parameters ---------- file_path meas_grp For more information on the .gwy file format visit the link below - http://gwyddion.net/documentation/user-guide-en/gwyfile-format.html """ # Need to build a set of channels to test against and a function-level variable to write to channels = [] # Read the data in from the specified file gwy_data = gwyfile.load(self._input_file_path) for obj in gwy_data: gwy_key = obj.split('/') try: # if the second index of the gwy_key can be cast into an int then # it needs to be processed either as an image or a graph int(gwy_key[1]) if gwy_key[2] == 'graph': # graph processing channels = self._translate_graph(gwy_data, obj) elif obj.endswith('data'): channels.append(self._translate_image_stack(gwy_data, obj)) else: continue except ValueError: # if the second index of the gwy_key cannot be cast into an int # then it needs to be processed wither as a spectra, volume or xyz if gwy_key[1] == 'sps': channels = self._translate_spectra(gwy_data, obj) elif gwy_key[1] == 'brick': channels = self._translate_volume(gwy_data, obj) elif gwy_key[1] == 'xyz': channels = self._translate_xyz(gwy_data, obj) return channels
def test_data(): filename = os.path.realpath('{}/test.gwy'.format( os.path.dirname(os.path.realpath(__file__)))) return gwyfile.load(filename)