Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85153583
test_surface.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 27, 03:42
Size
2 KB
Mime Type
text/x-python
Expires
Sun, Sep 29, 03:42 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21064233
Attached To
rTAMAAS tamaas
test_surface.py
View Options
# -*- coding: utf-8 -*-
# @file
# @section LICENSE
#
# Copyright (©) 2016-19 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
Log In to Comment