Page MenuHomec4science

test_surface.py
No OneTemporary

File Metadata

Created
Fri, May 17, 17:47

test_surface.py

# -*- coding: utf-8 -*-
# @file
# @section LICENSE
#
# Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import print_function, division
import numpy as np
import tamaas as tm
import pytest
def compute_mse(values, mean):
return np.mean((values - mean)**2)
@pytest.fixture(scope="module",
params=[tm.SurfaceGeneratorFilter2D,
tm.SurfaceGeneratorRandomPhase2D])
def isopowerlaw(tamaas_fixture, request):
iso = tm.Isopowerlaw2D()
iso.q0 = 16
iso.q1 = 32
iso.q2 = 64
iso.hurst = 0.8
N = 128
sg = request.param()
sg.setSpectrum(iso)
sg.setSizes([N, N])
analytical_stats = {
"rms_heights": iso.rmsHeights(),
"rms_slopes_spectral": iso.rmsSlopes(),
"moments": iso.moments(),
"alpha": iso.alpha()
}
return sg, analytical_stats
def test_surface_statistics(isopowerlaw):
sg, analytical_stats = isopowerlaw
realizations = 1000
stats = {k: [] for k in analytical_stats}
for i in range(realizations):
sg.random_seed = i
s = sg.buildSurface()
stats['rms_heights'].append(
np.sqrt(np.mean(s**2)))
stats['rms_slopes_spectral'].append(
tm.Statistics2D.computeSpectralRMSSlope(s))
stats['moments'].append(tm.Statistics2D.computeMoments(s))
# Testing only the more reliable measures
for key in ['rms_heights', 'rms_slopes_spectral']:
mu = np.mean(stats[key])
error = np.abs(mu - analytical_stats[key]) / analytical_stats[key]
assert error < 3e-3

Event Timeline