Skip to content
Open
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
8 changes: 5 additions & 3 deletions pygmt/src/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def project(
Pass in (x, y, z) or (longitude, latitude, elevation) values by
providing a file name to an ASCII data table, a 2-D
$table_classes.
x/y/z : 1-D arrays
Arrays of x- and y-coordinates and z-values of the data points.
$output_type
$outfile
center
Expand Down Expand Up @@ -223,9 +225,9 @@ def project(
"""
if kwargs.get("C", center) is None:
raise GMTParameterError(required="center")
if kwargs.get("G") is None and data is None:
if kwargs.get("G") is None and data is None and x is None and y is None:
raise GMTParameterError(
required="data", reason="Required unless 'generate' is set."
at_least_one=["data", "x/y/z"], reason="Required unless 'generate' is set."
)
if kwargs.get("G") is not None and kwargs.get("F") is not None:
raise GMTParameterError(at_most_one=["convention", "generate"])
Expand Down Expand Up @@ -267,7 +269,7 @@ def project(
y=y,
z=z,
mincols=2,
required=False,
required=aliasdict.get("G") is None,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data or x/y/z is required if -G option (generate mode) is not set.

) as vintbl,
lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl,
):
Expand Down
26 changes: 21 additions & 5 deletions pygmt/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ def test_project_input_matrix(array_func, dataframe):
)


def test_project_input_xy(dataframe):
"""
Run project by passing in x/y as input.
"""
output = project(
x=dataframe.x, y=dataframe.y, center=[0, -1], azimuth=45, flat_earth=True
)
assert isinstance(output, pd.DataFrame)
assert output.shape == (1, 6)
npt.assert_allclose(
output.iloc[0],
[0.000000, 0.000000, 0.707107, 0.707107, 0.500000, -0.500000],
rtol=1e-5,
)


def test_project_output_filename(dataframe):
"""
Run project by passing in a pandas.DataFrame, and output to an ASCII txt file.
Expand All @@ -78,17 +94,17 @@ def test_project_output_filename(dataframe):

def test_project_incorrect_parameters():
"""
Run project by providing incorrect parameters such as 1) no `center`; 2) no `data`
or `generate`; and 3) `generate` with `convention`.
Run project by providing incorrect parameters such as 1) no 'center'; 2) no 'data',
'x'/'y' or 'generate'; and 3) 'generate' with 'convention'.
"""
with pytest.raises(GMTParameterError):
# No `center`
# 'center' is not set
project(azimuth=45)
with pytest.raises(GMTParameterError):
# No `data` or `generate`
# None of 'data', 'x'/'y' or 'generate' is set
project(center=[0, -1], azimuth=45, flat_earth=True)
with pytest.raises(GMTParameterError):
# Using `generate` with `convention`
# Using 'generate' with 'convention'
project(center=[0, -1], generate=0.5, convention="xypqrsz")


Expand Down
Loading