A Gwyddion native data file (GWY) consists of a tree-like structure of serialized objects. Generally, these objects can be of various kind and contain other embedded objects (hence the tree-like structure). It can be instructive to play with gwydump, a simple file structure visualizer available in on the project's web, for a while and examine the contents of various files. If you plan to read and/or write GWY files in independent software, have also a look at libgwyfile, a small standalone embeddable library for GWY file handling. Third party implementations of the file format also exist (with varying capabilities), for instance Python gwyfile.
This file format description specifies in fact two different things that are sometimes useful to distinguish:
In should be usually quite clear where we talk about the generic format and where about specific Gwyddion data objects (occassionally it will be explicitly noted). We will start with the physical file structure.
The file header consists of four bytes (magic number) with the
values of ASCII characters GWYP
.
This is the new file format; an older version of file format with magic
header GWYO
also exists. It will not be discussed
here as it is mostly extinct nowadays.
The rest of a Gwyddion file consists of a serialized GwyContainer object that contains all the data. This top-level object is stored exactly the same way as any other object, that is as described in the next section.
A generic GWY file can have some other object as the top-level object.
An object consists of three parts (in the following order):
NUL
-terminated string of
ASCII characters. In a Gwyddion file this is the type name in
GObject type system. Generally the name should be a valid C
identifier.
The number of components is not explicitly stored. It is implied by the total serialized data size. The components take together exactly this many bytes; there is no padding.
Each component consists of three parts (in the following order):
NUL
-terminated UTF-8 encoded
string.
Components are often called items in libgwyfile and Gwyddion libraries.
Component size is not explicitly represented – it is implied by its type and contents. Skipping an unknown (or uninteresting) component while reading a GWY file can be done by first reading the component name and type. Then there are several possibilities:
NUL
character.
NUL
) according to the
array length.
Available atomic data types are listed in following table:
Type | Character | Size | Note |
---|---|---|---|
boolean | b | 1 byte | Zero is false, nonzero (normally 1) is true. |
character | c | 1 byte | |
32bit integer | i | 4 bytes | |
64bit integer | q | 8 bytes | |
double | d | 8 bytes | Finite IEEE 754 double precision floating point number, i.e. files must not contain infinities and not-a-numbers. |
string | s | variable |
NUL -terminated and UTF-8 encoded.
|
object | o | variable | Nested serialized object as described above. |
Each atomic type except boolean has its array counterpart. The type character of array types is the same as of the corresponding atomic type, except it is uppercase. An array is stored as unsigned 32bit integer representing the number of items, followed by the item values. The number of items must be positive; empty arrays are not stored. Array data types are listed in following table:
Type | Character | Note |
---|---|---|
array of characters | C |
In general neither NUL -terminated
nor UTF-8 encoded (s is used for text
strings).
|
array of 32bit integers | I | |
array of 64bit integers | Q | |
array of doubles | D | |
array of strings | S | |
array of objects | O | Uppercase Oh, not zero. |
GwyContainer is a general dictionary-like data object that can hold arbitrary components of arbitrary types. This permits incorporating unforeseen data structures into GWY files in a relatively sane manner.
The names (keys) of data objects in a GwyContainer representing a Gwyddion
GWY file strongly resemble UNIX file names, i.e. they have the form of
/
-separated paths and form a sort of tree-like structure.
For instance the title of the first image, numbered 0, is stored under the key
/0/data/title
. Note that some data or information is found under keys
that may not seem logical; the reason is usually historical.
The following sections describe the organisation of interesting data and information in the top-level GwyContainer. The list is not necessarily complete. However, since all data items in the file specify consistently their name, type and size in bytes it is always possible to skip unknown data types or data you are not interested in and extract only the desired data items.
The following table summarises the common keys of image-related data in the top-level container for image number 0. For other images, the number 0 has to be replaced with the corresponding image number. Note that images are often numbered sequentially, starting from 0. However, they can have any numbers and the set of images numbers does not have to be contiguous.
Key | Type | Meaning |
---|---|---|
/0/data | GwyDataField | Channel data. |
/0/data/title | string | Channel title, as shown in the data browser. |
/0/data/visible | boolean | Whether the image should be displayed in a window when the file is loaded. |
/0/data/realsquare | boolean | Whether the image should be displayed as Physically square (as opposed to Pixelwise square). |
/0/base/palette | string | Name of the false color gradient used to display the image. |
/0/base/range-type | 32bit integer | False color mapping type (as set by the Color range tool), the value is from GwyLayerBasicRangeType enum. |
/0/base/min | double | Minimum value for user-set display range. |
/0/base/max | double | Maximum value for user-set display range. |
/0/mask | GwyDataField | Mask data. The pixel dimensions of this data field must match those of the image data. |
/0/mask/red | double | Red component of the mask color. |
/0/mask/green | double | Green component of the mask color. |
/0/mask/blue | double | Blue component of the mask color. |
/0/mask/alpha | double | Alpha (opacity) component of the mask color. |
/0/show | GwyDataField | Presentation data. The pixel dimensions of this data field must match those of the image data. |
/0/meta | GwyContainer | Channel metadata. The keys are directly the names as displayed in the metadata browser and the string values are the values. |
/0/data/log | GwyStringList |
Channel log as a list of string log entries. They have the format
.
|
/0/select/ | a GwySelection subclass |
Selection data. Each kind of selection has (usually) a different object
type and is stored under a different name; the specific name
foo is the same as shown in the
selection manager.
|
Channels are represented as GwyDataField objects. The components of a GwyDataField are summarised in the following table:
Component | Type | Meaning |
---|---|---|
xres | 32bit integer | Horizontal size in pixels. |
yres | 32bit integer | Vertical size in pixels. |
xreal | double | Horizontal dimension in physical units. |
yreal | double | Vertical dimension in physical units. |
xoff | double | Horizontal offset of the top-left corner in physical units. It usually occurs only if non-zero. |
yoff | double | Vertical offset of the top-left corner in physical units. It usually occurs only if non-zero. |
si_unit_xy | GwySIUnit | Unit of lateral dimensions. |
si_unit_z | GwySIUnit | Unit of data values. |
data | array of doubles |
Field data, stored as a flat array of size
xres × yres ,
from top to bottom and from left to right.
|
The following table summarises the common keys of graph-related data in the top-level container for graph number 1. For other graphs, the number 1 has to be replaced with the corresponding graph number. Note that graphs are often numbered sequentially, starting from 1, however, they can have any numbers positive and the set of graph numbers does not have to be contiguous. The number 0 in the prefix of graph keys is a historical relic that does not mean anything and it is always 0.
Key | Type | Meaning |
---|---|---|
/0/graph/graph/1 | GwyGraphModel | Graph model object data. |
/0/graph/graph/1/visible | boolean | Whether the graph should be displayed in a window when the file is loaded. |
Graphs are represented as GwyGraphModel objects. The components of a GwyGraphModel are summarised in the following table:
Component | Type | Meaning |
---|---|---|
curves | array of GwyGraphCurveModels | Individual graph curves. |
title | string | Graph title as displayed in the data browser. |
x_unit | GwySIUnit | Unit of the abscissa. |
y_unit | GwySIUnit | Unit of the ordinate. |
top_label | string | Label on the top axis. |
bottom_label | string | Label on the bottom axis. |
left_label | string | Label on the left axis. |
right_label | string | Label on the right axis. |
x_is_logarithmic | boolean | Whether the abscissa has a logarithmic scale. |
y_is_logarithmic | boolean | Whether the ordinate has a logarithmic scale. |
x_min | double | User-set minimum value of the abscissa. |
x_min_set | boolean | Whether user-set minimum value of the abscissa should be used (otherwise the range is determined automatically). |
x_max | double | User-set maximum value of the abscissa. |
x_max_set | boolean | Whether user-set maximum value of the abscissa should be used (otherwise the range is determined automatically). |
y_min | double | User-set minimum value of the ordinate. |
y_min_set | boolean | Whether user-set minimum value of the ordinate should be used (otherwise the range is determined automatically). |
y_max | double | User-set maximum value of the ordinate. |
y_max_set | boolean | Whether user-set maximum value of the ordinate should be used (otherwise the range is determined automatically). |
grid-type | 32bit integer | Type of grid shown. The value is from GwyGraphGridType enum. |
label.has_frame | boolean | Whether the graph key has a frame. |
label.frame_thickness | 32bit integer | Width of graph key frame. |
label.reverse | boolean | Whether to reverse the graph key. |
label.visible | boolean | Whether the graph key is visible. |
label.position | 32bit integer | The position (corner) where the graph key is places. The value is from GwyGraphLabelPosition enum. |
Graph curves are represented as GwyGraphCurveModel objects. The components of a GwyGraphCurveModel are summarised in the following table:
Component | Type | Meaning |
---|---|---|
xdata | array of doubles |
Abscissa points. The number of points must match ydata .
|
ydata | array of doubles |
Ordinate points. The number of points must match xdata .
|
description | string | Curve description (name). |
type | 32bit integer | Curve mode (points, lines, etc.) The value is from GwyGraphCurveType enum. |
color.red | double | Red component of the curve color. |
color.green | double | Green component of the curve color. |
color.blue | double | Blue component of the curve color. |
point_type | 32bit integer | Type of symbols representing data points. The value is from GwyGraphPointType enum. |
point_size | 32bit integer | Size of symbols representing data points. |
line_type | 32bit integer | Type of lines connecting data points. The value is from GwyGraphLineType enum. |
line_size | 32bit integer | Width of lines connecting data points. |
The following table summarises the common keys of spectra-related data in the top-level container for spectra set number 0. For other spectra, the number 0 has to be replaced with the corresponding spectra set number. Note that spectra sets are often numbered sequentially, starting from 0, however, they can have any numbers and the set of spectra set numbers does not have to be contiguous.
Key | Type | Meaning |
---|---|---|
/sps/0 | GwySpectra | Spectra data. |
Sets of spectra of one kind are represented as GwySpectra objects. The components of a GwySpectra are summarised in the following table:
Component | Type | Meaning |
---|---|---|
title | string | Spectra title as displayed in the data browser. |
si_unit_xy | GwySIUnit | Unit of spectrum position coordinates. |
coords | array of doubles |
Coordinates of points where the spectra were taken, in physical units.
Each spectrum takes two items: for the horizontal and vertical coordinate.
The number of coordinates must match the number of curves in
data .
|
data | array of GwyDataLines | Individual spectra curves. |
selected | array of 32bit integers | Indices of selected spectra curves. |
Individual curves in spectra are represented as GwyDataLine objects. The GwyDataLine object is a one-dimensional counterpart of GwyDataField and is used also for other regular one-dimensional data. The components of a GwyDataLine are summarised in the following table:
Component | Type | Meaning |
---|---|---|
res | 32bit integer | Number of data points. |
real | double | Length in physical units. |
off | double | Offset of the begining in physical units. It usually occurs only if non-zero. |
si_unit_x | GwySIUnit | Unit of abscissa. |
si_unit_y | GwySIUnit | Unit of data values. |
data | array of doubles |
Line data, stored as an array of res ,
from left to right.
|
The following table summarises the common keys of volume-related data in the top-level container for volume data number 0. For other volume data, the number 0 has to be replaced with the corresponding volume data number. Note that volume data are often numbered sequentially, starting from 0, however, they can have any numbers and the set of volume data numbers does not have to be contiguous.
Key | Type | Meaning |
---|---|---|
/brick/0 | GwyBrick | Volume data. |
/brick/0/preview | GwyDataField | Two-dimensional data shown when the volume data are displayed in a window. |
/brick/0/title | string | Volume data title, as shown in the data browser. |
/brick/0/visible | boolean | Whether the volume data should be displayed in a window when the file is loaded. |
/brick/0/preview/palette | string | Name of the false color gradient used to display the preview data. |
/brick/0/meta | GwyContainer | Volume data metadata. The keys are directly the names as displayed in the metadata browser and the string values are the values. |
/brick/0/log | GwyStringList |
Volume data log as a list of string log entries. They have the format
.
|
Volume data are represented as GwyBrick objects. The components of a GwyBrick are summarised in the following table:
Component | Type | Meaning |
---|---|---|
xres | 32bit integer | Horizontal size in pixels. |
yres | 32bit integer | Vertical size in pixels. |
zres | 32bit integer | Depth (number of levels) in pixels. |
xreal | double | Horizontal dimension in physical units. |
yreal | double | Vertical dimension in physical units. |
zreal | double | Depthwise dimension in physical units. |
xoff | double | Horizontal offset of the top-left corner in physical units. It usually occurs only if non-zero. |
yoff | double | Vertical offset of the top-left corner in physical units. It usually occurs only if non-zero. |
zoff | double | Depthwise offset of the top-left corner in physical units. It usually occurs only if non-zero. |
si_unit_x | GwySIUnit | Unit of horizontal lateral dimensions. |
si_unit_y | GwySIUnit | Unit of vertical lateral dimensions. |
si_unit_z | GwySIUnit | Unit of depthwise dimensions. |
si_unit_w | GwySIUnit | Unit of data values. |
data | array of doubles |
Field data, stored as a flat array of size
xres × yres × zres ,
from the zeroth to the last plane, top to bottom and from left to right.
|
calibration | GwyDataLine |
Calibration of the z axis to
represent non-linear sampling in this dimension.
The number of points must be equal to zres .
This component is present only if non-linear sampling is
used.
|
The following table summarises the common keys of XYZ-related data in the top-level container for XYZ data number 0. For other XYZ data, the number 0 has to be replaced with the corresponding XYZ data number. Note that XYZ data are often numbered sequentially, starting from 0, however, they can have any numbers and the set of XYZ data numbers does not have to be contiguous.
Key | Type | Meaning |
---|---|---|
/xyz/0 | GwySurface | XYZ data. |
/xyz/0/preview | GwyDataField | Regularised preview shown when the XYZ data are displayed in a window. Note that although XYZ previews are stored in GWY files, they are commonly re-created and updated when the data are displayed so it is rarely useful to add them when you are writing a GWY file. |
/xyz/0/title | string | XYZ data title, as shown in the data browser. |
/xyz/0/visible | boolean | Whether the XYZ data should be displayed in a window when the file is loaded. |
/xyz/0/preview/palette | string | Name of the false color gradient used to display the preview data. |
/xyz/0/meta | GwyContainer | XYZ data metadata. The keys are directly the names as displayed in the metadata browser and the string values are the values. |
/xyz/0/log | GwyStringList |
Volume data log as a list of string log entries. They have the format
.
|
XYZ data are represented as GwySurface objects. The components of a GwySurface are summarised in the following table:
Component | Type | Meaning |
---|---|---|
si_unit_xy | GwySIUnit | Unit of horizontal lateral dimensions. |
si_unit_z | GwySIUnit | Unit of data values. |
data | array of doubles |
XYZ data, stored as a flat array of whose size is a multiple of 3.
Each XYZ triplet is stored together, leading to the following data order:
x ₀, y ₀, z ₀,
x ₁, y ₁, z ₁,
x ₂, y ₂, z ₂,
etc.
|
The following table summarises the common keys of curve map related data in the top-level container for XYZ data number 0. For other curve map data, the number 0 has to be replaced with the corresponding curve map data number. Note that curve map data are often numbered sequentially, starting from 0, however, they can have any numbers and the set of curve map data numbers does not have to be contiguous.
Key | Type | Meaning |
---|---|---|
/lawn/0 | GwyLawn | Curve map data. |
/lawn/0/preview | GwyDataField | Image preview shown when the curve map data are displayed in a window. |
/lawn/0/title | string | XYZ data title, as shown in the data browser. |
/lawn/0/visible | boolean | Whether the XYZ data should be displayed in a window when the file is loaded. |
/lawn/0/preview/palette | string | Name of the false color gradient used to display the preview data. |
/lawn/0/preview/realsquare | boolean | Whether the image should be displayed as Physically square (as opposed to Pixelwise square). |
/lawn/0/meta | GwyContainer | Curve map data metadata. The keys are directly the names as displayed in the metadata browser and the string values are the values. |
/lawn/0/log | GwyStringList |
Volume data log as a list of string log entries. They have the format
.
|
Curve map data are represented as GwyLawn objects. The components of a GwyLawn are summarised in the following table:
Component | Type | Meaning |
---|---|---|
xres | 32bit integer | Horizontal size in pixels. |
yres | 32bit integer | Vertical size in pixels. |
ncurves | 32bit integer | The number of curves in each pixel. |
curvelengths | array of 32bit integers |
Array of size xres × yres
containing the sample counts in each pixel (in the usual image
order). The sample counts can be zero.
|
xreal | double | Horizontal dimension in physical units. |
yreal | double | Vertical dimension in physical units. |
xoff | double | Horizontal offset of the top-left corner in physical units. It usually occurs only if non-zero. |
yoff | double | Vertical offset of the top-left corner in physical units. It usually occurs only if non-zero. |
si_unit_xy | GwySIUnit | Unit of horizontal lateral dimensions. |
si_units_curves | array of GwySIUnit objects |
Units of curve data, as an array with ncurves items.
|
data | array of doubles |
Concatenated curve data, stored as a flat array of whose size is a multiple of
the number of curves (ncurves ). The data are stored in the usual
image order. First all curves in the top left pixel are concatenated and stored,
then the all curves in the next pixel, etc. Reading and writing this item requires
the use of curvelengths for correct indexing.
|
curve_labels | array of strings |
Optional array with ncurves items specifying curve labels.
|
nsegments | 32bit integer |
The number of segments each curve is split into – if curves are segmented. In such
case item segments should specify the segmentation.
|
segments | array of 32bit integers |
Segmentation of each curve, given as start and end indices of
each segment in each curve. The array size is
xres × yres × 2nsegments .
Segments do not have to exactly partition the curve; they can overlap or leave holes.
|
segment_labels | array of strings |
Optional array with nsegments items specifying segment labels.
|
The main GwyContainer contains also items that do not pertain to any specific channel, graph or other data type.
Key | Type | Meaning |
---|---|---|
/filename | string | The name of file the GwyContainer is currently associated with. If it was saved to a file then the item contains the corresponding file name. Otherwise it contains the name of file from which the data were loaded or imported. It may also be unset, for instance for newly created synthetic data. |
The components of a GwySIUnit are summarised in the following table:
Component | Type | Meaning |
---|---|---|
unitstr | string |
Textual representation of the unit, e.g. "A"
or "m^-1" (as base SI unit, prefixes are ignored).
|
The components of a GwySelection are summarised in the following table. Some selection types can have other data members; refer to the documentation of specific selection classes for how to interpret the data.
Component | Type | Meaning |
---|---|---|
max | 32bit integer |
Maximum number of objects the selection can hold (this is the number
set by gwy_selection_set_max_objects() ).
|
data | array of doubles | Selection data. The number of items that form one selection object is determined by the selection type. |
The components of a GwyStringList are summarised in the following table. Note that if GwyStringLists are used to represent logs, the strings have a specific structure described above.