@@ -105,33 +105,28 @@ class Session:
105
105
"""
106
106
A GMT API session where most operations involving the C API happen.
107
107
108
- Works as a context manager (for use in a ``with`` block) to create a GMT C
109
- API session and destroy it in the end to clean up memory.
108
+ Works as a context manager (for use in a ``with`` block) to create a GMT C API
109
+ session and destroy it in the end to clean up memory.
110
110
111
- Functions of the shared library are exposed as methods of this class. Most
112
- methods MUST be used with an open session (inside a ``with`` block). If
113
- creating GMT data structures to communicate data, put that code inside the
114
- same ``with`` block as the API calls that will use the data.
111
+ Functions of the shared library are exposed as methods of this class. Most methods
112
+ MUST be used with an open session (inside a ``with`` block). If creating GMT data
113
+ structures to communicate data, put that code inside the same ``with`` block as the
114
+ API calls that will use the data.
115
115
116
- By default, will let :mod:`ctypes` try to find the GMT shared library
117
- (``libgmt``). If the environment variable :term:`GMT_LIBRARY_PATH` is set, will
118
- look for the shared library in the directory specified by it.
116
+ By default, will let :mod:`ctypes` try to find the GMT shared library (``libgmt``).
117
+ If the environment variable :term:`GMT_LIBRARY_PATH` is set, will look for the
118
+ shared library in the directory specified by it.
119
119
120
- A ``GMTVersionError`` exception will be raised if the GMT shared library
121
- reports a version older than the required minimum GMT version.
122
-
123
- The ``session_pointer`` attribute holds a ctypes pointer to the currently
124
- open session.
120
+ The ``session_pointer`` attribute holds a ctypes pointer to the currently open
121
+ session.
125
122
126
123
Raises
127
124
------
128
125
GMTCLibNotFoundError
129
- If there was any problem loading the library (couldn't find it or
130
- couldn't access the functions).
126
+ If there was any problem loading the library (couldn't find it or couldn't
127
+ access the functions).
131
128
GMTCLibNoSessionError
132
- If you try to call a method outside of a 'with' block.
133
- GMTVersionError
134
- If the minimum required version of GMT is not found.
129
+ If you try to call a method outside of a ``with`` block.
135
130
136
131
Examples
137
132
--------
@@ -141,45 +136,44 @@ class Session:
141
136
>>> grid = load_static_earth_relief()
142
137
>>> type(grid)
143
138
<class 'xarray.core.dataarray.DataArray'>
144
- >>> # Create a session and destroy it automatically when exiting the "with"
145
- >>> # block.
146
- >>> with Session() as ses:
139
+ >>> # Create a session and destroy it automatically when exiting the "with" block.
140
+ >>> with Session() as lib:
147
141
... # Create a virtual file and link to the memory block of the grid.
148
- ... with ses .virtualfile_from_grid(grid) as fin:
142
+ ... with lib .virtualfile_from_grid(grid) as fin:
149
143
... # Create a temp file to use as output.
150
144
... with GMTTempFile() as fout:
151
- ... # Call the grdinfo module with the virtual file as input
152
- ... # and the temp file as output.
153
- ... ses .call_module("grdinfo", [fin, "-C", f"->{fout.name}"])
145
+ ... # Call the grdinfo module with the virtual file as input and the
146
+ ... # temp file as output.
147
+ ... lib .call_module("grdinfo", [fin, "-C", f"->{fout.name}"])
154
148
... # Read the contents of the temp file before it's deleted.
155
149
... print(fout.read().strip())
156
150
-55 -47 -24 -10 190 981 1 1 8 14 1 1
157
151
"""
158
152
159
153
@property
160
- def session_pointer (self ):
154
+ def session_pointer (self ) -> ctp . c_void_p :
161
155
"""
162
156
The :class:`ctypes.c_void_p` pointer to the current open GMT session.
163
157
164
158
Raises
165
159
------
166
160
GMTCLibNoSessionError
167
- If trying to access without a currently open GMT session (i.e.,
168
- outside of the context manager).
161
+ If trying to access without a currently open GMT session (i.e., outside of
162
+ the context manager).
169
163
"""
170
164
if not hasattr (self , "_session_pointer" ) or self ._session_pointer is None :
171
165
raise GMTCLibNoSessionError ("No currently open GMT API session." )
172
166
return self ._session_pointer
173
167
174
168
@session_pointer .setter
175
- def session_pointer (self , session ):
169
+ def session_pointer (self , session : ctp . c_void_p ):
176
170
"""
177
171
Set the session void pointer.
178
172
"""
179
173
self ._session_pointer = session
180
174
181
175
@property
182
- def info (self ):
176
+ def info (self ) -> dict [ str , str ] :
183
177
"""
184
178
Dictionary with the GMT version and default paths and parameters.
185
179
"""
0 commit comments