diff --git a/pygmt/src/project.py b/pygmt/src/project.py index 33f4da1ceca..5b1988d0349 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -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 @@ -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"]) @@ -267,7 +269,7 @@ def project( y=y, z=z, mincols=2, - required=False, + required=aliasdict.get("G") is None, ) as vintbl, lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl, ): diff --git a/pygmt/tests/test_project.py b/pygmt/tests/test_project.py index 4d00709c039..35b8841541e 100644 --- a/pygmt/tests/test_project.py +++ b/pygmt/tests/test_project.py @@ -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. @@ -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")