Skip to content

Commit

Permalink
Refactor x2sys_cross to remove verbose info and return output stateme…
Browse files Browse the repository at this point in the history
…nts (GenericMappingTools#1572)

Silences captured stderr messages in the log from running x2sys_cross.
  • Loading branch information
weiji14 authored and Josh Sixsmith committed Dec 21, 2022
1 parent 0ff33ec commit f5d5383
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions pygmt/tests/test_x2sys_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ def test_x2sys_cross_input_file_output_file(mock_x2sys_home):
x2sys_init(tag=tag, fmtfile="xyz", force=True)
outfile = os.path.join(tmpdir, "tmp_coe.txt")
output = x2sys_cross(
tracks=["@tut_ship.xyz"], tag=tag, coe="i", outfile=outfile, verbose="i"
tracks=["@tut_ship.xyz"], tag=tag, coe="i", outfile=outfile
)

assert output is None # check that output is None since outfile is set
assert os.path.exists(path=outfile) # check that outfile exists at path
_ = pd.read_csv(outfile, sep="\t", header=2) # ensure ASCII text file loads ok

return output


def test_x2sys_cross_input_file_output_dataframe(mock_x2sys_home):
"""
Expand All @@ -62,16 +60,14 @@ def test_x2sys_cross_input_file_output_dataframe(mock_x2sys_home):
with TemporaryDirectory(prefix="X2SYS", dir=os.getcwd()) as tmpdir:
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)
output = x2sys_cross(tracks=["@tut_ship.xyz"], tag=tag, coe="i", verbose="i")
output = x2sys_cross(tracks=["@tut_ship.xyz"], tag=tag, coe="i")

assert isinstance(output, pd.DataFrame)
assert output.shape == (14294, 12)
columns = list(output.columns)
assert columns[:6] == ["x", "y", "i_1", "i_2", "dist_1", "dist_2"]
assert columns[6:] == ["head_1", "head_2", "vel_1", "vel_2", "z_X", "z_M"]

return output


def test_x2sys_cross_input_dataframe_output_dataframe(mock_x2sys_home, tracks):
"""
Expand All @@ -82,7 +78,7 @@ def test_x2sys_cross_input_dataframe_output_dataframe(mock_x2sys_home, tracks):
tag = os.path.basename(tmpdir)
x2sys_init(tag=tag, fmtfile="xyz", force=True)

output = x2sys_cross(tracks=tracks, tag=tag, coe="i", verbose="i")
output = x2sys_cross(tracks=tracks, tag=tag, coe="i")

assert isinstance(output, pd.DataFrame)
assert output.shape == (14, 12)
Expand All @@ -92,8 +88,6 @@ def test_x2sys_cross_input_dataframe_output_dataframe(mock_x2sys_home, tracks):
assert output.dtypes["i_1"].type == np.object_
assert output.dtypes["i_2"].type == np.object_

return output


def test_x2sys_cross_input_two_dataframes(mock_x2sys_home):
"""
Expand All @@ -120,7 +114,7 @@ def test_x2sys_cross_input_two_dataframes(mock_x2sys_home):
track["time"] = pd.date_range(start=f"2020-{i}1-01", periods=10, freq="ms")
tracks.append(track)

output = x2sys_cross(tracks=tracks, tag=tag, coe="e", verbose="i")
output = x2sys_cross(tracks=tracks, tag=tag, coe="e")

assert isinstance(output, pd.DataFrame)
assert output.shape == (30, 12)
Expand Down Expand Up @@ -171,9 +165,7 @@ def test_x2sys_cross_input_two_filenames(mock_x2sys_home):
) as fname:
np.savetxt(fname=fname, X=np.random.rand(10, 3))

output = x2sys_cross(
tracks=["track_0.xyz", "track_1.xyz"], tag=tag, coe="e", verbose="i"
)
output = x2sys_cross(tracks=["track_0.xyz", "track_1.xyz"], tag=tag, coe="e")

assert isinstance(output, pd.DataFrame)
assert output.shape == (24, 12)
Expand All @@ -182,8 +174,6 @@ def test_x2sys_cross_input_two_filenames(mock_x2sys_home):
assert columns[6:] == ["head_1", "head_2", "vel_1", "vel_2", "z_X", "z_M"]
_ = [os.remove(f"track_{i}.xyz") for i in range(2)] # cleanup track files

return output


def test_x2sys_cross_invalid_tracks_input_type(tracks):
"""
Expand Down

0 comments on commit f5d5383

Please sign in to comment.