Skip to content

Commit

Permalink
Enhance errors handling in GMT module
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Feb 28, 2024
1 parent a2ccf6c commit 4b3aeb7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pygmtsar/pygmtsar/GMT.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ def load_earth_relief(bounds, product, filename):
#print ('gmt grdcut argv:', ' '.join(argv))
p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8')
stdout_data, stderr_data = p.communicate()
if p.returncode != 0 or len(stderr_data.strip()) > 0:
if p.returncode != 0 or not os.path.exists(filename):
print('Error executing external command "gmt grdcut":')
raise ValueError(stderr_data)
return stdout_data.strip()
return stdout_data

if product in ['SRTM1', '1s', '01s']:
resolution = '01s'
Expand Down Expand Up @@ -237,10 +237,10 @@ def grdlandmask(bounds, product, resolution, filename):
#print ('grdlandmask argv:', ' '.join(argv))
p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8')
stdout_data, stderr_data = p.communicate()
if p.returncode != 0 or len(stderr_data.strip()) > 0:
if p.returncode != 0 or not os.path.exists(filename):
print('Error executing external command "gmt grdlandmask":')
raise ValueError(stderr_data)
return stdout_data.strip()
return stdout_data

if filename is not None and os.path.exists(filename) and skip_exist:
print ('NOTE: landmask file exists, ignore the command. Use "skip_exist=False" or omit the filename to allow new downloading')
Expand Down

0 comments on commit 4b3aeb7

Please sign in to comment.