diff --git a/pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc b/pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc deleted file mode 100644 index b8a2c1c6022..00000000000 --- a/pygmt/tests/baseline/test_meca_gcmt_convention.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: a44dc0f1af50958aeff2d359ea8b03a7 - size: 8732 - path: test_meca_gcmt_convention.png diff --git a/pygmt/tests/baseline/test_meca_spec_1d_array.png.dvc b/pygmt/tests/baseline/test_meca_spec_1d_array.png.dvc deleted file mode 100644 index 83a40249a05..00000000000 --- a/pygmt/tests/baseline/test_meca_spec_1d_array.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 916dd79b35defcb6b6c1464f4a279790 - size: 3216 - path: test_meca_spec_1d_array.png diff --git a/pygmt/tests/baseline/test_meca_spec_dictionary.png.dvc b/pygmt/tests/baseline/test_meca_spec_dictionary.png.dvc deleted file mode 100644 index a98a6a549e9..00000000000 --- a/pygmt/tests/baseline/test_meca_spec_dictionary.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 8581943564134f58b295ec633acb8d1e - size: 17901 - path: test_meca_spec_dictionary.png diff --git a/pygmt/tests/baseline/test_meca_spec_file.png.dvc b/pygmt/tests/baseline/test_meca_spec_file.png.dvc deleted file mode 100644 index 1693cb3f82d..00000000000 --- a/pygmt/tests/baseline/test_meca_spec_file.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: ad602355748d74a76edfa5cef4100b13 - size: 3179 - path: test_meca_spec_file.png diff --git a/pygmt/tests/baseline/test_meca_spec_single_focalmecha.png.dvc b/pygmt/tests/baseline/test_meca_spec_single_focalmecha.png.dvc new file mode 100644 index 00000000000..dac0eb3512e --- /dev/null +++ b/pygmt/tests/baseline/test_meca_spec_single_focalmecha.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: fc7c271049fc8583914b508c4bee08fe + size: 9830 + path: test_meca_spec_single_focalmecha.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 5f5e0518b5d..7c730c1a9e3 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -8,24 +8,73 @@ from pygmt.helpers import GMTTempFile -@pytest.mark.mpl_image_compare -def test_meca_spec_dictionary(): +@pytest.mark.mpl_image_compare(filename="test_meca_spec_single_focalmecha.png") +@pytest.mark.parametrize("inputtype", ["dict_mecha", "dict_full", "array1d", "pandas"]) +def test_meca_spec_single_focalmecha(inputtype): + """ + Test passing a single focal mechanism to the spec parameter. + """ + if inputtype == "dict_mecha": + args = { + "spec": {"strike": 0, "dip": 90, "rake": 0, "magnitude": 5}, + "longitude": 0, + "latitude": 5, + "depth": 0, + } + elif inputtype == "dict_full": + args = { + "spec": { + "longitude": 0, + "latitude": 5, + "depth": 0, + "strike": 0, + "dip": 90, + "rake": 0, + "magnitude": 5, + } + } + elif inputtype == "array1d": + args = { + "spec": np.array([0, 5, 0, 0, 90, 0, 5]), + "convention": "a", + } + elif inputtype == "pandas": + args = { + "spec": pd.DataFrame( + { + "longitude": 0, + "latitude": 5, + "depth": 0, + "strike": 0, + "dip": 90, + "rake": 0, + "magnitude": 5, + }, + index=[0], + ) + } + fig = Figure() + fig.basemap(region=[-1, 1, 4, 6], projection="M8c", frame=2) + fig.meca(scale="2.5c", **args) + return fig + + +@pytest.mark.mpl_image_compare(filename="test_meca_spec_single_focalmecha.png") +def test_meca_spec_single_focalmecha_file(): """ - Test supplying a dictionary containing a single focal mechanism to the spec + Test supplying a file containing focal mechanisms and locations to the spec parameter. """ fig = Figure() - # Right lateral strike slip focal mechanism - fig.meca( - spec={"strike": 0, "dip": 90, "rake": 0, "magnitude": 5}, - longitude=0, - latitude=5, - depth=0, - scale="2.5c", - region=[-1, 1, 4, 6], - projection="M14c", - frame=2, - ) + fig.basemap(region=[-1, 1, 4, 6], projection="M8c", frame=2) + with GMTTempFile() as temp: + with open(temp.name, mode="w", encoding="utf8") as temp_file: + temp_file.write("0 5 0 0 90 0 5") + fig.meca( + spec=temp.name, + convention="aki", + scale="2.5c", + ) return fig @@ -83,44 +132,6 @@ def test_meca_spec_dataframe(): return fig -@pytest.mark.mpl_image_compare -def test_meca_spec_1d_array(): - """ - Test supplying a 1-D numpy array containing focal mechanisms and locations - to the spec parameter. - """ - fig = Figure() - # supply focal mechanisms to meca as a 1-D numpy array, here we are using - # the Harvard CMT zero trace 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. - focal_mechanism = [ - -127.40, # longitude - 40.87, # latitude - 12, # depth - -3.19, # mrr - 0.16, # mtt - 3.03, # mff - -1.02, # mrt - -3.93, # mrf - -0.02, # mtf - 23, # exponent - 0, # plot_lon, 0 to plot at event location - 0, # plot_lat, 0 to plot at event location - ] - focal_mech_array = np.asarray(focal_mechanism) - fig.meca( - spec=focal_mech_array, - convention="mt", - component="full", - region=[-128, -127, 40, 41], - scale="2c", - projection="M14c", - ) - return fig - - @pytest.mark.mpl_image_compare def test_meca_spec_2d_array(): """ @@ -151,30 +162,6 @@ def test_meca_spec_2d_array(): return fig -@pytest.mark.mpl_image_compare -def test_meca_spec_file(): - """ - Test supplying a file containing focal mechanisms and locations to the spec - parameter. - """ - fig = Figure() - focal_mechanism = [-127.43, 40.81, 12, -3.19, 1.16, 3.93, -1.02, -3.93, -1.02, 23] - # writes temp file to pass to gmt - with GMTTempFile() as temp: - with open(temp.name, mode="w", encoding="utf8") as temp_file: - temp_file.write(" ".join([str(x) for x in focal_mechanism])) - # supply focal mechanisms to meca as a file - fig.meca( - spec=temp.name, - convention="mt", - component="full", - region=[-128, -127, 40, 41], - scale="2c", - projection="M14c", - ) - return fig - - @pytest.mark.mpl_image_compare def test_meca_loc_array(): """ @@ -207,37 +194,6 @@ def test_meca_loc_array(): return fig -@pytest.mark.mpl_image_compare -def test_meca_gcmt_convention(): - """ - Test plotting beachballs using the global CMT convention. - """ - fig = Figure() - # specify focal mechanisms - focal_mechanisms = { - "strike1": 180, - "dip1": 18, - "rake1": -88, - "strike2": 0, - "dip2": 72, - "rake2": -90, - "mantissa": 5.5, - "exponent": 0, - } - fig.meca( - spec=focal_mechanisms, - scale="1c", - longitude=239.384, - latitude=34.556, - depth=12, - convention="gcmt", - region=[239, 240, 34, 35.2], - projection="m2.5c", - frame=True, - ) - return fig - - @pytest.mark.mpl_image_compare def test_meca_dict_offset(): """