Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Figure.meca tests to dvc #1153

Merged
merged 4 commits into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed pygmt/tests/baseline/test_meca_loc_array.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_loc_array.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 7500fa67c18f4e307497e05fbc6857e3
size: 4903
path: test_meca_loc_array.png
Binary file removed pygmt/tests/baseline/test_meca_spec_1d_array.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_spec_1d_array.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 05610aeb221699698eac9d74012b5c0b
size: 3212
path: test_meca_spec_1d_array.png
Binary file removed pygmt/tests/baseline/test_meca_spec_2d_array.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_spec_2d_array.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: b3e49cd999ed234d679f359d7b4fac28
size: 5424
path: test_meca_spec_2d_array.png
Binary file removed pygmt/tests/baseline/test_meca_spec_dataframe.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_spec_dataframe.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 7b7024b143d6b0ec2a339e58db4d7c78
size: 4575
path: test_meca_spec_dataframe.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_spec_dict_list.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: a0abe33fb3dc4a67444cabe82cad92ba
size: 3074
path: test_meca_spec_dict_list.png
Binary file removed pygmt/tests/baseline/test_meca_spec_dictionary.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_spec_dictionary.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 9077531329696ab21991b6e9595b281a
size: 19564
path: test_meca_spec_dictionary.png
Binary file removed pygmt/tests/baseline/test_meca_spec_file.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_meca_spec_file.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: ad602355748d74a76edfa5cef4100b13
size: 3179
path: test_meca_spec_file.png
44 changes: 9 additions & 35 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
@pytest.mark.mpl_image_compare
def test_meca_spec_dictionary():
"""
Test supplying a dictionary containing a single focal mechanism to the
`spec` argument.
Test supplying a dictionary containing a single focal mechanism to the spec
parameter.
"""

fig = Figure()

# Right lateral strike slip focal mechanism
fig.meca(
dict(strike=0, dip=90, rake=0, magnitude=5),
Expand All @@ -32,24 +30,20 @@ def test_meca_spec_dictionary():
projection="M14c",
frame=2,
)

return fig


@pytest.mark.mpl_image_compare
def test_meca_spec_dict_list():
"""
Test supplying a dictionary containing a list of focal mechanism to the
`spec` argument.
spec parameter.
"""

fig = Figure()

# supply focal mechanisms as a dict of lists
focal_mechanisms = dict(
strike=[330, 350], dip=[30, 50], rake=[90, 90], magnitude=[3, 2]
)

fig.meca(
focal_mechanisms,
longitude=[-124.3, -124.4],
Expand All @@ -59,15 +53,14 @@ def test_meca_spec_dict_list():
scale="2c",
projection="M14c",
)

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` argument.
Test supplying a pandas.DataFrame containing focal mechanisms and locations
to the spec parameter.
"""

fig = Figure()
Expand All @@ -83,21 +76,17 @@ def test_meca_spec_dataframe():
depth=[12, 11.0],
)
spec_dataframe = pd.DataFrame(data=focal_mechanisms)

fig.meca(spec_dataframe, region=[-125, -122, 47, 49], scale="2c", projection="M14c")

return fig


@pytest.mark.mpl_image_compare
def test_meca_spec_1d_array():
"""
Test supplying a 1D numpy array containing focal mechanisms and locations
to the `spec` argument.
to the spec parameter.
"""

fig = Figure()

# supply focal mechanisms to meca as a 1D 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
Expand All @@ -118,7 +107,6 @@ def test_meca_spec_1d_array():
0, # plot_lat, 0 to plot at event location
]
focal_mech_array = np.asarray(focal_mechanism)

fig.meca(
focal_mech_array,
convention="mt",
Expand All @@ -127,19 +115,16 @@ def test_meca_spec_1d_array():
scale="2c",
projection="M14c",
)

return fig


@pytest.mark.mpl_image_compare
def test_meca_spec_2d_array():
"""
Test supplying a 2D numpy array containing focal mechanisms and locations
to the `spec` argument.
to the spec parameter.
"""

fig = Figure()

# supply focal mechanisms to meca as a 2D 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
Expand All @@ -163,29 +148,25 @@ def test_meca_spec_2d_array():
[-127.50, 40.88, 12.0, 168, 40, -115, 20, 54, -70, 4.0, 23, 0, 0],
]
focal_mechs_array = np.asarray(focal_mechanisms)

fig.meca(
focal_mechs_array,
convention="gcmt",
region=[-128, -127, 40, 41],
scale="2c",
projection="M14c",
)

return fig


@pytest.mark.mpl_image_compare
def test_meca_spec_file():
"""
Test supplying a file containing focal mechanisms and locations to the
`spec` argument.
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") as temp_file:
Expand All @@ -199,7 +180,6 @@ def test_meca_spec_file():
scale="2c",
projection="M14c",
)

return fig


Expand All @@ -209,22 +189,17 @@ 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 = dict(
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 1d 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,
Expand All @@ -234,5 +209,4 @@ def test_meca_loc_array():
region=[-125, -122, 47, 49],
projection="M14c",
)

return fig