Skip to content

Commit

Permalink
Check azimuthal gap in validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
acarapetis committed Jul 28, 2022
1 parent ee813da commit e2f4958
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
14 changes: 9 additions & 5 deletions tests/add_validation_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
import logging
import os
import sys
from os.path import join, abspath, dirname
from os.path import join, abspath
from typing import Optional

from obspy import UTCDateTime

from eatws_skip_client import SKIP, Event
from wphase import runwphase
from validation_cases import result_keys, DATA_DIR, add_case

# get event data from production SKIP
skip = SKIP('https://skip.eatws.net',
secret_id='skip-prod-readonly-access')

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def prepare_test_case(evid, inventory=None, waveforms=None):
event: Event = skip.get_event(evid)
datadir = abspath(DATA_DIR)
event: Optional[Event] = skip.get_event(evid)
if not event:
raise ValueError('%s not found in SKIP' % evid)
eqinfo = dict(
Expand All @@ -29,6 +30,7 @@ def prepare_test_case(evid, inventory=None, waveforms=None):
dep=event.depth_km,
time=UTCDateTime(event.event_time),
)
datadir = abspath(DATA_DIR)
result = runwphase(
server='IRIS',
eqinfo=eqinfo,
Expand All @@ -37,15 +39,17 @@ def prepare_test_case(evid, inventory=None, waveforms=None):
inventory=inventory,
waveforms=waveforms,
)
MT = result['MomentTensor']
MT = result.MomentTensor
case = dict(
id=event.id,
lat=event.latitude,
lon=event.longitude,
dep=event.depth_km,
time=event.event_time,
_expected_results={k: MT[k] for k in result_keys},
_expected_results={k: getattr(MT, k) for k in result_keys},
)
if result.QualityParams is not None:
case["_expected_results"]["azimuthal_gap"] = result.QualityParams.azimuthal_gap
print(json.dumps(case, indent=4))
add_case(case)
print("This test case has been added to validation_cases.json and test-datasets/.")
Expand Down
5 changes: 5 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_validity_from_fixed_datasets(event, tmpdir):
inventory, waveforms = get_dataset(event)

eqinfo = Event(
id=event["id"],
latitude=event["lat"],
longitude=event["lon"],
depth=event["dep"],
Expand All @@ -39,3 +40,7 @@ def test_validity_from_fixed_datasets(event, tmpdir):
EXP = event['_expected_results']
assert_allclose([EXP[k] for k in result_keys],
[getattr(MT, k) for k in result_keys])
ag = EXP.get("azimuthal_gap")
if ag is not None:
assert r.QualityParams is not None
assert_allclose(r.QualityParams.azimuthal_gap, ag)
2 changes: 1 addition & 1 deletion tests/validation_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

logger = logging.getLogger("wphase.tests")

DATASETS_URL = 'https://github.com/GeoscienceAustralia/ga-wphase/releases/download/v0.1/ga-wphase-test-datasets.tar.gz'
DATASETS_URL = 'https://github.com/GeoscienceAustralia/ga-wphase/releases/download/v0.3/ga-wphase-test-datasets.tar.gz'
DATA_DIR = 'test-datasets'
TESTS_DIR = dirname(__file__)

Expand Down

0 comments on commit e2f4958

Please sign in to comment.