Consider an atomic force microscope scan with a raised particle near one edge and a background that slopes across the frame. Making the picture easier to read could mean changing its colours, excluding the particle from a background fit, or subtracting a fitted plane. Those operations have different consequences. Gwyddion makes the distinction visible in its architecture: the numerical surface, its presentation and the selected regions occupy separate places in the data model.[1][5]
Gwyddion is free software for scanning probe microscopy analysis. Its place outside a single instrument vendor's software is well established: microscopist Peter Eaton includes it in his independent survey of third-party SPM analysis tools.[2] This walkthrough follows the documented Gwyddion 2.x objects and operations. The project is also developing a 3.x line with changes to file representation and masks, so the internal names below belong to that stated scope.[1]
A surface arrives with dimensions
Gwyddion's file-loading modules translate instrument formats into its own structures. Automatic detection examines file contents rather than trusting extensions: names such as .dat and .img are shared by unrelated formats. Once imported, the native .gwy format can preserve channels, masks, selections and other properties together.[4]
For a two-dimensional channel, the central object is GwyDataField. It holds a double-precision array, pixel counts xres and yres, physical dimensions xreal and yreal, and separate units for lateral coordinates and measured values. A raster therefore carries more than pixel brightness: it also describes how far apart samples are and what their numbers mean.[5]
The surrounding GwyContainer provides named locations. For channel zero, /0/data holds the numerical field, /0/mask the selected pixels, and /0/show an optional presentation. The palette and display range have their own keys. The separation gives a developer inspecting a saved file a concrete question: did an operation change the measured values, the selected population, or only what the window displays?[5]
More contrast, same measurements
The Color Range tool changes the mapping from values to colours. Its Fixed mode lets the user choose a range; values beyond that range receive the end colours. Adaptive mapping distributes colours nonlinearly, making small variations in relatively flat areas easier to see. Neither operation modifies the numerical field.[6]
In the imagined scan, a tall particle might consume much of a linear colour range. Adjusting the display can reveal texture in the surrounding surface without removing the particle or lowering its recorded height. This is a viewing decision. Comparing screenshots without their colour scales could consequently suggest a physical difference that the underlying measurements do not contain.
A presentation goes further: it can show shading or highlighted edges over the data. Calculations still use the channel's underlying numerical field. Here, “underlying” means its current values, including any processing already applied; it does not mean an untouched acquisition secretly survives every edit.[7]
There is also a subtle cost to this separation. Presentations do not automatically refresh when the data change. A convincing shaded surface can therefore outlive the values from which it was made. Removing or regenerating the presentation is part of checking what the image now represents.[7]
Decide which surface defines the plane
Plane Level fits a plane and subtracts it from the data. If a mask exists, the fit can include its pixels, exclude them, or ignore the mask. For the particle on a tilted substrate, excluding the particle can make the surrounding substrate determine the fitted background.[8]
That example assumes the substrate is the intended reference. If the raised feature belongs to the surface being characterised, excluding it changes the scientific question. The mask records a set of pixels; the analyst supplies the reason those pixels should count differently.
The library exposes the two stages explicitly. gwydatafieldfitplane() estimates coefficients, while gwydatafieldplanelevel() subtracts a plane from the field. A masked fitting function supplies control over the samples used in estimation. Exclusion from the fit does not protect a pixel from the subsequent whole-field subtraction. The particle's height values are corrected against the same fitted background as its surroundings.[9]
More flexible backgrounds require more judgment. Polynomial subtraction can follow curvature, but the manual warns that higher degrees can suppress real surface waviness and alter the resulting statistics. A smoother-looking result is insufficient evidence that the correction was appropriate.[8]
Roughness belongs to a selected, processed surface
Gwyddion's statistical tools calculate S_q, the root-mean-square deviation from mean height, and S_a, the mean absolute deviation. The measured region matters: the Statistical Quantities tool can use the full field or a selected rectangle, and many statistical operations support masks.[10]
In our example, the particle-inclusive surface and the exposed substrate answer different roughness questions. A number should travel with that distinction. So should the processing history: subtracting tilt or curvature can change the distribution whose roughness is being reported.
A useful counterexample keeps the reasoning honest. Fix Zero and Zero Mean Value add a constant to every height.[8] For an unchanged set of pixels, such a shift leaves deviations from the mean unchanged, so it leaves these two roughness measures unchanged. That follows from their definitions; shifting the height origin is not equivalent to removing a slope.[10]
The statistical guide also warns that scan-line levelling can bias estimates. The practical lesson is specific: record the region and correction method before comparing values. Agreement between two exported pictures cannot establish agreement between two measurement procedures.[10]
Preserve the work behind the image
A .gwy file retains structures that ordinary image exports leave behind. Gwyddion recommends its native format for processed data because other exports generally preserve only a subset, often the active image without masks and presentations.[4] An exported illustration serves a report; the analysis file lets a colleague inspect the choices that produced it.
The processing log helps that inspection. It stores operation names, parameters and times with the data, and can be viewed or exported. But the manual explicitly limits its role: complex or interactive operations may not be reconstructible from their entries, logging can be disabled, and logs can be cleared. It is useful working history, not a complete audit record.[11]
For a laboratory using this workflow, the sensible handoff includes the original instrument file, the processed .gwy file and a short explanation of the mask and corrections. That recommendation follows from the storage and logging limits above.[4][11] Gwyddion gives the colleague somewhere to look: past the attractive surface picture, into the numerical field and the decisions that changed it.
Sources
- Gwyddion project homepage — project purpose, open-source status and dated notices distinguishing the 2.x and 3.x development lines; consulted November 10, 2026.
- Peter Eaton, “SPM Software,” AFMHelp — independent survey of third-party microscopy analysis software, including Gwyddion; used for context.
- AAMonitor96, “AFM at work,” March 8, 2021 — original photograph and description, Wikimedia Commons, CC BY-SA 3.0.
- Gwyddion user guide, “Managing Files” — import detection, native storage and limits of other export formats.
- Gwyddion user guide, “Format of Gwyddion Files” — GwyContainer keys and the GwyDataField representation used in Gwyddion 2.x.
- Gwyddion user guide, “False Color Mapping” — Fixed and Adaptive display modes and separation from data modification.
- Gwyddion user guide, “Presentations and Masks” — calculation inputs, presentation refresh behaviour and mask interpretation.
- Gwyddion user guide, “Data Levelling and Background Subtraction” — constant offsets, plane fitting, masking and polynomial-background limits.
- Gwyddion 2 library reference, “level” — plane fitting, masked fitting and plane subtraction API functions.
- Gwyddion user guide, “Statistical Analysis” — roughness definitions, region selection, masking and levelling bias.
- Gwyddion user guide, “Logging” — saved operation history, reconstruction limits and controls for disabling or clearing logs.