def test_project_input_matrix(array_func, dataframe): """ Run project by passing in a matrix as input. """ table = array_func(dataframe) output = project(data=table, 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_generate(): """ Run project by passing in center and endpoint as input. """ output = project(center=[0, -1], endpoint=[0, 1], flat_earth=True, generate=0.5) assert isinstance(output, pd.DataFrame) assert output.shape == (5, 3) npt.assert_allclose(output.iloc[1], [3.061617e-17, -0.5, 0.5]) pd.testing.assert_index_equal(left=output.columns, right=pd.Index(data=["r", "s", "p"]))
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`. """ with pytest.raises(GMTInvalidInput): # No `center` project(azimuth=45) with pytest.raises(GMTInvalidInput): # No `data` or `generate` project(center=[0, -1], azimuth=45, flat_earth=True) with pytest.raises(GMTInvalidInput): # Using `generate` with `convention` project(center=[0, -1], generate=0.5, convention="xypqrsz")
def test_project_output_filename(dataframe): """ Run project by passing in a pandas.DataFrame, and output to an ASCII txt file. """ with GMTTempFile() as tmpfile: output = project( data=dataframe, center=[0, -1], azimuth=45, flat_earth=True, outfile=tmpfile.name, ) assert output is None # check that output is None since outfile is set assert os.path.exists( path=tmpfile.name) # check that outfile exists at path output = pd.read_csv(tmpfile.name, sep="\t", header=None) 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, )
----------------------------------- The :meth:`pygmt.project` method can generate points along a great circle whose center and end points can be defined via the ``center`` and ``endpoint`` parameters, respectively. Using the ``generate`` parameter allows to generate (*r*, *s*, *p*) points every *dist* units of *p* along a profile as output. By default all units (*r*, *s* and *p*) are set to degrees while ``unit=True`` allows to set the unit for *p* to km. """ import pygmt fig = pygmt.Figure() # generate points every 10 degrees along a great circle from 10N,50W to 30N,5W points1 = pygmt.project(center=[-50, 10], endpoint=[-5, 30], generate=10) # generate points every 750 km along a great circle from 10N,50W to 57.5N,90W points2 = pygmt.project(center=[-50, 10], endpoint=[-90, 57.5], generate=750, unit=True) # generate points every 350 km along a great circle from 10N,50W to 68N,5W points3 = pygmt.project(center=[-50, 10], endpoint=[-5, 68], generate=350, unit=True) # create a plot with coast and Mercator projection (M) fig.basemap(region=[-100, 0, 0, 70], projection="M12c", frame=True) fig.coast(shorelines=True, area_thresh=5000)