Raise IOError when file not found

This commit is contained in:
Florent Guiotte 2018-04-09 18:25:12 +02:00
parent 4f8cb4b421
commit a2297e8441

View File

@ -8,6 +8,7 @@
#
# TODO details
from pathlib import Path
import numpy as np
import gdal
@ -41,7 +42,12 @@ def write(fname, X):
dst_ds.FlushCache()
def read(fname):
gdl_data = gdal.Open(str(fname))
pname = Path(fname)
if not pname.exists():
raise IOError('File not found: {}'.format(pname))
gdl_data = gdal.Open(pname.as_posix())
if gdl_data.RasterCount == 1:
return gdl_data.ReadAsArray()