File tree 1 file changed +20
-1
lines changed 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
grdvolume - Calculate grid volume and area constrained by a contour.
3
3
"""
4
+ import numpy as np
5
+ import pandas as pd
4
6
from pygmt .clib import Session
7
+ from pygmt .exceptions import GMTInvalidInput
5
8
from pygmt .helpers import (
6
9
GMTTempFile ,
7
10
build_arg_string ,
21
24
V = "verbose" ,
22
25
)
23
26
@kwargs_to_strings (C = "sequence" , R = "sequence" )
24
- def grdvolume (grid , ** kwargs ):
27
+ def grdvolume (grid , data_format = "a" , ** kwargs ):
25
28
r"""
26
29
{aliases}
27
30
@@ -47,4 +50,20 @@ def grdvolume(grid, **kwargs):
47
50
)
48
51
lib .call_module ("grdvolume" , arg_str )
49
52
result = outfile .read ()
53
+ if data_format == "s" :
54
+ return result
55
+ data_list = []
56
+ for string_entry in result .strip ().split ("\n " ):
57
+ float_entry = []
58
+ string_list = string_entry .strip ().split ()
59
+ for i in string_list :
60
+ float_entry .append (float (i ))
61
+ data_list .append (float_entry )
62
+ data_array = np .array (data_list )
63
+ if data_format == "a" :
64
+ result = data_array
65
+ elif data_format == "d" :
66
+ result = pd .DataFrame (data_array )
67
+ else :
68
+ raise GMTInvalidInput ("""Must specify format as either a, d, or s.""" )
50
69
return result
You can’t perform that action at this time.
0 commit comments