Commit 1667b18a authored by Matthias Rüster's avatar Matthias Rüster
Browse files

Tests: Also check POI data outputs

parent ca3be63f
Pipeline #20874 passed with stages
in 4 minutes and 22 seconds
......@@ -39,7 +39,8 @@ run_tests:
before_script:
- apt-get update
- DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
- DEBIAN_FRONTEND=noninteractive apt-get install -y python3 build-essential autoconf gdal-bin
- DEBIAN_FRONTEND=noninteractive apt-get install -y python3 python3-pip build-essential autoconf gdal-bin
- pip3 install -r "${TESTS_DIR}/requirements.txt"
script:
- *compile_easywave
- cd "${TESTS_DIR}"
......
# How to run the test scripts
To run the tests the [GDAL](https://gdal.org/) tools `gdalinfo`,
`gdal_translate` and `gdal_calc.py` are required as well as Python 3 and the
[pandas](https://pandas.pydata.org/) package.
For decompressing and extracting the expected data the tools `xz` and `tar`
need to be installed.
## For CPU
Compile the `easywave` binary in the `code` directory, then run
......@@ -13,10 +19,11 @@ example achieved with the nvidia runtime environment of the docker service:
```shell
docker run --rm --runtime nvidia -e NVIDIA_VISIBLE_DEVICES=0 -it nvidia/cuda:11.0.3-devel-ubuntu20.04 /bin/bash
apt-get update && apt-get install -y autoconf g++ binutils make gdal-bin python3.8 git
apt-get update && apt-get install -y autoconf g++ binutils make gdal-bin python3.8 python3-pip git
git clone https://git.gfz-potsdam.de/id2/geoperil/easyWave.git
cd easyWave/code
./bootstrap.sh && ./configure && make
cd tests
pip3 install -r requirements.txt
./test-gpu.sh
```
......@@ -7,6 +7,7 @@ import datetime
import subprocess
import glob
import re
import pandas
sdir = os.path.dirname(os.path.abspath(sys.argv[0]))
......@@ -14,19 +15,34 @@ sdir = os.path.dirname(os.path.abspath(sys.argv[0]))
easywave = '@../src/easywave'
test_scenarios = [
# fault with slip, length and width:
{
'name': 'fault with slip, length and width',
'grid': '@../../data/grids/e2r4Asean.grd',
'fault': '@../../data/faults/BengkuluSept2007.flt',
# directory which contains the expected outputs
'expected': '@BengkuluSept2007',
},
# fault with magnitude:
{
'name': 'fault with magnitude',
'grid': '@../../data/grids/e2r4Asean.grd',
'fault': '@../../data/faults/MentawaiOct2010.flt',
'expected': '@MentawaiOct2010',
},
{
'name': 'fault with slip, length, width and including POIs',
'grid': '@../../data/grids/e2r4Asean.grd',
'fault': '@../../data/faults/BengkuluSept2007.flt',
'pois': '@../../data/pois/poiIndonesia.poi',
# directory which contains the expected outputs
'expected': '@BengkuluSept2007',
},
{
'name': 'fault with magnitude and including POIs',
'grid': '@../../data/grids/e2r4Asean.grd',
'fault': '@../../data/faults/MentawaiOct2010.flt',
'pois': '@../../data/pois/poiIndonesia.poi',
'expected': '@MentawaiOct2010',
},
]
......@@ -59,9 +75,8 @@ def compareResults(expected, computed):
path.append(computed)
for i in range(0, 2):
files.append(glob.glob(path[i] + '/*.ssh'))
files[i] += glob.glob(path[i] + '/*.sshmax')
# files[i] += glob.glob(path[i] + '/*.time')
files.append(glob.glob(path[i] + '/eWave.2D.*.ssh'))
files[i].append(path[i] + '/eWave.2D.sshmax')
for f in files[0]:
# go through expected files
......@@ -111,13 +126,132 @@ def compareResults(expected, computed):
success = False
if success:
print('\033[92mSuccessful:\033[0m %f\n' % maxDiff)
print('\033[92mSuccessful:\033[0m %f' % maxDiff)
else:
print('\033[91mFailed:\033[0m %f\n' % maxDiff)
print('\033[91mFailed:\033[0m %f' % maxDiff)
return success
def comparePoiSsh(expected, computed):
success = True
tolerance = 0.02
exp_data = pandas.read_csv(expected, delim_whitespace=True)
comp_data = pandas.read_csv(computed, delim_whitespace=True)
if exp_data.shape != comp_data.shape:
print('POI ssh file ' + computed + ' has not the expected shape.')
return False
diff = exp_data.sub(comp_data)
diff_abs = diff.abs()
maxDiff = diff_abs.max().max()
if maxDiff > tolerance:
print('Computed results differ too much from expected results')
success = False
if success:
print('\033[92mSuccessful:\033[0m %f' % maxDiff)
else:
print('\033[91mFailed:\033[0m %f' % maxDiff)
return success
def comparePoiSummary(expected, computed):
success = True
tolerance = 0.02
exp_data = pandas.read_csv(expected, delim_whitespace=True)
comp_data = pandas.read_csv(computed, delim_whitespace=True)
if exp_data.shape != comp_data.shape:
print('POI summary file ' + computed + ' has not the expected shape.')
return False
c1 = exp_data.columns[1]
c2 = exp_data.columns[2]
comp_c1 = comp_data.columns[1]
comp_c2 = comp_data.columns[2]
if c1 != comp_c1 or c2 != comp_c2:
print(
'Columns in POI summary file ' + computed + ' are not as expected.'
)
return False
diff_c1 = exp_data[c1].sub(comp_data[c1])
diff_c2 = exp_data[c2].sub(comp_data[c2])
abs_c1 = diff_c1.abs()
abs_c2 = diff_c2.abs()
maxDiff = max(abs_c1.max(), abs_c2.max())
if maxDiff > tolerance:
print('Computed results differ too much from expected results')
success = False
if success:
print('\033[92mSuccessful:\033[0m %f' % maxDiff)
else:
print('\033[91mFailed:\033[0m %f' % maxDiff)
return success
def comparePoiResults(expected, computed):
path = []
files = [[], []]
success = True
ret = True
path.append(expected)
path.append(computed)
for i in range(0, 2):
files[i].append(path[i] + '/eWave.poi.ssh')
files[i].append(path[i] + '/eWave.poi.summary')
for f in files[0]:
# go through expected files
basef = os.path.basename(f)
fnext = path[1] + '/' + basef
if not os.path.isfile(f):
print('Expected file ' + f + ' does not exist')
ret = False
continue
if not os.path.isfile(fnext):
print('Expected computed file ' + fnext + ' does not exist')
ret = False
continue
if fnext in files[1]:
# we found the expected file in the computed results
files[1].remove(fnext)
print('Comparing POI file %s with %s' % (f, fnext))
if fnext.endswith('.ssh'):
success = comparePoiSsh(f, fnext)
elif fnext.endswith('.summary'):
success = comparePoiSummary(f, fnext)
else:
print('Unknown how to compare the POI files, not implemented')
success = False
if not success:
ret = False
return ret
if __name__ == '__main__':
easywave = easywave.replace('@', sdir + '/')
ret = 0
......@@ -127,9 +261,16 @@ if __name__ == '__main__':
easywave = easywave + ' ' + sys.argv[1]
for sc in test_scenarios:
print('\nTesting: ' + sc['name'])
grid = sc['grid'].replace('@', sdir + '/')
fault = sc['fault'].replace('@', sdir + '/')
args = '-grid ' + grid + ' -source ' + fault + ' -time 300'
if sc.get('pois'):
args += ' -poi ' + sc.get('pois').replace('@', sdir + '/') \
+ ' -poi_dt_out 30 -poi_search_dist 20'
cmd = []
cmd.append(easywave + ' ' + args)
tmpdir = start(cmd[-1])
......@@ -137,12 +278,18 @@ if __name__ == '__main__':
expected = sc['expected'].replace('@', sdir + '/')
successful = compareResults(expected, tmpdir)
if not successful:
ret = 1
if sc.get('pois'):
successful = comparePoiResults(expected, tmpdir)
if not successful:
ret = 1
if ret == 1:
print('Some tests failed.')
print('\nSome tests failed.')
else:
print('All tests passed successfully.')
print('\nAll tests passed successfully.')
sys.exit(ret)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment