Commit 8a3b342b authored by Daniel Scheffler's avatar Daniel Scheffler

Fixed issue that bandnames are not written to ENVI header by GeoArray.save().

parent 297fa33f
Pipeline #3070 passed with stages
in 1 minute and 25 seconds
......@@ -41,6 +41,7 @@ test_styles:
- source /root/miniconda3/bin/activate
- export GDAL_DATA=/root/miniconda3/share/gdal
- export PYTHONPATH=$PYTHONPATH:/root # /root <- directory needed later
- pip install "pycodestyle>=2.0.0,!=2.4.0" # TODO remove as soon as docker runner is recreated
- make lint
artifacts:
paths:
......
......@@ -159,21 +159,26 @@ class GeoArray(object):
# type: (list) -> None
if list_bandnames:
assert isinstance(list_bandnames, list), "A list must be given when setting the 'bandnames' attribute. " \
"Received %s." % type(list_bandnames)
assert len(list_bandnames) == self.bands, \
'Number of given bandnames does not match number of bands in array.'
assert len(list(set([type(b) for b in list_bandnames]))) == 1 and type(list_bandnames[0] == 'str'), \
"'bandnames must be a set of strings. Got other datetypes in there.'"
if not isinstance(list_bandnames, list):
raise TypeError("A list must be given when setting the 'bandnames' attribute. "
"Received %s." % type(list_bandnames))
if len(list_bandnames) != self.bands:
raise ValueError('Number of given bandnames does not match number of bands in array.')
if len(list(set([type(b) for b in list_bandnames]))) != 1 or not isinstance(list_bandnames[0], str):
raise ValueError("'bandnames must be a set of strings. Got other datatypes in there.'")
bN_dict = OrderedDict((band, i) for i, band in enumerate(list_bandnames))
assert len(bN_dict) == self.bands, \
'Bands must not have the same name. Received band list: %s' % list_bandnames
if len(bN_dict) != self.bands:
raise ValueError('Bands must different names. Received band list: %s' % list_bandnames)
self._bandnames = bN_dict
# update bandnames in metadata
if self._metadata is not None:
try:
self.metadata.band_meta['band_names'] = list_bandnames
except AttributeError:
# in case self._metadata is None
pass
else:
del self.bandnames
......@@ -893,6 +898,12 @@ class GeoArray(object):
# write dataset
ds_out = driver.CreateCopy(out_path, ds_inmem, options=creationOptions if creationOptions else [])
# # 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_inmem) # expects bands,rows,columns
# ds_out = gdal.Open(out_path)
del ds_inmem
################
......@@ -909,7 +920,10 @@ class GeoArray(object):
if 'band_names' in envi_metadict:
for bidx in range(self.bands):
band = ds_out.GetRasterBand(bidx + 1)
band.SetDescription(self.metadata.band_meta['band_names'][bidx].strip())
bandname = self.metadata.band_meta['band_names'][bidx].strip()
band.SetDescription(bandname)
assert band.GetDescription() == bandname
del band
if 'description' in envi_metadict:
......@@ -939,10 +953,6 @@ class GeoArray(object):
del band
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_out
else:
......
......@@ -33,7 +33,7 @@ dependencies:
- six
- spectral
- flake8
- pycodestyle
- pycodestyle<2.4.0 # fixes ImportError: module 'pycodestyle' has no attribute 'break_around_binary_operator'
- pylint
- pydocstyle
- nose
......
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