From 0cae4feaf9c1f71e0a61f9b1124aae8eada50ccd Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 5 Jun 2023 13:19:45 +0800 Subject: [PATCH 1/4] Refactor the test_meca_spec_dict_list test to the more general test_meca_spec_multiple_focalmecha test --- ...est_meca_spec_multiple_focalmecha.png.dvc} | 2 +- pygmt/tests/test_meca.py | 39 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) rename pygmt/tests/baseline/{test_meca_spec_dict_list.png.dvc => test_meca_spec_multiple_focalmecha.png.dvc} (56%) diff --git a/pygmt/tests/baseline/test_meca_spec_dict_list.png.dvc b/pygmt/tests/baseline/test_meca_spec_multiple_focalmecha.png.dvc similarity index 56% rename from pygmt/tests/baseline/test_meca_spec_dict_list.png.dvc rename to pygmt/tests/baseline/test_meca_spec_multiple_focalmecha.png.dvc index 2e4920e7356..17bd2eac2f8 100644 --- a/pygmt/tests/baseline/test_meca_spec_dict_list.png.dvc +++ b/pygmt/tests/baseline/test_meca_spec_multiple_focalmecha.png.dvc @@ -1,4 +1,4 @@ outs: - md5: 1469301865b97d4a95bdc26a89ae7df5 size: 13936 - path: test_meca_spec_dict_list.png + path: test_meca_spec_multiple_focalmecha.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 7c730c1a9e3..8e4b30bd98c 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -78,30 +78,27 @@ def test_meca_spec_single_focalmecha_file(): return fig -@pytest.mark.mpl_image_compare -def test_meca_spec_dict_list(): +@pytest.mark.mpl_image_compare(filename="test_meca_spec_multiple_focalmecha.png") +@pytest.mark.parametrize("inputtype", ["dict_mecha"]) +def test_meca_spec_multiple_focalmecha(inputtype): """ - Test supplying a dictionary containing a list of focal mechanism to the - spec parameter. + Test passing multiple focal mechanisms to the spec parameter. """ + if inputtype == "dict_mecha": + args = { + "spec": { + "strike": [330, 350], + "dip": [30, 50], + "rake": [90, 90], + "magnitude": [3, 2], + }, + "longitude": [-123.5, -124.5], + "latitude": [47.5, 48.5], + "depth": [12.0, 11.0], + } fig = Figure() - # supply focal mechanisms as a dict of lists - focal_mechanisms = { - "strike": [330, 350], - "dip": [30, 50], - "rake": [90, 90], - "magnitude": [3, 2], - } - fig.meca( - spec=focal_mechanisms, - longitude=[-123.5, -124.5], - latitude=[47.5, 48.5], - depth=[12.0, 11.0], - region=[-125, -122, 47, 49], - scale="2c", - projection="M8c", - frame=True, - ) + fig.basemap(region=[-125, -122, 47, 49], projection="M8c", frame=True) + fig.meca(scale="2c", **args) return fig From acdb8075e7978e06a01e772e89f89cddb5e90942 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 5 Jun 2023 15:51:23 +0800 Subject: [PATCH 2/4] Merge test_meca_spec_dataframe into test_meca_spec_multiple_focalmecha --- .../baseline/test_meca_spec_dataframe.png.dvc | 4 -- pygmt/tests/test_meca.py | 44 +++++++------------ 2 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 pygmt/tests/baseline/test_meca_spec_dataframe.png.dvc diff --git a/pygmt/tests/baseline/test_meca_spec_dataframe.png.dvc b/pygmt/tests/baseline/test_meca_spec_dataframe.png.dvc deleted file mode 100644 index 50e82f6ee04..00000000000 --- a/pygmt/tests/baseline/test_meca_spec_dataframe.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: b40481dd506db95c617978fe41ca9f9c - size: 4583 - path: test_meca_spec_dataframe.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 8e4b30bd98c..ed4a3676964 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -79,7 +79,7 @@ def test_meca_spec_single_focalmecha_file(): @pytest.mark.mpl_image_compare(filename="test_meca_spec_multiple_focalmecha.png") -@pytest.mark.parametrize("inputtype", ["dict_mecha"]) +@pytest.mark.parametrize("inputtype", ["dict_mecha", "dataframe"]) def test_meca_spec_multiple_focalmecha(inputtype): """ Test passing multiple focal mechanisms to the spec parameter. @@ -96,39 +96,27 @@ def test_meca_spec_multiple_focalmecha(inputtype): "latitude": [47.5, 48.5], "depth": [12.0, 11.0], } + elif inputtype == "dataframe": + args = { + "spec": pd.DataFrame( + data={ + "strike": [330, 350], + "dip": [30, 50], + "rake": [90, 90], + "magnitude": [3, 2], + "longitude": [-123.5, -124.5], + "latitude": [47.5, 48.5], + "depth": [12.0, 11.0], + }, + ) + } + fig = Figure() fig.basemap(region=[-125, -122, 47, 49], projection="M8c", frame=True) fig.meca(scale="2c", **args) return fig -@pytest.mark.mpl_image_compare -def test_meca_spec_dataframe(): - """ - Test supplying a pandas.DataFrame containing focal mechanisms and locations - to the spec parameter. - """ - - fig = Figure() - # supply focal mechanisms to meca as a dataframe - focal_mechanisms = { - "strike": [324, 353], - "dip": [20.6, 40], - "rake": [83, 90], - "magnitude": [3.4, 2.9], - "longitude": [-124, -124.4], - "latitude": [48.1, 48.2], - "depth": [12, 11.0], - } - fig.meca( - spec=pd.DataFrame(data=focal_mechanisms), - region=[-125, -122, 47, 49], - scale="2c", - projection="M14c", - ) - return fig - - @pytest.mark.mpl_image_compare def test_meca_spec_2d_array(): """ From a51ea04e90c525e8914a73e02bff9ee98139c191 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 5 Jun 2023 16:24:04 +0800 Subject: [PATCH 3/4] Merge test_meca_spec_2d_array into test_meca_spec_multiple_focalmecha --- .../baseline/test_meca_spec_2d_array.png.dvc | 4 -- pygmt/tests/test_meca.py | 42 +++++-------------- 2 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 pygmt/tests/baseline/test_meca_spec_2d_array.png.dvc diff --git a/pygmt/tests/baseline/test_meca_spec_2d_array.png.dvc b/pygmt/tests/baseline/test_meca_spec_2d_array.png.dvc deleted file mode 100644 index d0a8f4fc2b2..00000000000 --- a/pygmt/tests/baseline/test_meca_spec_2d_array.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: b3e49cd999ed234d679f359d7b4fac28 - size: 5424 - path: test_meca_spec_2d_array.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index ed4a3676964..644d997b43e 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -79,7 +79,7 @@ def test_meca_spec_single_focalmecha_file(): @pytest.mark.mpl_image_compare(filename="test_meca_spec_multiple_focalmecha.png") -@pytest.mark.parametrize("inputtype", ["dict_mecha", "dataframe"]) +@pytest.mark.parametrize("inputtype", ["dict_mecha", "dataframe", "array2d"]) def test_meca_spec_multiple_focalmecha(inputtype): """ Test passing multiple focal mechanisms to the spec parameter. @@ -110,6 +110,16 @@ def test_meca_spec_multiple_focalmecha(inputtype): }, ) } + elif inputtype == "array2d": + args = { + "spec": np.array( + [ + [-123.5, 47.5, 12.0, 330, 30, 90, 3], + [-124.5, 48.5, 11.0, 350, 50, 90, 2], + ] + ), + "convention": "aki", + } fig = Figure() fig.basemap(region=[-125, -122, 47, 49], projection="M8c", frame=True) @@ -117,36 +127,6 @@ def test_meca_spec_multiple_focalmecha(inputtype): return fig -@pytest.mark.mpl_image_compare -def test_meca_spec_2d_array(): - """ - Test supplying a 2-D numpy array containing focal mechanisms and locations - to the spec parameter. - """ - fig = Figure() - # supply focal mechanisms to meca as a 2-D numpy array, here we are using - # the GCMT convention but the focal mechanism parameters may be - # specified any of the available conventions. Since we are not using a - # dict or dataframe the convention and component should be specified. - - # longitude, latitude, depth, strike1, rake1, strike2, dip2, rake2, - # mantissa, exponent, plot_longitude, plot_latitude - focal_mechanisms = np.array( - [ - [-127.40, 40.87, 12, 170, 20, -110, 11, 71, -83, 5.1, 23, 0, 0], - [-127.50, 40.88, 12.0, 168, 40, -115, 20, 54, -70, 4.0, 23, 0, 0], - ] - ) - fig.meca( - spec=focal_mechanisms, - convention="gcmt", - region=[-128, -127, 40, 41], - scale="2c", - projection="M14c", - ) - return fig - - @pytest.mark.mpl_image_compare def test_meca_loc_array(): """ From c17f091c1e1b0b8b5576c4a517eea40ab931061e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 6 Jun 2023 13:00:09 +0800 Subject: [PATCH 4/4] Merge test_meca_loc_array into test_meca_spec_multiple_focalmecha --- .../baseline/test_meca_loc_array.png.dvc | 4 -- pygmt/tests/test_meca.py | 48 ++++++------------- 2 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 pygmt/tests/baseline/test_meca_loc_array.png.dvc diff --git a/pygmt/tests/baseline/test_meca_loc_array.png.dvc b/pygmt/tests/baseline/test_meca_loc_array.png.dvc deleted file mode 100644 index 31612381e84..00000000000 --- a/pygmt/tests/baseline/test_meca_loc_array.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 7500fa67c18f4e307497e05fbc6857e3 - size: 4903 - path: test_meca_loc_array.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 644d997b43e..4d013400074 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -79,7 +79,9 @@ def test_meca_spec_single_focalmecha_file(): @pytest.mark.mpl_image_compare(filename="test_meca_spec_multiple_focalmecha.png") -@pytest.mark.parametrize("inputtype", ["dict_mecha", "dataframe", "array2d"]) +@pytest.mark.parametrize( + "inputtype", ["dict_mecha", "dict_mecha_mixed", "dataframe", "array2d"] +) def test_meca_spec_multiple_focalmecha(inputtype): """ Test passing multiple focal mechanisms to the spec parameter. @@ -96,6 +98,18 @@ def test_meca_spec_multiple_focalmecha(inputtype): "latitude": [47.5, 48.5], "depth": [12.0, 11.0], } + elif inputtype == "dict_mecha_mixed": + args = { + "spec": { + "strike": [330, 350], + "dip": [30, 50], + "rake": [90, 90], + "magnitude": [3, 2], + }, + "longitude": np.array([-123.5, -124.5]), + "latitude": [47.5, 48.5], + "depth": [12, 11], + } elif inputtype == "dataframe": args = { "spec": pd.DataFrame( @@ -127,38 +141,6 @@ def test_meca_spec_multiple_focalmecha(inputtype): return fig -@pytest.mark.mpl_image_compare -def test_meca_loc_array(): - """ - Test supplying lists and np.ndarrays as the event location (longitude, - latitude, and depth). - """ - fig = Figure() - # specify focal mechanisms - focal_mechanisms = { - "strike": [327, 350], - "dip": [41, 50], - "rake": [68, 90], - "magnitude": [3, 2], - } - # longitude, latitude, and depth may be specified as an int, float, - # list, or 1-D numpy array - longitude = np.array([-123.3, -124.4]) - latitude = np.array([48.4, 48.2]) - depth = [12.0, 11.0] # to test mixed data types as inputs - scale = "2c" - fig.meca( - focal_mechanisms, - scale, - longitude=longitude, - latitude=latitude, - depth=depth, - region=[-125, -122, 47, 49], - projection="M14c", - ) - return fig - - @pytest.mark.mpl_image_compare def test_meca_dict_offset(): """