snpl.afm module¶
I/O interface utilities for AFM (atomic force microscope) images.
- class snpl.afm.GwyddionSimpleField(fp=None)[source]¶
- Bases: - object- Read/write interface for Gwyddion Simple Field format. - See http://gwyddion.net/documentation/user-guide-en/gsf.html for specifications. - Parameters:
- fp – Source file (path or file-like object). If None, create an empty object. 
 - h¶
- header. - “XRes”: pixel number along the x axis. 
- “YRes”: pixel number along the y axis. 
- “XReal”: real length of the image along the x axis (in meter). 
- “YReal”: real length of the image along the y axis (in meter). 
- “XOffset”: offset to the x coordinates. 
- “YOffset”: offset to the y coordinates. 
- “Title”: title string. 
- “XYUnits”: string describing the unit. (usually m (meter)). 
- “ZUnits”: string describing the unit. (usually m (meter)). 
 - Type:
- dict 
 
 - x¶
- 1-d array of the x-coordinates along x axis. - Type:
- numpy.ndarray 
 
 - y¶
- 1-d array of the y-coordinates along y axis. - Type:
- numpy.ndarray 
 
 - zmat¶
- 2-d array of the z data (height, phase angle, etc) - Type:
- numpy.ndarray 
 
 - xmat¶
- 2-d array of the x coordinates. - Type:
- numpy.ndarray 
 
 - ymat¶
- 2-d array of the y coordinates. - Type:
- numpy.ndarray 
 
 - path¶
- path to the source file, if any. - Type:
- str 
 
 - Example - >>> d = afm.GwyddionSimpleField("test.gsf") >>> pyplot.pcolormesh(d.xmat, d.ymat, d.zmat, shading="nearest") >>> pyplot.show() >>> d.save("save_test.gsf") 
- snpl.afm.load_xq(fp, ztype='auto')[source]¶
- Loads a .xqdx or .xqpx files from Hitachi AFM. - Parameters:
- fp – file path or file-like object. The object must be in the binary read mode. 
- ztype – type of the z axis. if “auto”, it is inferred from the extension. - .xqdx= height,- .xqpx= phase. Or it can be either of “topography” or “phase”.
 
- Returns:
- a - GwyddionSimpleFieldobject.
 - Examples - >>> d = afm.load_xq("test_afm_raw_data_file.xqdx") >>> pyplot.pcolormesh(d.xmat, d.ymat, d.zmat, shading="nearest") >>> pyplot.show() >>> d.save("test_afm_saved_data.gjf") # save it as a Gwyddion Simple Field format 
- snpl.afm.row_background_polynomial(xmat, zmat, polydeg=1, mask=None)[source]¶
- Calculates polynomial background for each scan row. - Performs polynomial fitting to each row in - zmat. This is one of the basic method to correct for the mismatch between scan lines and the curving of each scan line.- Parameters:
- xmat (numpy.ndarray) – 2-d array of x coordinates. 
- zmat (numpy.ndarray) – 2-d array of z coordinates (e.g., height) 
- polydeg (int) – Degree of polynomial used in the fitting. Must be a non-negative integer. Defaults to 1. 
- mask (numpy.ndarray or None) – A 2-d truth array specifying which points to use in the fitting. If None, all points will be used. Defaults to None. 
 
- Returns:
- A 2-d - numpy.ndarraywith the same size as- zmat.
 - Examples - >>> d = afm.load_xq("test_data.xqdx") >>> xmat = d.xmat*1e6 >>> ymat = d.ymat*1e6 >>> zmat = d.zmat*1e6 >>> >>> mask = np.logical_or(xmat < 2.5, 16.0 < xmat) # mask a part of the image >>> zbmat = afm.row_background_polynomial(xmat, zmat, polydeg=1, mask=mask) >>> >>> pyplot.gca().set_aspect("equal") >>> pyplot.pcolormesh(xmat, ymat, zmat - zbmat) >>> pyplot.colorbar() >>> pyplot.show()