from spym.generic import Spm_image, load_from_gsf import matplotlib.pyplot as plt import numpy as np file_name = 'wg_berk-0deg_n2_6um_000_TR.gsf' #file_name = 'BMG8-zr60cu30al10_375c_10mN_6um_000_TR.gsf' image =load_from_gsf(file_name) image.change_xy_unit('um') image.change_z_unit('nm') image = image.crop(5,5,5,5) image.center_min() X, Y, Z = image.get_xyz() r = 2. mask = np.where(X[0]**2 > r**2, 0., np.nan ) image, residual = image.line_fit(mask = mask) X, Y, Z = image.get_xyz() xlabel, ylabel, zlabel = image.get_labels() # Let's define some paths: s = np.linspace(-5., 5., 100) # A tilted line to produce a section angle0 = 55. xc = 0. yc = 0. x0 = np.cos(np.radians(angle0)) * s + xc y0 = np.sin(np.radians(angle0)) * s + yc X0, Y0, Z0 = image.interpolate(x0, y0) x1 = np.cos(np.radians(angle0 + 120.)) * s + xc y1 = np.sin(np.radians(angle0 + 120.)) * s + yc X1, Y1, Z1 = image.interpolate(x1, y1) x2 = np.cos(np.radians(angle0 - 120.)) * s + xc y2 = np.sin(np.radians(angle0 - 120.)) * s + yc
from matplotlib import cm import numpy as np file_name = 'planilux_berk_10mN_6um.gsf' # This script is intended to be used on "Gwyddion Simple File" (GSF) files. This choice is motivated by the fact that Gwyddion can open most of the proprietary files standards produced by AFM/SPM commercial devices and can then save them to the open format GSF. name = 'planilux_berk_10mN_6um.gsf' # GSF File path # GRAPHICAL SETTINGS levels = 100 # Number of levels on the color maps fs = 12. # Font size alpha = 2.5 # Cross section tilt med_filt_size = None # If the image is noisy, a median filter can be applied, put a number greater than 1 (eg. 3). cmap = cm.jet # IMAGE PREPROCESSING image = load_from_gsf(file_name) # Image loading image = image.crop( cx0=10, cx1=10, cy0=10, cy1=10 ) # Light crop in order to remove artifacts on the extremities of the scans image.change_xy_unit('um') # Setting xy units image.change_z_unit('nm') # Setting z unit xlabel, ylabel, zlabel = image.get_labels( ) # Getting labels for ploting purpose X0, Y0, Z0 = image.get_xyz() # Getting raw image data image.center_min() # Offseting to center the bottom of the indent X1, Y1, Z1 = image.get_xyz() # Getting centered image data for masking purpose R2 = X1**2 + Y1**2 # Building a mask r = min(X1.max(), -X1.min(), Y1.max(), -Y1.min()) k = .8 mask = np.where(R2 > r**2 * k**2, 1., np.nan) # Circular mask filled with 1 and NaN
from spym.generic import Spm_image, load_from_gsf import matplotlib.pyplot as plt import matplotlib import numpy as np matplotlib.rcParams['contour.negative_linestyle'] = 'solid' #file_name = 'wg_berk-0deg_n2_6um_000_TR.gsf' file_name = 'BMG8-zr60cu30al10_375c_10mN_6um_000_TR.gsf' image = load_from_gsf(file_name) image.change_xy_unit('um') image.change_z_unit('nm') X, Y, Z = image.get_xyz() xlabel, ylabel, zlabel = image.get_labels() # Translation image = image.translate(nx=30, ny=-50) levels = 10 Xr, Yr, Zr = image.get_xyz() fig = plt.figure(0) plt.clf() ax = fig.add_subplot(121) ax.set_aspect('equal') plt.title('Original') grad = plt.contourf(X, Y, Z, levels) plt.contour(X, Y, Z, levels, colors='black') cbar = plt.colorbar(grad) plt.xlabel(xlabel) plt.ylabel(ylabel) cbar.set_label(zlabel) ax = fig.add_subplot(122) ax.set_aspect('equal') plt.title('Translate')
file_name = 'planilux_berk_10mN_6um.gsf' # This script is intended to be used on "Gwyddion Simple File" (GSF) files. This choice is motivated by the fact that Gwyddion can open most of the proprietary files standards produced by AFM/SPM commercial devices and can then save them to the open format GSF. name = 'planilux_berk_10mN_6um.gsf' # GSF File path # GRAPHICAL SETTINGS levels = 100 # Number of levels on the color maps fs = 12. # Font size alpha = 2.5 # Cross section tilt med_filt_size = None # If the image is noisy, a median filter can be applied, put a number greater than 1 (eg. 3). cmap = cm.jet # IMAGE PREPROCESSING image = load_from_gsf(file_name) # Image loading image = image.crop(cx0 = 10, cx1= 10, cy0 = 10, cy1= 10) # Light crop in order to remove artifacts on the extremities of the scans image.change_xy_unit('um') # Setting xy units image.change_z_unit('nm') # Setting z unit xlabel, ylabel, zlabel = image.get_labels() # Getting labels for ploting purpose X0, Y0, Z0 = image.get_xyz() # Getting raw image data image.center_min() # Offseting to center the bottom of the indent X1, Y1, Z1 = image.get_xyz() # Getting centered image data for masking purpose R2 = X1**2 + Y1**2 # Building a mask r = min( X1.max(), -X1.min(), Y1.max(), -Y1.min()) k = .8 mask = np.where(R2 > r**2 * k**2, 1., np.nan ) # Circular mask filled with 1 and NaN image, trash = image.line_fit(mask = mask) image = image.crop(cx0 = 40, cx1= 40, cy0 = 40, cy1= 40) # Cropping to keep only the indent X, Y, Z = image.get_xyz() # Final image data contour, area = Watershed(image, angle = 2.5)
from spym.generic import load_from_gsf import numpy as np file_name = 'WG-air_10mN_001_TF.gsf' file_name = 'BMG8-zr60cu30al10_375c_10mN_6um_000_TR.gsf' image = load_from_gsf(file_name) # Load the image # Perform some operations image.change_xy_unit('um') image.change_z_unit('nm') image = image.crop(5,5,5,5) X, Y, Z = image.get_xyz() xi = X[image.get_min_position()] yi = Y[image.get_min_position()] r = 2. mask = np.where((X-xi)**2 + (Y-yi)**2 > r**2, 0., np.nan ) image, residual = image.line_fit(mask = mask) image.center_min() # Save it again image.dump2gsf(file_name.replace('.', '_linefit.'))
from spym.generic import Spm_image, load_from_gsf import matplotlib.pyplot as plt import matplotlib import numpy as np matplotlib.rcParams['contour.negative_linestyle'] = 'solid' #file_name = 'wg_berk-0deg_n2_6um_000_TR.gsf' file_name = 'BMG8-zr60cu30al10_375c_10mN_6um_000_TR.gsf' image = load_from_gsf(file_name) # Load the image image.change_xy_unit('um') image.change_z_unit('nm') xlabel, ylabel, zlabel = image.get_labels() X, Y, Z = image.get_xyz() loc = image.get_min_position() xc, yc = X[loc], Y[loc] image.set_center(xc=xc, yc=yc) X, Y, Z = image.get_xyz() image = image.rotate(angle=30., tx=0., ty=0.) levels = 10 Xr, Yr, Zr = image.get_xyz() fig = plt.figure(0) plt.clf() ax = fig.add_subplot(121) ax.set_aspect('equal') plt.title('Original') grad = plt.contourf(X, Y, Z, levels) plt.contour(X, Y, Z, levels, colors='black') cbar = plt.colorbar(grad) plt.xlabel(xlabel) plt.ylabel(ylabel) cbar.set_label(zlabel)
from spym.generic import load_from_gsf import matplotlib.pyplot as plt file_name = 'WG-air_10mN_001_TF.gsf' im = load_from_gsf(file_name) im.change_xy_unit('um') im.change_z_unit('nm') plt.figure() plt.clf() X,Y,Z = im.get_xyz() xlabel, ylabel, zlabel = im.get_labels() plt.xlabel(xlabel) plt.ylabel(ylabel) grad = plt.contourf(X,Y,Z, 100) cbar = plt.colorbar(grad) cbar.set_label(zlabel) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.gca().set_aspect('equal') plt.grid() plt.show()
from spym.generic import load_from_gsf import matplotlib.pyplot as plt file_name = 'WG-air_10mN_001_TF.gsf' im = load_from_gsf(file_name) im.change_xy_unit('um') im.change_z_unit('nm') plt.figure() plt.clf() X, Y, Z = im.get_xyz() xlabel, ylabel, zlabel = im.get_labels() plt.xlabel(xlabel) plt.ylabel(ylabel) grad = plt.contourf(X, Y, Z, 100) cbar = plt.colorbar(grad) cbar.set_label(zlabel) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.gca().set_aspect('equal') plt.grid() plt.show()