diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b38618820ff57512c77f9ada84ebf454572658c8..2e7f1865220b46ad055f2e13e46a88023d888f66 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/geoarray/baseclasses.py b/geoarray/baseclasses.py index cde614378584f1993d77dc304af2a6b84a995e33..01030fd4faca32ba69b14ce95eb9f29f4b0112e0 100644 --- a/geoarray/baseclasses.py +++ b/geoarray/baseclasses.py @@ -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: diff --git a/tests/CI_docker/context/environment_geoarray.yml b/tests/CI_docker/context/environment_geoarray.yml index f5c2e0e9f487c1b28a0c9f847472700ea76fde70..2bb3fe1fd09faf25904129da9a38fa80c9200c3c 100644 --- a/tests/CI_docker/context/environment_geoarray.yml +++ b/tests/CI_docker/context/environment_geoarray.yml @@ -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