Exemple #1
0
 def update_image(self,widget,data):
     #pass
     #self.channel_id = self.combobox_channels.get_active()
     gwy.gwy_app_data_browser_add(self.c)
     self.load_data()
     self.d.data_changed()
     #print "update", self.togglebutton_level.get_active()
     self.local_c.set_object_by_name(self.data_id_str+"data", self.d)
     if re.search(r'Z', self.channel_str):
         #print self.channel_str
         self.gradient_key = 'Gwyddion.net'
     elif re.search(r'Frequency', self.channel_str):
         self.gradient_key = 'Gray'
     self.local_c.set_string_by_name(self.data_id_str+"base/palette", self.gradient_key)
     self.local_c.set_int32_by_name(self.data_id_str+"base/range-type", 1)#gwy.LAYER_BASIC_RANGE_FIXED
     self.local_c.set_double_by_name(self.data_id_str+"base/min", float(self.data_min + self.scale_min_current/100*self.data_dif))
     self.local_c.set_double_by_name(self.data_id_str+"base/max", float(self.data_min + self.scale_max_current/100*self.data_dif))
     self.local_c[self.data_id_str+"data"].data_changed()
     #print self.local_c[self.data_id_str+"base/min"],self.data_id_str+"base/min"
     #print self.data_min + self.scale_min_current/100*self.data_dif,self.data_min + self.scale_max_current/100*self.data_dif
     layer = gwy.LayerBasic()
     layer.set_data_key(self.data_id_str+"data")
     layer.set_gradient_key(self.data_id_str+"base/palette")
     layer.set_range_type_key(self.data_id_str+"base")
     layer.set_min_max_key(self.data_id_str+"base")
     self.view.set_data_prefix(self.data_id_str+"data")
     self.view.set_base_layer(layer)
     #self.combobox_files.grab_focus()
     gwy.gwy_app_data_browser_remove(self.c)
Exemple #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])
 def update_image(self,widget,data):
     #pass
     for container,gwydata,view in zip(self.containers,self.gwydatas,self.views):
         self.c = gwydata.get_container()
         self.load_data(0,0)
         gwy.gwy_app_data_browser_add(self.c)
         self.d_origin = self.c[self.data_id_str + 'data']
         #self.d = self.d_origin.duplicate()
         if self.d_origin:
             self.c.set_object_by_name(self.data_id_str + 'data',self.d_origin)
         else:
             self.d_origin = self.c[self.data_id_str + 'data']
         gwy.gwy_app_data_browser_select_data_field(self.c,0)
         #if self.togglebutton_level.get_active():
         #    gwy.gwy_app_data_browser_select_data_field(self.c, 0)
         #    gwy.gwy_process_func_run("level", self.c, gwy.RUN_IMMEDIATE)
         self.d = self.c[self.data_id_str + 'data']
         d_process = self.d.duplicate()
         #self.data_min = self.d.get_min()
         #self.data_max = self.d.get_max()
         #self. data_dif = self.data_max - self.data_min
         #self.scale_min_current = self.scale_min.get_value()
         #self.scale_max_current = self.scale_max.get_value()
         #bottom = self.data_min + self.scale_min_current/100*self.data_dif
         #top = self.data_min + self.scale_max_current/100*self.data_dif
         #d_process.clamp(bottom, top)
         #self.d.clamp(bottom, top)
         self.d = d_process
         self.d.data_changed()
         #print "update", self.togglebutton_level.get_active()
         container.set_object_by_name(self.data_id_str+"data", self.d)
         #if re.search(r'Z', self.channel_str):
             #print self.channel_str
         #    self.gradient_key = 'Julio'
         self.gradient_key = 'Julio'
         #elif re.search(r'Frequency', self.channel_str):
         #    self.gradient_key = 'Gray'
         container.set_string_by_name(self.data_id_str+"base/palette", self.gradient_key)
         container.set_int32_by_name(self.data_id_str+"base/range-type", 1)#gwy.LAYER_BASIC_RANGE_FIXED
         #self.local_c.set_double_by_name(self.data_id_str+"base/min", float(self.data_min + self.scale_min_current/100*self.data_dif))
         #self.local_c.set_double_by_name(self.data_id_str+"base/max", float(self.data_min + self.scale_max_current/100*self.data_dif))
         container[self.data_id_str+"data"].data_changed()
         #print self.local_c[self.data_id_str+"base/min"],self.data_id_str+"base/min"
         #print self.data_min + self.scale_min_current/100*self.data_dif,self.data_min + self.scale_max_current/100*self.data_dif
         layer = gwy.LayerBasic()
         layer.set_data_key(self.data_id_str+"data")
         layer.set_gradient_key(self.data_id_str+"base/palette")
         layer.set_range_type_key(self.data_id_str+"base")
         layer.set_min_max_key(self.data_id_str+"base")
         view.set_data_prefix(self.data_id_str+"data")
         view.set_base_layer(layer)
         #self.combobox_files.grab_focus()
         gwy.gwy_app_data_browser_remove(self.c)
