Skip to content

Commit d7a17f2

Browse files
committed
Set default BandInfo.band_{quantity,unit} to None (fixes #46).
When reading ENVI files, the band_quantity attribute of the SpyFile's BandInfo object was being set to "Wavelength". While that is usually the case, it is not always. Now, that assumption is no longer made and the band_quantity and band_unit attributes are defaulted to None in the BandInfo object (the previous default was an empty string). * graphics/spypylab.py: (plot): Handle band_quantity and band_unit default value None. * io/envi.py: (open): band_quantity defaults to None instead of "Wavelength". If "wavelength units" is not specified in the header, default band_unit to None instead of empty string. (add_band_info_to_metadata): Handle and band_unit default value None. * spectral.py: (BandInfo.__init__): Initialize band_quantity and band_unit to None.
1 parent 8bbf5df commit d7a17f2

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

spectral/graphics/spypylab.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,15 @@ def plot(data, source=None):
13011301
spectral._xyplot = p
13021302
plt.grid(1)
13031303
if source is not None and hasattr(source, 'bands'):
1304-
xlabel = source.bands.band_quantity
1305-
if len(source.bands.band_unit) > 0:
1306-
xlabel = xlabel + ' (' + source.bands.band_unit + ')'
1304+
if source.bands.band_quantity is not None:
1305+
xlabel = source.bands.band_quantity
1306+
else:
1307+
xlabel = ''
1308+
if source.bands.band_unit is not None:
1309+
if len(xlabel) > 0:
1310+
xlabel += ' (%s)' % source.bands.band_unit
1311+
else:
1312+
xlabel = str(source.bands.band_unit)
13071313
plt.xlabel(xlabel)
13081314
return p
13091315

spectral/io/envi.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ def open(file, image=None):
351351
img.bands.bandwidths = [float(f) for f in h['fwhm']]
352352
except:
353353
pass
354-
img.bands.band_unit = h.get('wavelength units', "")
355-
img.bands.band_quantity = "Wavelength"
354+
img.bands.band_unit = h.get('wavelength units', None)
356355

357356
return img
358357

@@ -666,8 +665,8 @@ def add_band_info_to_metadata(bands, metadata, overwrite=False):
666665
if bands.bandwidths is not None and (overwrite is True or
667666
'fwhm' not in metadata):
668667
metadata['fwhm'] = bands.bandwidths
669-
if len(bands.band_unit) > 0 and (overwrite is True or
670-
'wavelength units' not in metadata):
668+
if bands.band_unit is not None and (overwrite is True or
669+
'wavelength units' not in metadata):
671670
metadata['wavelength units'] = bands.band_unit
672671

673672

spectral/spectral.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ def __init__(self):
221221
self.bandwidths = None
222222
self.centers_stdevs = None
223223
self.bandwidth_stdevs = None
224-
self.band_quantity = ""
225-
self.band_unit = ""
224+
self.band_quantity = None
225+
self.band_unit = None
226226

227227

228228
class Image(object):

0 commit comments

Comments
 (0)