def load_data(filename, debug = "true"):
	""" loads files into gwyydion container and returns it"""
	if debug:
		print("in load_data with arguments {0}".format(filename))
	mode = gwy.RUN_NONINTERACTIVE
	c=gwy.gwy_file_load(filename,mode)
	return 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])
Exemple #3
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 #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)
from os import listdir, mkdir, getcwd
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))
Exemple #7
0
            if chunk:  # filter out keep-alive new chunks
                f.write(chunk)
                #f.flush() commented by recommendation from J.F.Sebastian
    return local_filename


# Main program
## Create output folder
output_folder = "."
try:
    os.makedirs("%s/" % (output_folder))
    os.chdir(output_folder)
except OSError as exc:
    pass

## Download file
#rawFile = download_file("http://127.0.0.1:8080%s" % path)
rawFile = path

## Gywddion load
print("Gwyddion loading %s" % rawFile)
import gwy
container = gwy.gwy_file_load(rawFile, gwy.RUN_NONINTERACTIVE)

## Save to gwy
gwy.gwy_file_save(container, "%s/data.gwy" % (output_folder),
                  gwy.RUN_NONINTERACTIVE)

print("%s/" % (output_folder))
sys.exit()
Exemple #8
0
 def load_data(self,data_path):
     self.current_data = data_path
     self.param['full_path'] = self.current_data
     self.c = gwy.gwy_file_load(self.current_data,gwy.RUN_NONINTERACTIVE)
     data_field_id = 0
     data_field = '/' + str(data_field_id) + '/data'
     self.d = self.c[data_field]
     meta_field = '/' + str(data_field_id) + '/meta'
     meta = self.c[meta_field]
     # Extract bias and current, if needed
     ################ For Nanonis sxm file ################
     if meta.contains_by_name('Bias'):
         bias = meta['Bias']
         self.param['bias'] = bias.split(' ')[0]
         self.param['bu'] = bias.split(' ')[-1]
     if meta.contains_by_name('Z controller Setpoint'):
         current = meta['Z controller Setpoint']
         current, cu = current.split(' ')
         self.param['current'] = float(current) * 1e12
         self.param['cu'] = 'pA'
     ################ For Createc file ##################
     if meta.contains_by_name('Biasvolt[mV]'):
         self.param['bias'] = meta['Biasvolt[mV]']
         self.param['bu'] = 'mV'
     if meta.contains_by_name('Current[A]'):
         self.param['current'] = float(meta['Current[A]']) * 1e12
         self.param['cu'] = 'pA'
     ############### For Omicron file ###################
     if self.c.contains_by_name('/meta/eepa/GapVoltageControl.Voltage'):
         self.param['bias'] = self.c['/meta/eepa/GapVoltageControl.Voltage']
     if self.c.contains_by_name('/meta/eepa/Regulator.Setpoint_1'):
         self.param['current'] = self.c['/meta/eepa/Regulator.Setpoint_1']*1e9
     #current_bias = 'pm'
     ##### IF WANT TO SUPPORT MORE FORMATS, ADD PROCESSING CODE HERE #####
     self.param['width'] = self.d.get_xreal() * 1e9
     self.param['height'] = self.d.get_yreal() * 1e9
     self.param['width_real'] = self.param['width'] * self.param['ratio']
     self.param['height_real'] = self.param['height'] * self.param['ratio']
     self.param['xyu'] = 'nm'
     self.param['w_dim'] = self.d.get_xres()
     self.param['h_dim'] = self.d.get_yres()
     # Setting the channels
     c_keys = self.c.keys_by_name()
     count = 0
     channels = []
     for item in c_keys:
         if re.search(r'title',item):
             count = count + 1
     print count
     for i in range(0,count,2):
         title = '/' + str(i) + '/data/title'
         temp_title = self.c[title]
         if self.param['full_path'][-3:] == 'sxm':
             temp_channel, temp_directions = temp_title.split(' ')
             temp_directions = temp_directions[1:-1]
         elif self.param['full_path'][-6:] =='Z_mtrx':
             print temp_title, temp_title.strip().split(' ')
             temp_channel = temp_title.strip().split(' ')[-1]
             print temp_channel
         else:
             temp_channel = temp_title
         #print temp_directions, i
         channels.append(temp_channel)
     self.param['channels'] = channels
Exemple #9
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)
    gwy_rawdata['/%d/mask' % channel_ID] = binary_mask


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