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)
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)
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
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 array import array # output_file = open("%s/channel/%02d/binary" % (output_folder,i), 'wb') # float_array = array('d', data) # float_array.tofile(output_file) # output_file.close() # Save into JSON ch_meta["data"] = data # Save pickle #file = open("%s/channel/%02d/image.p" % (output_folder,i), "w" ) #pickle.dump(data,file) #file.close() # Save binary data #data = data_field.get_data() # Save PNG thumbnail gwy.gwy_file_save(container, "%s/channel/%02d/image.png" % (output_folder,i), gwy.RUN_NONINTERACTIVE) # Save metadata file = open("%s/channel/%02d/channel.json" % (output_folder,i), "w" ) json.dump(ch_meta,file) file.close() gwy.gwy_app_data_browser_remove(container) print("%s" % (output_folder)) sys.exit()
### SAVING THE MODIFIED FILES AS TIFFS ### #Save all files as tiffs - this puts them all with the raw data annoyingly #Could put in some os commands to move everything around afterwards #Use blue and gold colour scheme with a sensible and consistent colour scale maximum_disp_value = gwy_rawdata.set_int32_by_name( "/" + str(i) + "/base/range-type", int(1)) minimum_disp_value = gwy_rawdata.set_double_by_name( "/" + str(i) + "/base/min", float(1e-9)) maximum_disp_value = gwy_rawdata.set_double_by_name( "/" + str(i) + "/base/max", float(20e-9)) palette = gwy_rawdata.set_string_by_name( "/" + str(i) + "/base/palette", "BlueandGold") if i == 4: #save trace and retrace seperately - presumably can do this more elegantly saved_filename = str(image[:-4] + '_trace.tiff') gwy.gwy_file_save(gwy_rawdata, saved_filename, gwy.RUN_NONINTERACTIVE) else: saved_filename = str(image[:-4] + '_retrace.tiff') gwy.gwy_file_save(gwy_rawdata, saved_filename, gwy.RUN_NONINTERACTIVE) gwy.gwy_app_data_browser_remove( gwy_rawdata) #close the file once we've finished with it