Exemple #4
0
 def inner(int_id):  # pylint: disable=missing-docstring
     new_container = gwy.Container()
     gwy.gwy_app_data_browser_add(new_container)
     gwy.gwy_app_data_browser_copy_channel(con, int_id, new_container)
     file_name = str(m_id) + "_" + str(int_id) + ".gwy"
     file_out = os.path.join(dir_path, file_name)
     meta_id = get_meta_ids(new_container)[0]
     time_extract = new_container[meta_id]["Date"]
     time_reformat = datetime.strptime(time_extract, "%Y-%m-%d %H:%M:%S")
     gwy.gwy_app_file_write(new_container, file_out)
     time_sec = time.mktime(time_reformat.timetuple())
     os.utime(file_out, (time_sec, time_sec))
     return file_out
def run(container, mode):
    data_field_id = gwy.gwy_app_data_browser_get_current(gwy.APP_DATA_FIELD_ID)
    data_field = container[gwy.gwy_app_get_data_key_for_id(data_field_id)]

    new_container = gwy.Container()
    gwy.gwy_app_data_browser_add(new_container)

    # Need to populate container with dummy data, otherwise
    # gwy_app_data_browser_copy_channel crashes.
    dummy_id = gwy.gwy_app_data_browser_add_data_field(
        data_field, new_container, False
    )
    new_id = gwy.gwy_app_data_browser_copy_channel(
        container, data_field_id, new_container
    )
    gwy.gwy_app_data_browser_select_data_field(new_container, new_id)

    # Get rid of dummy reference.
    new_container.remove_by_prefix('/{}/'.format(dummy_id))
Exemple #6
0
 def __init__(self, m_file, **kwargs):
     self.surface = None
     self.tip = None
     Data.__init__(self, m_file, **kwargs)
     self.set_settings()
     self.container = gwy.gwy_file_load(self.m_file, gwy.RUN_NONINTERACTIVE)
     gwy.gwy_app_data_browser_add(self.container)
     self.img_topo_fwd = None
     self.img_topo_bwd = None
     self.topo_fwd_ch = self.return_topo_fwd_ch()
     self.topo_bwd_ch = self.return_topo_bwd_ch()
     self.size = None
     self.rotation = None
     self.line_time = None
     self.bias = None
     self.current = None
     self.xoffset = None
     self.yoffset = None
     self.scan_duration = None
     self.extract_meta(gwyddion.get_meta_ids(self.container)[0])
def convertAFM(filenamex, saveImg = True):
    filename = os.path.abspath(filenamex)
    # print 'Loading ', filename
    for i in range(100):
        c = gwy.gwy_file_load(filename, gwy.RUN_NONINTERACTIVE)
        if c != None:
            break
        time.sleep(0.1)
    if c == None:
        return None, None
    gwy.gwy_app_data_browser_add(c)
    for key in c.keys_by_name():
        if re.match(r'^/0/data$', key):
            field = c[key]
            xres = field.get_xres()
            yres = field.get_yres()
            xreal = (field.get_xreal()*1e6)/2.0
            yreal = (field.get_yreal()*1e6)/2.0
            weights = gwy.DataLine(xres, 1.0, True)
            weights.part_fill(0, xres//3, 1.0)
            filtered = gwy.DataField.new_alike(field, False)
            field.fft_filter_1d(filtered, weights,
                                gwy.ORIENTATION_HORIZONTAL,
                                gwy.INTERPOLATION_ROUND)
            degrees = [1,1]
            field.subtract_polynom(degrees[0],degrees[1],field.fit_polynom(degrees[0],degrees[1]))
            field.data_changed()
            data = gwyutils.data_field_data_as_array(field)
            data = np.array(data)[::,::-1]

            imfilename = False
            if saveImg:
                filename = os.path.abspath('D:/lithography/')
                imfilename = str(filename)+"/current.png"
                print (imfilename)
                res = saveAFMimg(data, imfilename )
                writeImageMacro( imfilename , [-xreal, -yreal, xreal, yreal])
    info = {'width':xreal*2, 'height':yreal*2, 'imname': imfilename}
    gwy.gwy_app_data_browser_remove(c)
    return data, info
Exemple #8
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)
from os.path import isfile, join
cwd = '/home/june/pygwy/cont'
Files_To_Open = [ f for f in listdir(cwd) if isfile(join(cwd,f)) ]
#mkdir(join(cwd,'Processed'))
filename_save = getcwd().split('/')[-1]
# Export PNG with scalebar
s = gwy.gwy_app_settings_get()
s['/module/pixmap/title_type'] = 0
s['/module/pixmap/ztype'] = 0
s['/module/pixmap/xytype'] = 0
s['/module/pixmap/draw_maskkey'] = False
# ... (*lots* of possible settings, see ~/.gwyddion/settings)

