Beispiel #1
0
def choosechannels(data, channel1, channel2):
    # Obtain the data field ids for the data file (i.e. the various channels within the file)
    ids = gwy.gwy_app_data_browser_get_data_ids(data)
    # Make an empty array for the chosen channels to be saved into
    chosen_ids = []
    # Find channels with the title ZSensor, if these do not exist, find channels with the title Height
    chosen_ids = gwy.gwy_app_data_browser_find_data_by_title(data, channel1)
    if not chosen_ids:
        chosen_ids = gwy.gwy_app_data_browser_find_data_by_title(data, channel2)
    else:
        chosen_ids = chosen_ids
    # Save out chosen_ids as a list of the channel ids for ZSensor or height if ZSensor doesnt exist
    return chosen_ids
Beispiel #2
0
 def __init__(self, m_file, **kwargs):
     self.surface = None
     Data.__init__(self, m_file, **kwargs)
     self.container = gwy.gwy_file_load(self.m_file, gwy.RUN_NONINTERACTIVE)
     gwy.gwy_app_data_browser_add(self.container)
     self.channel_id = gwy.gwy_app_data_browser_find_data_by_title(
         self.container, "*SE*"
     )[0]
     gwy.gwy_app_data_browser_select_data_field(self.container, self.channel_id)
     self.extract_meta(gwyddion.get_meta_ids(self.container)[0])
Beispiel #3
0
    def find_channel(self, match_list):
        """Finds the right data channel within a Gwyddion container.

        Args:
            container: Gwyddion container with several data channels.
            match_list (list): Names which will be searched. e.g. topography

        Returns:
            chn_ids (list): List of channel IDs.
        """

        self.ch_ids = []
        for self._data_title in match_list:
            self._match_ch = gwy.gwy_app_data_browser_find_data_by_title(
                self.container, self._data_title)
            self.ch_ids.extend(self._match_ch)

        return self.ch_ids
Beispiel #4
0
    def return_match_ch(self, pattern, channels):
        """Returns topography channels

        Args:
            pattern: Pattern list, which identifies the desired channel.
            channels: List of channels.

        Returns:
            ch (list): Channel ids.
        """

        for pat in pattern:
            self.topo_ch = [ch for ch in channels if re.search(pat, ch)]
            if len(self.topo_ch) > 0:
                break

        return [
            gwy.gwy_app_data_browser_find_data_by_title(self.container, ch)
            for ch in self.topo_ch
        ]
Beispiel #5
0
def gwybas(filename):
    #add the gwyddion folders to the path, making sure they can be found
    import sys
    sys.path.append('C:\Program Files (x86)\Gwyddion\\bin')
    sys.path.append('C:\Program Files (x86)\Gwyddion\share\gwyddion\pygwy')

    #import gwyddion
    import gwy
    import gwyutils

    #load the file and add to data browser
    c = gwy.gwy_file_load(filename, gwy.RUN_IMMEDIATE)
    gwy.gwy_app_data_browser_add(c)

    #Set the right settings for the align_rows command
    settings = gwy.gwy_app_settings_get()

    settings['/module/linematch/direction'] = int(gwy.ORIENTATION_HORIZONTAL)
    settings['/module/linematch/do_extract'] = False
    settings['/module/linematch/do_plot'] = False
    settings[
        '/module/linematch/method'] = 0  # 0: poly, 1: median, 2: median of diff,3: modus,4: matching, 5: trimemd mean, 6: trimmed mean of diff
    settings['/module/linematch/masking'] = 2
    settings['/module/linematch/max_degree'] = 3  #Order of polynominal
    settings['/module/linematch/trim_fraction'] = 0.05

    #print the datafield ID's corresponding to the different channels of the AFM, such as height, phase and error, usually the first one (0) is the height
    # print gwy.gwy_app_data_browser_get_data_ids(c)

    #itterate over the different datafield ID's/AFM channels, and do processing on them
    for datafield_id in gwy.gwy_app_data_browser_get_data_ids(c):
        # datafield = c['/%d/data' % datafield_id]

        #set the color range to automatic with tials cut off (corresponding to number 2)
        c['/%d/base/range-type' % datafield_id] = 2

        #select the datafield_ID/AFM channel to process
        gwy.gwy_app_data_browser_select_data_field(c, datafield_id)

        #level the plane
        gwy.gwy_process_func_run("level", c, gwy.RUN_IMMEDIATE)

        #align the rows, with settings chosen above line 19-25
        gwy.gwy_process_func_run("align_rows", c, gwy.RUN_IMMEDIATE)

        #remove scars a couple of times (button bashing)
        gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)
        gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)
        gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)
        gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)
        gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)

        #fix lowest point to zero
        gwy.gwy_process_func_run('fix_zero', c, gwy.RUN_IMMEDIATE)

    #define new file names, I chose to simply add the wanted extention to the original filename
    newname = filename + '.gwy'
    newname2 = filename + '.jpg'

    #find the ID/Channel corresponding to the height, of this one a JPG will be created, .gwy will contain all channels
    ids = gwy.gwy_app_data_browser_find_data_by_title(c, 'Height')
    gwy.gwy_app_data_browser_select_data_field(c, ids[0])
    gwy.gwy_file_save(c, newname, gwy.RUN_NONINTERACTIVE)
    gwy.gwy_file_save(c, newname2, gwy.RUN_NONINTERACTIVE)

    #remove the current container, makes room for the next file
    gwy.gwy_app_data_browser_remove(c)
    if file_name[-4:] == '.spm':
        full_file_name = directory + file_name

        try:
            spm_file_list.append(full_file_name)
        except NameError:
            spm_file_list = [full_file_name]

for image in spm_file_list:

    #Load the image and make it current in the gwyddion data browser
    gwy_rawdata = gwy.gwy_file_load(image, gwy.RUN_NONINTERACTIVE)
    gwy.gwy_app_data_browser_add(gwy_rawdata)

    #Find the id locators for the height
    height_ids = gwy.gwy_app_data_browser_find_data_by_title(
        gwy_rawdata, 'Height')

    #Get the settings for each function from the saved settings file (~/.gwyddion/settings)
    s = gwy.gwy_app_settings_get()
    configureGwySettings(s)

    #Process both trace and retrace
    for i in height_ids:

        ###
        ### CORRECTING THE DATA WITH GWYDDION FUNCTIONS
        ### HAVE INCREDIBLY UNPLEASANT LOOKING EDITING OF SETTINGS TO DO FOR EACH FUNCTION
        ### PROBABLY A NEATER WAY TO DO THIS BUT CBA TO LOOK FOR IT NOW
        ### COPIED THE SETTINGS FROM THE ~/.gwyddion/settings file
        ###