From e2f4958c93b13bb0bffeb211ab1f32cae3bfbd06 Mon Sep 17 00:00:00 2001 From: Anthony Carapetis Date: Thu, 28 Jul 2022 14:20:20 +1000 Subject: [PATCH] Check azimuthal gap in validation test --- tests/add_validation_case.py | 14 +++++++++----- tests/test_validation.py | 5 +++++ tests/validation_cases.py | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/add_validation_case.py b/tests/add_validation_case.py index 32c2c91..42dd2a0 100755 --- a/tests/add_validation_case.py +++ b/tests/add_validation_case.py @@ -4,7 +4,8 @@ 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 @@ -12,14 +13,14 @@ 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( @@ -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, @@ -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/.") diff --git a/tests/test_validation.py b/tests/test_validation.py index 29096ba..7b8591a 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -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"], @@ -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) diff --git a/tests/validation_cases.py b/tests/validation_cases.py index 7fb482b..c5eed54 100644 --- a/tests/validation_cases.py +++ b/tests/validation_cases.py @@ -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__)