-
Notifications
You must be signed in to change notification settings - Fork 235
Wrap grd2xyz #1284
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
Wrap grd2xyz #1284
Changes from 6 commits
17a86be
7e7a7fa
6525ff3
13e309c
c08d717
cd26ff2
ccd27c0
bf58dc2
7f100d5
0701d62
789ac47
8787892
11f1782
6ac279c
a226f34
0b52451
37d366d
b27699a
0361381
a9fef07
957d8fe
5a4baa5
1cf9e56
948ca73
b050cd8
9ab9701
891ff6c
02cd02f
00bece0
3b6fc93
01613ff
3da6dda
2dcf859
283d515
77315ba
29c8be6
c4549e4
66761a8
0a525b6
8de23a8
938532a
161c94b
317a3dd
41051a9
9eebee3
3ac3642
81b0511
af6aac9
e1c6555
1927795
95c7731
76190ab
31388eb
924a3e0
9a3c377
4b1214c
59bae5c
2a11880
ff45946
290cf04
e3336c4
552bf3f
6731814
f49dac0
708e3c4
f94df58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ Operations on grids: | |
| .. autosummary:: | ||
| :toctree: generated | ||
|
|
||
| grd2xyz | ||
| grdclip | ||
| grdcut | ||
| grdfill | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| blockmedian, | ||
| config, | ||
| grd2cpt, | ||
| grd2xyz, | ||
| grdclip, | ||
| grdcut, | ||
| grdfill, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """ | ||
| grd2xyz - Convert grid to data table | ||
| """ | ||
| from pygmt.clib import Session | ||
| from pygmt.helpers import ( | ||
| GMTTempFile, | ||
| build_arg_string, | ||
| fmt_docstring, | ||
| kwargs_to_strings, | ||
| use_alias, | ||
| ) | ||
|
|
||
|
|
||
| @fmt_docstring | ||
| @use_alias( | ||
| R="region", | ||
| V="verbose", | ||
| ) | ||
| @kwargs_to_strings(R="sequence") | ||
willschlitzer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def grd2xyz(grid, **kwargs): | ||
| r""" | ||
| Create xyz tables from grid files. | ||
willschlitzer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Read a binary 2-D grid files and write out | ||
| xyz-triplets in ASCII [or binary] format to a standard output. | ||
willschlitzer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Full option list at :gmt-docs:`grd2xyz.html` | ||
|
|
||
| {aliases} | ||
|
|
||
| Parameters | ||
| ---------- | ||
| grid : str or xarray.DataArray | ||
| The file name of the input grid or the grid loaded as a DataArray. | ||
| This is the only required parameter. | ||
willschlitzer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {R} | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {V} | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Returns | ||
| ------- | ||
| info : str | ||
| A string with information about the grid. | ||
willschlitzer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| with GMTTempFile() as outfile: | ||
| with Session() as lib: | ||
| file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) | ||
| with file_context as infile: | ||
| arg_str = " ".join( | ||
| [infile, build_arg_string(kwargs), "->" + outfile.name] | ||
| ) | ||
| lib.call_module("grd2xyz", arg_str) | ||
| result = outfile.read() | ||
| return result | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """ | ||
| Tests for grd2xyz. | ||
| """ | ||
| import pytest | ||
| from pygmt import grd2xyz | ||
| from pygmt.datasets import load_earth_relief | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", name="grid") | ||
| def fixture_grid(): | ||
| """ | ||
| Load the grid data from the sample earth_relief file. | ||
| """ | ||
| return load_earth_relief(resolution="01d", region=[-1, 1, -1, 1]) | ||
willschlitzer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_grd2xyz(grid): | ||
| """ | ||
| Make sure grd2xyz works as expected. | ||
| """ | ||
| xyz_data = grd2xyz(grid=grid) | ||
| assert xyz_data.strip().split("\n") == [ | ||
|
||
| "-0.5 0.5 -4967", | ||
| "0.5 0.5 -4852", | ||
| "-0.5 -0.5 -4917", | ||
| "0.5 -0.5 -4747.5", | ||
| ] | ||
Uh oh!
There was an error while loading. Please reload this page.