Raise IOError when parent dir not found
This commit is contained in:
parent
55013a04dd
commit
33b3f6166e
@ -24,6 +24,10 @@ np_to_gdt = {
|
|||||||
def write(fname, X):
|
def write(fname, X):
|
||||||
"""X.shape = (length, width) or
|
"""X.shape = (length, width) or
|
||||||
X.shape = (length, width, samples)"""
|
X.shape = (length, width, samples)"""
|
||||||
|
|
||||||
|
fname = Path(fname)
|
||||||
|
if not fname.parent.exists():
|
||||||
|
raise IOError('Directory not found: {}'.format(fname.parent))
|
||||||
|
|
||||||
width = X.shape[1]
|
width = X.shape[1]
|
||||||
length = X.shape[0]
|
length = X.shape[0]
|
||||||
@ -38,7 +42,7 @@ def write(fname, X):
|
|||||||
dst_ds = driver.Create(str(fname), width, length, samples, np_to_gdt[X.dtype.type])
|
dst_ds = driver.Create(str(fname), width, length, samples, np_to_gdt[X.dtype.type])
|
||||||
|
|
||||||
for i in range(samples):
|
for i in range(samples):
|
||||||
dst_ds.GetRasterBand(i + 1).WriteArray(X[:,:,i].astype(np.uint8))
|
dst_ds.GetRasterBand(i + 1).WriteArray(X[:,:,i])
|
||||||
dst_ds.FlushCache()
|
dst_ds.FlushCache()
|
||||||
|
|
||||||
def read(fname):
|
def read(fname):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user