#Load first file to use as Merged file
Cont_Dest = gwy.gwy_file_load(join(cwd,Files_To_Open[0]), RUN_NONINTERACTIVE)
gwy.gwy_app_data_browser_add(Cont_Dest)
#Make Visible
Cont_Dest.set_boolean_by_name('/0/data/visible', 1)

#File Merge
#First Container
DataFields = gwyutils.get_data_fields_dir(Cont_Dest)
for key in DataFields.keys():
	title = Cont_Dest.get_string_by_name(key+"/title")
	if (title == 'Amplitude') : Cont_Dest.remove_by_prefix('/'+key.split('/')[1]+'/')
	Cont_Dest.set_string_by_name(key+'/title', title+'.'+Files_To_Open[0])

#Rest of Containers
for filename in Files_To_Open[1:] :
	print (orgfile, join(cwd,filename))
	Cont_Source = gwy.gwy_file_load(join(cwd,filename), RUN_NONINTERACTIVE)
## Create output folder
output_folder = "."
try:
    os.makedirs("%s/" % (output_folder))
except OSError as exc:
    pass

## Download file
raw_file = path

# Load gwy file
print("Gwyddion loading '%s'" % raw_file)
container = gwy.gwy_file_load(raw_file, gwy.RUN_NONINTERACTIVE)

# Add to data browser to inspect
gwy.gwy_app_data_browser_add(container)

# Save metadata to image.json
image_folder = output_folder
image_meta = {}
image_meta["type"] = "inspect-gwy"
meta = container["/0/meta"]
for entry in meta.keys_by_name():
    image_meta[entry] = meta[entry]
    #print('%s:%s' % (entry,meta[entry]))
file = open("%s/image.json" % (image_folder), "w" )
json.dump(image_meta,file)
file.close()

# List all channels
ids = gwy.gwy_app_data_browser_get_data_ids(container)
Exemple #11
0
def getdata(filename):
    # Open file and add data to browser
    data = gwy.gwy_file_load(filename, gwy.RUN_NONINTERACTIVE)
    # Add data to browser
    gwy.gwy_app_data_browser_add(data)
    return data
