Commit 85db94cb authored by Daniel Scheffler's avatar Daniel Scheffler

Added GDAL cache flushing.

parent 93cd35d6
Pipeline #3066 failed with stages
in 1 minute and 18 seconds
......@@ -900,16 +900,21 @@ class GeoArray(object):
os.makedirs(os.path.dirname(out_path))
if self.is_inmem:
ds = get_GDAL_ds_inmem(self.arr, self.geotransform, self.projection,
self.nodata) # expects rows,columns,bands
ds_inmem = get_GDAL_ds_inmem(self.arr, self.geotransform, self.projection,
self.nodata) # expects rows,columns,bands
# write dataset
ds_out = driver.CreateCopy(out_path, ds_inmem, options=creationOptions if creationOptions else [])
del ds_inmem
# set metadata
# NOTE: The dataset has to be written BEFORE metadata are added. Otherwise, metadata are not written.
if not self.metadata.empty:
global_meta = {}
# set band domain metadata
for bidx in range(self.bands):
band = ds.GetRasterBand(bidx + 1)
band = ds_out.GetRasterBand(bidx + 1)
meta2write = self.metadata[bidx].to_dict()
meta2write = dict((k, repr(v)) for k, v in meta2write.items() if v is not np.nan)
......@@ -923,7 +928,7 @@ class GeoArray(object):
# set global domain metadata
if global_meta:
ds.SetMetadata(global_meta)
ds_out.SetMetadata(global_meta)
# get ENVI metadata domain
# ds_orig = gdal.Open(self.filePath)
......@@ -931,14 +936,12 @@ class GeoArray(object):
# ds.SetMetadata(envi_meta_domain, 'ENVI')
# ds_orig = None
ds.FlushCache()
driver.CreateCopy(out_path, ds, options=creationOptions if creationOptions else [])
ds_out.FlushCache()
# rows, columns, bands => bands, rows, columns
# out_arr = self.arr if self.ndim == 2 else np.swapaxes(np.swapaxes(self.arr, 0, 2), 1, 2)
# gdalnumeric.SaveArray(out_arr, out_path, format=fmt, prototype=ds) # expects bands,rows,columns
del ds
del ds_out
else:
src_ds = gdal.Open(self.filePath)
......@@ -1310,7 +1313,7 @@ class GeoArray(object):
image2plot = data
plt.figure(figsize=figsize)
plt.hist(list(image2plot.flat), normed=normed, bins=bins, color='gray', range=[vmin, vmax])
plt.hist(list(image2plot.flat), density=normed, bins=bins, color='gray', range=[vmin, vmax])
plt.xlabel('Pixel value')
plt.ylabel('Probabilty' if normed else 'Count')
plt.show()
......
......@@ -384,13 +384,11 @@ class Test_GeoarrayFunctions(unittest.TestCase):
# Opening the temporary serialized variables (see setUpClass of test case 1) to re-use in the new test case
# without the need to inherit the variables from test case 1.
if cls.k == 0:
with open(os.path.join(tests_path, "tests", "data", "output", "testtiff_path.tmp"), "rb") as f:
cls.testtiff = dill.load(f)
assert cls.k in [0, 1]
fN = "testtiff_path.tmp" if cls.k == 0 else "testtiff_array.tmp"
if cls.k == 1:
with open(os.path.join(tests_path, "tests", "data", "output", "testtiff_array.tmp"), "rb") as f:
cls.testtiff = dill.load(f)
with open(os.path.join(tests_path, "tests", "data", "output", fN), "rb") as f:
cls.testtiff = dill.load(f)
@classmethod
def tearDownClass(cls):
......@@ -601,7 +599,7 @@ if __name__ == '__main__':
# Creating a test suite for the first test case
suite = unittest.TestSuite()
loader = TestLoader()
test = None
test = Test_GeoarrayAppliedOnPathArray
test.k = k
......@@ -630,7 +628,7 @@ if __name__ == '__main__':
# will be removed in the else-statement.
if testResult.wasSuccessful() and testResult.skipped == []:
other_suite = unittest.TestSuite()
more_test = None
more_test = Test_GeoarrayFunctions
more_test.k = k
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment