Skip to content

Commit 2d3e197

Browse files
committed
changing the if statmrnt to try except style
1 parent 8a20e99 commit 2d3e197

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pygmt/src/plot.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
plot - Plot in two dimensions.
33
"""
4-
import os
5-
4+
import pygmt
65
from pygmt.clib import Session
76
from pygmt.exceptions import GMTInvalidInput
87
from pygmt.helpers import (
@@ -209,11 +208,18 @@ def plot(self, x=None, y=None, data=None, size=None, direction=None, **kwargs):
209208
extra_arrays = []
210209
if "S" in kwargs and kwargs["S"][0] in "vV" and direction is not None:
211210
extra_arrays.extend(direction)
212-
if "S" not in kwargs and kind == "file" and os.path.exists(data):
213-
with open(data, "r") as file:
214-
line = file.readline()
215-
if "@GMULTIPOINT" in line or "@GPOINT" in line:
216-
kwargs["S"] = "s0.2c"
211+
if (
212+
"S" not in kwargs and kind == "file"
213+
): # chacking that the data is a file path to set defualt style
214+
try:
215+
with open(pygmt.which(data), "r") as file:
216+
line = file.readline()
217+
if (
218+
"@GMULTIPOINT" in line or "@GPOINT" in line
219+
): # if the file is gmt style and geometry is set to Point
220+
kwargs["S"] = "s0.2c"
221+
except FileNotFoundError:
222+
pass
217223
if "G" in kwargs and not isinstance(kwargs["G"], str):
218224
if kind != "vectors":
219225
raise GMTInvalidInput(

0 commit comments

Comments
 (0)