def runbatch(root, cwd, pdr, pngexp, ratio):
    # Export PNG with scalebar
    s = gwy.gwy_app_settings_get()
    s['/module/pixmap/title_type'] = 0
    s['/module/pixmap/ztype'] = 0
    s['/module/pixmap/xytype'] = 0
    s['/module/pixmap/draw_maskkey'] = False
    # ... (*lots* of possible settings, see ~/.gwyddion/settings)

    Files_To_Open = [ f for f in listdir(cwd) if isfile(join(cwd,f)) ]

    try:
        mkdir(join(cwd,'Processed'))
    except Exception as sym:
        print ('Already Exist')
        Tobe_Saved = join(cwd, 'Processed')
        filename_save = cwd.split('/')[-1]
        print (Files_To_Open)
    #Load first file to use as Merged file
    for filename in Files_To_Open:
        print(filename)
        try:
            Temp = gwy.gwy_file_load(join(cwd,filename), RUN_NONINTERACTIVE)
            print(type(Temp))
            if type(Temp) == gwy.Container :
                print('right type')
                Cont_Dest = Temp
                Files_To_Open.remove(filename)
                break
            Files_To_Open.remove(filename)
            print('loadedbutnot')
        except Exception as sym:
            print('except')
            print ("not proper file"+str(sym)+"\n")
            continue
	#Add into current browser and Make Visible on display
    gwy.gwy_app_data_browser_add(Cont_Dest)
    Cont_Dest.set_boolean_by_name('/0/data/visible', 1)
    print (Files_To_Open)
    #File Merge
    #First Container
    DataFields = gwyutils.get_data_fields_dir(Cont_Dest)
    for key in DataFields.keys():
        title = Cont_Dest.get_string_by_name(key+"/title")
        if (title == 'Amplitude') : Cont_Dest.remove_by_prefix('/'+key.split('/')[1]+'/')
        Cont_Dest.set_string_by_name(key+'/title', title+'.'+Files_To_Open[0])

	#Rest of Containers
    for filename in Files_To_Open :
        #print (orgfile, join(cwd,filename))
        try:
            Temp_Source = gwy.gwy_file_load(join(cwd,filename), RUN_NONINTERACTIVE)
            if type(Temp_Source) == gwy.Container:
                Cont_Source = Temp_Source
                pass
            else:
                continue
        except Exception as sym:
            print ("not proper file"+sym+"\n")
            continue
        DataFields = gwyutils.get_data_fields_dir(Cont_Source)
        for key in DataFields.keys():
            ID = key.split('/')[1]
            title = Cont_Source.get_string_by_name(key+"/title")
            if (title == 'Height') :
                Cont_Source.set_string_by_name(key+'/title', title+'.'+filename)
                gwy.gwy_app_data_browser_copy_channel(Cont_Source, int(ID), Cont_Dest)
                print (key, title)
            gwy_app_data_browser_remove(Cont_Source)
            del Cont_Source
            print (gc.collect())


	#Change Palette, Flatten, Correct line, Remove Scars, Change Scale
    DataFields = gwyutils.get_data_fields_dir(Cont_Dest)
    for key in DataFields.keys():
        ID = key.split('/')[1]
        title = Cont_Dest.get_string_by_name(key+"/title")
        print (title+'\n')
        # Subtract polynomial background
        coeffs = DataFields[key].fit_polynom(3, 3)
        DataFields[key].subtract_polynom(3, 3, coeffs)
        DataFields[key].data_changed()
        #Get X Y scale
        si = {'x' : 'um' , 'y' : 'um'}
        size_x = DataFields[key].get_xreal()*1000000
        if (size_x < 1.0):
            size_x = size_x * 1000
            si['x'] = 'nm'
        size_y = DataFields[key].get_yreal()*1000000
        if (size_y < 1.0):
            size_y = size_y * 1000
            si['y'] = 'nm'
        scale = str(size_x)+si['x']+'by'+str(size_y)+si['y']
        title = title + '_'+ scale
        # Line and scar correction (run module functions)
        gwy.gwy_app_data_browser_select_data_field(Cont_Dest, int(ID))
        gwy.gwy_process_func_run("line_correct_median", Cont_Dest, gwy.RUN_IMMEDIATE)
        gwy.gwy_process_func_run("scars_remove", Cont_Dest, gwy.RUN_IMMEDIATE)
        gwy.gwy_process_func_run("fix_zero", Cont_Dest, gwy.RUN_IMMEDIATE)
        #Get Color Type
        colorr = Cont_Dest.get_int32_by_name('/'+ID+'/base/range-type')
        #Change_Color Palette
        Cont_Dest.set_string_by_name('/'+ID+'/base/palette', 'Gold')
        
        
        #Get Height Distribution and get Percentile color set range
        #Get CDH
        histogram = gwy.DataLine(1, 1, False)
        DataFields[key].cdh(histogram, 512)
        data = histogram.get_data()
        #Get Percentile Range	
        
        Data_Range = DataFields[key].get_min_max()
        Histogram_pct = [(float(index))/512 for index, value in enumerate(data) if (data[index] >= ratio[1] and data[index-1] <= ratio[1]) or (data[index] <= ratio[0] and data[index+1] >= ratio[0])]
        Range = Data_Range[1]-Data_Range[0]
        Color_Range = {'min': Data_Range[0]+Range*Histogram_pct[0], 'max':Data_Range[0]+Range*Histogram_pct[1]}
        Cont_Dest.set_int32_by_name('/0/base/range-type' , 1)
        Cont_Dest.set_double_by_name('/0/base/min', Color_Range['min'])
        Cont_Dest.set_double_by_name('/0/base/max', Color_Range['max'])
        
        
        #Change Color Range into (Full:0, Manual:1, Auto:2, Adaptive:3)
        Cont_Dest.set_int32_by_name('/'+ID+'/base/range-type', 2)
        print (title)
        gwy.gwy_file_save(Cont_Dest, Tobe_Saved+'/'+str(title)+'%d.png' % int(ID), gwy.RUN_NONINTERACTIVE)
        Cont_Dest.set_boolean_by_name('/'+ID+'/data/visible', 0)
    gwy.gwy_file_save(Cont_Dest,Tobe_Saved+'/'+filename_save+'.gwy', gwy.RUN_NONINTERACTIVE)
    gwy_app_data_browser_remove(Cont_Dest)

for file_name in file_list:
    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