+++
title = "Real space"
weight = 14
+++

# Real-space visualization of rough interfaces

The roughness defined for a sample can be turned into real-space
height maps, useful e.g. for direct visual comparison with
atomic-force-microscopy (AFM) images or as a sanity check on the
chosen autocorrelation, cross-correlation, and height-distribution
parameters.

```python
RoughnessMap(n_pts_x, n_pts_y, Lx, Ly, sample, i_layer[, seed])
```

generates one random rough surface, iteratively adjusted to
reproduce the given spectrum and height statistics. Algorithm by
Pérez-Ràfols & Almqvist,
[Tribology International 131, 591-604
(2019)](https://doi.org/10.1016/j.triboint.2018.11.020).

For multilayers, rough interfaces can also be generated together:

```python
maps = ba.RoughnessMap.generateInterfaceMaps(
    n_pts_x, n_pts_y, Lx, Ly, sample, interface_indices[, seed])
```

The result is a NumPy array with shape
`(len(interface_indices), n_pts_y, n_pts_x)`. For example,
`interface_indices=[1, 2]` returns the maps for interfaces 1 and 2 in
that order.

Unlike two independent `RoughnessMap(...).generate()` calls, the
stack generator uses the roughness cross-correlation model when one is
defined. The lowest rough interface is generated by the regular
single-interface IAAFT algorithm. Interfaces above it are then built
bottom-up from the nearest generated rough interface below: each
Fourier component is split into the inherited part prescribed by the
adjacent cross-spectrum and an orthogonal independent residual with
the remaining auto-spectrum. This makes replicated long-wavelength
features visible while keeping the one-interface generator unchanged.

The requested interface indices only select maps from the result; the
whole rough stack is generated internally. Therefore
`generateInterfaceMaps(..., [i], seed)` is not generally equivalent to
an independent `RoughnessMap(..., i, seed).generate()` call for an
upper interface. The height distribution is adjusted by IAAFT only for
the lowest generated rough interface. Upper interfaces are constrained
by the target auto-spectrum and adjacent cross-spectrum; their height
statistics are therefore an approximation inherited from the spectral
construction.

{{< figscg src="/img/auto/varia/RoughSurface.png" width="700" class="center">}}

{{< show-ex file="varia/RoughSurface.py" >}}
