Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Scheffler
geoarray
Commits
b692590c
Commit
b692590c
authored
Jan 13, 2022
by
Daniel Scheffler
Browse files
Fix exception in case of int and float bandnames in the input.
parent
3773e3e9
Pipeline
#37151
passed with stage
in 2 minutes and 10 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
geoarray/baseclasses.py
View file @
b692590c
...
...
@@ -199,8 +199,11 @@ class GeoArray(object):
"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.'"
)
if
len
(
list
(
set
([
type
(
b
)
for
b
in
list_bandnames
])))
!=
1
:
raise
ValueError
(
'Multiple data types of the band names are not supported.'
)
if
not
isinstance
(
list_bandnames
[
0
],
(
str
,
int
,
float
)):
raise
ValueError
(
f
'Band names must be a set of strings, integers, or floats. '
f
'Got
{
type
(
list_bandnames
[
0
])
}
'
)
bN_dict
=
OrderedDict
((
band
,
i
)
for
i
,
band
in
enumerate
(
list_bandnames
))
...
...
@@ -1054,7 +1057,7 @@ class GeoArray(object):
band
=
ds_out
.
GetRasterBand
(
bidx
+
1
)
if
'band_names'
in
envi_metadict
:
bandname
=
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
].
strip
()
bandname
=
str
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
]
)
.
strip
()
band
.
SetDescription
(
bandname
)
assert
band
.
GetDescription
()
==
bandname
...
...
@@ -1113,7 +1116,8 @@ class GeoArray(object):
# meta2write = dict((k, repr(v)) for k, v in self.metadata.band_meta.items() if v is not np.nan)
if
'band_names'
in
bandmeta
:
band
.
SetDescription
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
].
strip
())
bandname
=
str
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
]).
strip
()
band
.
SetDescription
(
bandname
)
del
bandmeta
[
'band_names'
]
if
'nodata'
in
bandmeta
:
...
...
tests/test_geoarray.py
View file @
b692590c
...
...
@@ -506,7 +506,9 @@ class Test_GeoArray(TestCase):
gdalinfo_orig
=
[
i
+
'
\n
'
for
i
in
getoutput
(
f
'gdalinfo -mdd ENVI
{
path_subset_bsq
}
'
).
split
(
'
\n
'
)]
diff
=
''
.
join
(
list
(
unified_diff
(
gdalinfo_orig
[
3
:],
gdalinfo_out
[
3
:])))
self
.
assertFalse
(
diff
)
self
.
assertFalse
(
diff
,
f
'
\n\n
The gdalinfo output of the saved dataset contains some unexpected differences:
\n\n
'
f
'
{
diff
}
'
)
# compare header files
with
open
(
p_out
[:
-
4
]
+
'.hdr'
,
'r'
)
as
inF
:
...
...
@@ -530,7 +532,9 @@ class Test_GeoArray(TestCase):
gdalinfo_orig
=
[
i
+
'
\n
'
for
i
in
getoutput
(
f
'gdalinfo
{
path_subset_tif
}
'
).
split
(
'
\n
'
)]
diff
=
''
.
join
(
list
(
unified_diff
(
gdalinfo_orig
[
2
:],
gdalinfo_out
[
2
:])))
self
.
assertFalse
(
diff
)
self
.
assertFalse
(
diff
,
f
'
\n\n
The gdalinfo output of the saved dataset contains some unexpected differences:
\n\n
'
f
'
{
diff
}
'
)
# os.system(f'gdalinfo {p_out}')
def
test_show
(
self
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment