Skip to content

Commit 08a29bb

Browse files
authored
Use consistent names (vintbl and vingrd) for input virtual files (#3082)
1 parent 14593ad commit 08a29bb

39 files changed

+98
-140
lines changed

pygmt/src/binstats.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ def binstats(data, **kwargs):
112112
"""
113113
with GMTTempFile(suffix=".nc") as tmpfile:
114114
with Session() as lib:
115-
file_context = lib.virtualfile_in(check_kind="vector", data=data)
116-
with file_context as infile:
115+
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
117116
if (outgrid := kwargs.get("G")) is None:
118117
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
119118
lib.call_module(
120-
module="binstats", args=build_arg_string(kwargs, infile=infile)
119+
module="binstats", args=build_arg_string(kwargs, infile=vintbl)
121120
)
122121

123122
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/blockm.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ def _blockm(block_method, data, x, y, z, outfile, **kwargs):
4444
"""
4545
with GMTTempFile(suffix=".csv") as tmpfile:
4646
with Session() as lib:
47-
table_context = lib.virtualfile_in(
47+
with lib.virtualfile_in(
4848
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
49-
)
50-
# Run blockm* on data table
51-
with table_context as infile:
49+
) as vintbl:
50+
# Run blockm* on data table
5251
if outfile is None:
5352
outfile = tmpfile.name
5453
lib.call_module(
5554
module=block_method,
56-
args=build_arg_string(kwargs, infile=infile, outfile=outfile),
55+
args=build_arg_string(kwargs, infile=vintbl, outfile=outfile),
5756
)
5857

5958
# Read temporary csv output to a pandas table

pygmt/src/contour.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs):
115115
kwargs = self._preprocess(**kwargs)
116116

117117
with Session() as lib:
118-
file_context = lib.virtualfile_in(
118+
with lib.virtualfile_in(
119119
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
120-
)
121-
with file_context as fname:
120+
) as vintbl:
122121
lib.call_module(
123-
module="contour", args=build_arg_string(kwargs, infile=fname)
122+
module="contour", args=build_arg_string(kwargs, infile=vintbl)
124123
)

pygmt/src/dimfilter.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,11 @@ def dimfilter(grid, **kwargs):
151151

152152
with GMTTempFile(suffix=".nc") as tmpfile:
153153
with Session() as lib:
154-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
155-
with file_context as infile:
154+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
156155
if (outgrid := kwargs.get("G")) is None:
157156
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
158157
lib.call_module(
159-
module="dimfilter", args=build_arg_string(kwargs, infile=infile)
158+
module="dimfilter", args=build_arg_string(kwargs, infile=vingrd)
160159
)
161160

162161
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/filter1d.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,12 @@ def filter1d(data, output_type="pandas", outfile=None, **kwargs):
119119

120120
with GMTTempFile() as tmpfile:
121121
with Session() as lib:
122-
file_context = lib.virtualfile_in(check_kind="vector", data=data)
123-
with file_context as infile:
122+
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
124123
if outfile is None:
125124
outfile = tmpfile.name
126125
lib.call_module(
127126
module="filter1d",
128-
args=build_arg_string(kwargs, infile=infile, outfile=outfile),
127+
args=build_arg_string(kwargs, infile=vintbl, outfile=outfile),
129128
)
130129

131130
# Read temporary csv output to a pandas table

pygmt/src/grd2cpt.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,12 @@ def grd2cpt(grid, **kwargs):
184184
if kwargs.get("W") is not None and kwargs.get("Ww") is not None:
185185
raise GMTInvalidInput("Set only categorical or cyclic to True, not both.")
186186
with Session() as lib:
187-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
188-
with file_context as infile:
187+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
189188
if kwargs.get("H") is None: # if no output is set
190-
arg_str = build_arg_string(kwargs, infile=infile)
189+
arg_str = build_arg_string(kwargs, infile=vingrd)
191190
else: # if output is set
192191
outfile, kwargs["H"] = kwargs["H"], True
193192
if not outfile or not isinstance(outfile, str):
194193
raise GMTInvalidInput("'output' should be a proper file name.")
195-
arg_str = build_arg_string(kwargs, infile=infile, outfile=outfile)
194+
arg_str = build_arg_string(kwargs, infile=vingrd, outfile=outfile)
196195
lib.call_module(module="grd2cpt", args=arg_str)

pygmt/src/grd2xyz.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,12 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs):
158158

159159
with GMTTempFile() as tmpfile:
160160
with Session() as lib:
161-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
162-
with file_context as infile:
161+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
163162
if outfile is None:
164163
outfile = tmpfile.name
165164
lib.call_module(
166165
module="grd2xyz",
167-
args=build_arg_string(kwargs, infile=infile, outfile=outfile),
166+
args=build_arg_string(kwargs, infile=vingrd, outfile=outfile),
168167
)
169168

170169
# Read temporary csv output to a pandas table

pygmt/src/grdclip.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,11 @@ def grdclip(grid, **kwargs):
9797
"""
9898
with GMTTempFile(suffix=".nc") as tmpfile:
9999
with Session() as lib:
100-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
101-
with file_context as infile:
100+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
102101
if (outgrid := kwargs.get("G")) is None:
103102
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
104103
lib.call_module(
105-
module="grdclip", args=build_arg_string(kwargs, infile=infile)
104+
module="grdclip", args=build_arg_string(kwargs, infile=vingrd)
106105
)
107106

108107
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdcontour.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def grdcontour(self, grid, **kwargs):
123123
"""
124124
kwargs = self._preprocess(**kwargs)
125125
with Session() as lib:
126-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
127-
with file_context as fname:
126+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
128127
lib.call_module(
129-
module="grdcontour", args=build_arg_string(kwargs, infile=fname)
128+
module="grdcontour", args=build_arg_string(kwargs, infile=vingrd)
130129
)

pygmt/src/grdcut.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ def grdcut(grid, **kwargs):
101101
"""
102102
with GMTTempFile(suffix=".nc") as tmpfile:
103103
with Session() as lib:
104-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
105-
with file_context as infile:
104+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
106105
if (outgrid := kwargs.get("G")) is None:
107106
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
108107
lib.call_module(
109-
module="grdcut", args=build_arg_string(kwargs, infile=infile)
108+
module="grdcut", args=build_arg_string(kwargs, infile=vingrd)
110109
)
111110

112111
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdfill.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ def grdfill(grid, **kwargs):
7979
raise GMTInvalidInput("At least parameter 'mode' or 'L' must be specified.")
8080
with GMTTempFile(suffix=".nc") as tmpfile:
8181
with Session() as lib:
82-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
83-
with file_context as infile:
82+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
8483
if (outgrid := kwargs.get("G")) is None:
8584
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
8685
lib.call_module(
87-
module="grdfill", args=build_arg_string(kwargs, infile=infile)
86+
module="grdfill", args=build_arg_string(kwargs, infile=vingrd)
8887
)
8988

9089
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdfilter.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ def grdfilter(grid, **kwargs):
134134
"""
135135
with GMTTempFile(suffix=".nc") as tmpfile:
136136
with Session() as lib:
137-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
138-
with file_context as infile:
137+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
139138
if (outgrid := kwargs.get("G")) is None:
140139
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
141140
lib.call_module(
142-
module="grdfilter", args=build_arg_string(kwargs, infile=infile)
141+
module="grdfilter", args=build_arg_string(kwargs, infile=vingrd)
143142
)
144143

145144
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdgradient.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ def grdgradient(grid, **kwargs):
169169
azimuth, direction, or radiance"""
170170
)
171171
with Session() as lib:
172-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
173-
with file_context as infile:
172+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
174173
if (outgrid := kwargs.get("G")) is None:
175174
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
176175
lib.call_module(
177-
module="grdgradient", args=build_arg_string(kwargs, infile=infile)
176+
module="grdgradient", args=build_arg_string(kwargs, infile=vingrd)
178177
)
179178

180179
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdimage.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ def grdimage(self, grid, **kwargs):
165165

166166
with Session() as lib:
167167
with (
168-
lib.virtualfile_in(check_kind="raster", data=grid) as fname,
168+
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
169169
lib.virtualfile_in(
170170
check_kind="raster", data=kwargs.get("I"), required_data=False
171-
) as shadegrid,
171+
) as vshadegrid,
172172
):
173-
kwargs["I"] = shadegrid
173+
kwargs["I"] = vshadegrid
174174
lib.call_module(
175-
module="grdimage", args=build_arg_string(kwargs, infile=fname)
175+
module="grdimage", args=build_arg_string(kwargs, infile=vingrd)
176176
)

pygmt/src/grdinfo.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ def grdinfo(grid, **kwargs):
112112
"""
113113
with GMTTempFile() as outfile:
114114
with Session() as lib:
115-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
116-
with file_context as infile:
115+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
117116
lib.call_module(
118117
module="grdinfo",
119-
args=build_arg_string(kwargs, infile=infile, outfile=outfile.name),
118+
args=build_arg_string(kwargs, infile=vingrd, outfile=outfile.name),
120119
)
121120
result = outfile.read()
122121
return result

pygmt/src/grdproject.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ def grdproject(grid, **kwargs):
113113
raise GMTInvalidInput("The projection must be specified.")
114114
with GMTTempFile(suffix=".nc") as tmpfile:
115115
with Session() as lib:
116-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
117-
with file_context as infile:
116+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
118117
if (outgrid := kwargs.get("G")) is None:
119118
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
120119
lib.call_module(
121-
module="grdproject", args=build_arg_string(kwargs, infile=infile)
120+
module="grdproject", args=build_arg_string(kwargs, infile=vingrd)
122121
)
123122

124123
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdsample.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ def grdsample(grid, **kwargs):
8989
"""
9090
with GMTTempFile(suffix=".nc") as tmpfile:
9191
with Session() as lib:
92-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
93-
with file_context as infile:
92+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
9493
if (outgrid := kwargs.get("G")) is None:
9594
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
9695
lib.call_module(
97-
module="grdsample", args=build_arg_string(kwargs, infile=infile)
96+
module="grdsample", args=build_arg_string(kwargs, infile=vingrd)
9897
)
9998

10099
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/grdtrack.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,17 @@ def grdtrack(grid, points=None, newcolname=None, outfile=None, **kwargs):
294294
with GMTTempFile(suffix=".csv") as tmpfile:
295295
with Session() as lib:
296296
with (
297-
lib.virtualfile_in(check_kind="raster", data=grid) as grdfile,
297+
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
298298
lib.virtualfile_in(
299299
check_kind="vector", data=points, required_data=False
300-
) as csvfile,
300+
) as vintbl,
301301
):
302-
kwargs["G"] = grdfile
302+
kwargs["G"] = vingrd
303303
if outfile is None: # Output to tmpfile if outfile is not set
304304
outfile = tmpfile.name
305305
lib.call_module(
306306
module="grdtrack",
307-
args=build_arg_string(kwargs, infile=csvfile, outfile=outfile),
307+
args=build_arg_string(kwargs, infile=vintbl, outfile=outfile),
308308
)
309309

310310
# Read temporary csv output to a pandas table

pygmt/src/grdview.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ def grdview(self, grid, **kwargs):
146146
kwargs = self._preprocess(**kwargs)
147147
with Session() as lib:
148148
with (
149-
lib.virtualfile_in(check_kind="raster", data=grid) as fname,
149+
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
150150
lib.virtualfile_in(
151151
check_kind="raster", data=kwargs.get("G"), required_data=False
152-
) as drapegrid,
152+
) as vdrapegrid,
153153
):
154-
kwargs["G"] = drapegrid
154+
kwargs["G"] = vdrapegrid
155155
lib.call_module(
156-
module="grdview", args=build_arg_string(kwargs, infile=fname)
156+
module="grdview", args=build_arg_string(kwargs, infile=vingrd)
157157
)

pygmt/src/grdvolume.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ def grdvolume(grid, output_type="pandas", outfile=None, **kwargs):
105105

106106
with GMTTempFile() as tmpfile:
107107
with Session() as lib:
108-
file_context = lib.virtualfile_in(check_kind="raster", data=grid)
109-
with file_context as infile:
108+
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
110109
if outfile is None:
111110
outfile = tmpfile.name
112111
lib.call_module(
113112
module="grdvolume",
114-
args=build_arg_string(kwargs, infile=infile, outfile=outfile),
113+
args=build_arg_string(kwargs, infile=vingrd, outfile=outfile),
115114
)
116115

117116
# Read temporary csv output to a pandas table

pygmt/src/histogram.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ def histogram(self, data, **kwargs):
135135
"""
136136
kwargs = self._preprocess(**kwargs)
137137
with Session() as lib:
138-
file_context = lib.virtualfile_in(check_kind="vector", data=data)
139-
with file_context as infile:
138+
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
140139
lib.call_module(
141-
module="histogram", args=build_arg_string(kwargs, infile=infile)
140+
module="histogram", args=build_arg_string(kwargs, infile=vintbl)
142141
)

pygmt/src/info.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ def info(data, **kwargs):
8181
- str if none of the above parameters are used.
8282
"""
8383
with Session() as lib:
84-
file_context = lib.virtualfile_in(check_kind="vector", data=data)
8584
with GMTTempFile() as tmpfile:
86-
with file_context as fname:
85+
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
8786
lib.call_module(
8887
module="info",
89-
args=build_arg_string(kwargs, infile=fname, outfile=tmpfile.name),
88+
args=build_arg_string(kwargs, infile=vintbl, outfile=tmpfile.name),
9089
)
9190
result = tmpfile.read()
9291

pygmt/src/meca.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,5 @@ def meca( # noqa: PLR0912, PLR0913, PLR0915
489489
# Assemble -S flag
490490
kwargs["S"] = f"{data_format}{scale}"
491491
with Session() as lib:
492-
file_context = lib.virtualfile_in(check_kind="vector", data=spec)
493-
with file_context as fname:
494-
lib.call_module(module="meca", args=build_arg_string(kwargs, infile=fname))
492+
with lib.virtualfile_in(check_kind="vector", data=spec) as vintbl:
493+
lib.call_module(module="meca", args=build_arg_string(kwargs, infile=vintbl))

pygmt/src/nearneighbor.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,13 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs):
145145
"""
146146
with GMTTempFile(suffix=".nc") as tmpfile:
147147
with Session() as lib:
148-
table_context = lib.virtualfile_in(
148+
with lib.virtualfile_in(
149149
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
150-
)
151-
with table_context as infile:
150+
) as vintbl:
152151
if (outgrid := kwargs.get("G")) is None:
153152
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
154153
lib.call_module(
155-
module="nearneighbor", args=build_arg_string(kwargs, infile=infile)
154+
module="nearneighbor", args=build_arg_string(kwargs, infile=vintbl)
156155
)
157156

158157
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

pygmt/src/plot.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ def plot( # noqa: PLR0912
251251
kwargs[flag] = ""
252252

253253
with Session() as lib:
254-
file_context = lib.virtualfile_in(
254+
with lib.virtualfile_in(
255255
check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays
256-
)
257-
258-
with file_context as fname:
259-
lib.call_module(module="plot", args=build_arg_string(kwargs, infile=fname))
256+
) as vintbl:
257+
lib.call_module(module="plot", args=build_arg_string(kwargs, infile=vintbl))

0 commit comments

Comments
 (0)