-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test client request with live server
- Loading branch information
Showing
12 changed files
with
125 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from os.path import dirname, abspath, join, isdir, isfile | ||
import pandas as pd | ||
|
||
from egsim.api.data.client.snippets.get_egsim_predictions import get_egsim_predictions | ||
from egsim.api.data.client.snippets.get_egsim_residuals import get_egsim_residuals | ||
from egsim.api.urls import PREDICTIONS_URL_PATH, RESIDUALS_URL_PATH | ||
|
||
test_data_dir = join(dirname(dirname(abspath(__file__))), 'data') | ||
|
||
assert isdir(test_data_dir) | ||
|
||
# these must be equal to the values provided in tests.smtk.test_create_data: | ||
models = ['CauzziEtAl2014', 'BindiEtAl2014Rjb'] | ||
imts = ['PGA', 'SA(0.032)', 'SA(0.034)'] | ||
|
||
|
||
def test_server_requests(live_server): | ||
create_predictions(live_server.url) | ||
create_residuals(live_server.url) | ||
|
||
|
||
def create_residuals(base_url): | ||
ffile_path = abspath(join(test_data_dir, | ||
'test_flatfile.csv')) | ||
with open(ffile_path) as fpt: | ||
dfr = get_egsim_residuals( | ||
models, imts, fpt, likelihood=False, | ||
base_url=f"{base_url}/{RESIDUALS_URL_PATH}" | ||
) | ||
file = join(test_data_dir, 'residuals.hdf') | ||
if isfile(file): | ||
dfr2:pd.DataFrame = pd.read_hdf(file) # noqa | ||
# dfr2 has only required columns for performance reasons, | ||
# so check those are the same: | ||
dfr = dfr[[c for c in dfr.columns if c in dfr2.columns]] | ||
# now test equality: | ||
pd.testing.assert_frame_equal( | ||
dfr, dfr2, check_exact=False, atol=0, rtol=1e-8 | ||
) | ||
|
||
|
||
def create_predictions(base_url): | ||
dfr = get_egsim_predictions( | ||
models, imts, [4, 5], [1, 10, 100], | ||
base_url=f"{base_url}/{PREDICTIONS_URL_PATH}" | ||
) | ||
file = join(test_data_dir, 'predictions.hdf') | ||
if isfile(file): | ||
dfr2 = pd.read_hdf(file) | ||
pd.testing.assert_frame_equal( | ||
dfr, dfr2, check_exact=False, atol=0, rtol=1e-3 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from os.path import dirname, abspath, join, isdir, isfile | ||
import pandas as pd | ||
from egsim.smtk import get_scenarios_predictions, get_residuals, read_flatfile | ||
|
||
test_data_dir = join(dirname(dirname(abspath(__file__))), 'data') | ||
|
||
assert isdir(test_data_dir) | ||
|
||
models = ['CauzziEtAl2014', 'BindiEtAl2014Rjb'] | ||
imts = ['PGA', 'SA(0.032)', 'SA(0.034)'] | ||
|
||
|
||
def test_create_predictions(): | ||
dfr = get_scenarios_predictions(models, imts, [4, 5], [1, 10, 100]) | ||
file = join(test_data_dir, 'predictions.hdf') | ||
if not isfile(file): | ||
dfr.to_hdf(file, key='data') | ||
else: | ||
dfr2 = pd.read_hdf(file) | ||
pd.testing.assert_frame_equal(dfr, dfr2) | ||
|
||
|
||
def test_create_residuals(): | ||
ffile = read_flatfile(join(test_data_dir, | ||
'test_flatfile.csv')) | ||
# take only the relevant columns, otherwise the file is too big: | ||
columnz = {'event_id', 'rjb', 'rrup', 'rake', 'magnitude', 'vs30', | ||
'SA(0.032)', 'SA(0.035)', 'PGA'} | ||
ffile = ffile[[c for c in ffile.columns if c in columnz]] | ||
|
||
dfr = get_residuals(models, imts, ffile, likelihood=False) | ||
file = join(test_data_dir, 'residuals.hdf') | ||
if not isfile(file): | ||
dfr.to_hdf(file, key='data') | ||
else: | ||
dfr2 = pd.read_hdf(file) | ||
pd.testing.assert_frame_equal(dfr, dfr2) |