Format of Gwyddion Files

Gwyddion native data files 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.

First of all, we will describe physical file structure without regard to possible interpretation of contained data.

Byte Order

All data is stored in little-endian (also known as LSB or Intel) byte order.

File Header

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.

File Data

The rest of the file consists of a serialized GwyContainer object that contains all the data. It is stored exactly the same way as any other object, that is as described in the next section.

Object Layout

An object consists of three parts (in the following order):

  • Type name, stored as a NUL-terminated string of ASCII characters. This is the type name in GObject type system.
  • Serialized data size, stored as an unsigned 32bit integer. It does not include the size of the type name and the size of self.
  • Component list. Components are named parts of object data, each of particular data type: an atomic type, an array of atomic types, or again an object. They are stored in no particular order.

Components

Each component consists of three parts (in the following order):

  • Name, stored as a NUL-terminated string.
  • Type, stored as a single unsigned byte (character). The table of possible component types is presented below.
  • Data, stored as whatever is appropriate for a particular type.

Data Types

Available atomic data types are listed in following table:

TypeCharacterNote
booleanb Stored as a byte, zero is false, nonzero (normally 1) is true
characterc 
32bit integeri 
64bit integerq 
doubled finite IEEE 754 double precision floating point number, i.e. files must not contain infinities and not-a-numbers
strings NUL-terminated
objecto 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. Arrays are stored as unsigned 32bit array length (the number of items), followed by the item values. Array data types are listed in following table:

TypeCharacterNote
array of charactersC Not NUL-terminated
array of 32bit integersI 
array of 64bit integersQ 
array of doublesD 
array of stringsS 
array of objectsOUppercase Oh, not zero

Top-Level GwyContainer

The names (keys) of data objects in a GwyContainer representing a Gwyddion 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 channel, numbered 0, is stored under the key /0/data/title. Note some data or information is found under keys that do not seem logical; the reason is usually historical.

The following sections describe the organisation of interesting data and information in the 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.

Channels

The following table summarises the common keys of channel-related data in the top-level container for channel number 0. For other channels, the number 0 has to be replaced with the corresponding channel number. Note that channels are often numbered sequentially, starting from 0, however, they can have any numbers and the set of channels numbers does not have to be contiguous.

KeyTypeMeaning
/0/dataGwyDataField Channel data.
/0/data/titlestring Channel title, as shown in the data browser.
/0/data/visibleboolean Whether the channel should be displayed in a window when the file is loaded.
/0/base/palettestring Name of the false color gradient used to display the channel.
/0/base/range-type32bit integer False color mapping type (as set by the Color range tool), the value is from GwyLayerBasicRangeType enum.
/0/base/mindouble Minimum value for user-set display range.
/0/base/maxdouble Maximum value for user-set display range.
/0/maskGwyDataField Mask data. The pixel dimensions of this data field must match those of the channel data.
/0/mask/reddouble Red component of the mask color.
/0/mask/greendouble Green component of the mask color.
/0/mask/bluedouble Blue component of the mask color.
/0/mask/alphadouble Alpha (opacity) component of the mask color.
/0/showGwyDataField Presentation data. The pixel dimensions of this data field must match those of the channel data.
/0/metaGwyContainer Channel metadata. The keys are directly the names as displayed in the metadata browser and the string values are the values.
/0/select/fooa 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:

ComponentTypeMeaning
xres32bit integer Horizontal size in pixels.
yres32bit integer Vertical size in pixels.
xrealdouble Horizontal dimension in physical units.
yrealdouble Vertical dimension in physical units.
xoffdouble Horizontal offset of the top-left corner in physical units. It usually occurs only if non-zero.
yoffdouble Vertical offset of the top-left corner in physical units. It usually occurs only if non-zero.
si_unit_xyGwySIUnit Unit of lateral dimensions.
si_unit_zGwySIUnit Unit of data values.
dataarray of doubles Field data, stored as a flat array of size xres×yres, from top to bottom and from left to right.

Graphs

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.

KeyTypeMeaning
/0/graph/graph/1GwyGraphModel Graph model object data.
/0/graph/graph/1/visibleboolean 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:

ComponentTypeMeaning
curvesarray of GwyGraphCurveModels Individual graph curves.
titlestring Graph title as displayed in the data browser.
x_unitGwySIUnit Unit of the abscissa.
y_unitGwySIUnit Unit of the ordinate.
top_labelstring Label on the top axis.
bottom_labelstring Label on the bottom axis.
left_labelstring Label on the left axis.
right_labelstring Label on the right axis.
x_is_logarithmicboolean Whether the abscissa has a logarithmic scale.
y_is_logarithmicboolean Whether the ordinate has a logarithmic scale.
x_mindouble User-set minimum value of the abscissa.
x_min_setboolean Whether user-set minimum value of the abscissa should be used (otherwise the range is determined automatically).
x_maxdouble User-set maximum value of the abscissa.
x_max_setboolean Whether user-set maximum value of the abscissa should be used (otherwise the range is determined automatically).
y_mindouble User-set minimum value of the ordinate.
y_min_setboolean Whether user-set minimum value of the ordinate should be used (otherwise the range is determined automatically).
y_maxdouble User-set maximum value of the ordinate.
y_max_setboolean Whether user-set maximum value of the ordinate should be used (otherwise the range is determined automatically).
grid-type32bit integer Type of grid shown. The value is from GwyGraphGridType enum.
label.has_frameboolean Whether the graph key has a frame.
label.frame_thickness32bit integer Width of graph key frame.
label.reverseboolean Whether to reverse the graph key.
label.visibleboolean Whether the graph key is visible.
label.position32bit 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:

ComponentTypeMeaning
xdataarray of doubles Abscissa points. The number of point must match ydata.
ydataarray of doubles Ordinate points. The number of point must match xdata.
descriptionstring Curve description (name).
type32bit integer Curve mode (points, lines, etc.) The value is from GwyGraphCurveType enum.
color.reddouble Red component of the curve color.
color.greendouble Green component of the curve color.
color.bluedouble Blue component of the curve color.
point_type32bit integer Type of symbols representing data points. The value is from GwyGraphPointType enum.
point_size32bit integer Size of symbols representing data points.
line_type32bit integer Type of lines connecting data points. The value is from GwyGraphLineType enum.
line_size32bit integer Width of lines connecting data points.

Spectra

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.

KeyTypeMeaning
/sps/0GwySpectra Spectra data.

Sets of spectra of one kind are represented as GwySpectra objects. The components of a GwySpectra are summarised in the following table:

ComponentTypeMeaning
titlestring Spectra title as displayed in the data browser.
si_unit_xyGwySIUnit Unit of spectrum position coordinates.
coordsarray 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.
dataarray of GwyDataLines Individual spectra curves.
selectedarray of 32bit integers Indices of selected spectra curves.

Individual curves in spectra are represented as GwyDataLine objects. The components of a GwyDataLine are summarised in the following table:

ComponentTypeMeaning
res32bit integer Number of data points.
realdouble Length in physical units.
offdouble Offset of the begining in physical units. It usually occurs only if non-zero.
si_unit_xGwySIUnit Unit of abscissa.
si_unit_yGwySIUnit Unit of data values.
dataarray of doubles Line data, stored as an array of res, from left to right.

Volume data

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.

KeyTypeMeaning
/brick/0GwyBrick Volume data.
/brick/0/previewGwyDataField Two-dimensional data shown when the volume data is displayed in a window.
/brick/0/titlestring Volume data title, as shown in the data browser.
/brick/0/visibleboolean Whether the volume data should be displayed in a window when the file is loaded.
/brick/0/preview/palettestring Name of the false color gradient used to display the preview data.
/brick/0/metaGwyContainer Volume data metadata. The keys are directly the names as displayed in the metadata browser and the string values are the values.

Volume data are represented as GwyBrick objects. The components of a GwyBrick are summarised in the following table:

ComponentTypeMeaning
xres32bit integer Horizontal size in pixels.
yres32bit integer Vertical size in pixels.
zres32bit integer Depth (number of levels) in pixels.
xrealdouble Horizontal dimension in physical units.
yrealdouble Vertical dimension in physical units.
zrealdouble Depthwise dimension in physical units.
xoffdouble Horizontal offset of the top-left corner in physical units. It usually occurs only if non-zero.
yoffdouble Vertical offset of the top-left corner in physical units. It usually occurs only if non-zero.
zoffdouble Depthwise offset of the top-left corner in physical units. It usually occurs only if non-zero.
si_unit_xGwySIUnit Unit of horizontal lateral dimensions.
si_unit_yGwySIUnit Unit of vertical lateral dimensions.
si_unit_zGwySIUnit Unit of depthwise dimensions.
si_unit_wGwySIUnit Unit of data values.
dataarray 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.

Auxiliary Objects

The components of a GwySIUnit are summarised in the following table:

ComponentTypeMeaning
unitstrstring 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.

ComponentTypeMeaning
max32bit integer Maximum number of objects the selection can hold (this is the number set by gwy_selection_set_max_objects()).
dataarray of doubles Selection data. The number of items that form one selection object is determined by the selection type.