Skip to content

Commit 0817e41

Browse files
committed
Handle bad band list (bbl) in headers and do not display bbl values in spectral plots.
1 parent 5add07c commit 0817e41

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

spectral/graphics/spypylab.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,24 +1280,22 @@ def plot(data, source=None):
12801280

12811281
set_mpl_interactive()
12821282

1283-
s = np.shape(data)
1284-
12851283
if source is not None and hasattr(source, 'bands'):
12861284
xvals = source.bands.centers
12871285
else:
1288-
xvals = None
1289-
1290-
if len(s) == 1:
1291-
if not xvals:
1292-
xvals = list(range(len(data)))
1293-
p = plt.plot(xvals, data)
1294-
elif len(s) == 2:
1295-
if not xvals:
1296-
xvals = list(range(s[1]))
1297-
p = plt.plot(xvals, data[0, :])
1286+
xvals = list(range(data.shape[-1]))
1287+
1288+
if data.ndim == 1:
1289+
data = data[np.newaxis, :]
1290+
data = data.reshape(-1, data.shape[-1])
1291+
if source is not None and hasattr(source, 'metadata') and \
1292+
'bbl' in source.metadata:
1293+
# Do not plot bad bands
1294+
data = np.array(data)
1295+
data[:, np.array(source.metadata['bbl']) == 0] = None
1296+
for x in data:
1297+
p = plt.plot(xvals, x)
12981298
plt.hold(1)
1299-
for i in range(1, s[0]):
1300-
p = plt.plot(xvals, data[i, :])
13011299
spectral._xyplot = p
13021300
plt.grid(1)
13031301
if source is not None and hasattr(source, 'bands'):

spectral/io/envi.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ def open(file, image=None):
366366
pass
367367
img.bands.band_unit = h.get('wavelength units', None)
368368

369+
if 'bbl' in h:
370+
try:
371+
h['bbl'] = [int(b) for b in h['bbl']]
372+
except:
373+
print('Unable to parse bad band list (bbl) in header as integers.')
369374
return img
370375

371376

@@ -599,6 +604,7 @@ def _prepared_data_and_metadata(hdr_file, image, **kwargs):
599604
if len(data.shape) == 2:
600605
data = data[:, :, np.newaxis]
601606
swap = False
607+
metadata = {}
602608
elif isinstance(image, SpyFile):
603609
if image.using_memmap is True:
604610
data = image._memmap
@@ -609,12 +615,17 @@ def _prepared_data_and_metadata(hdr_file, image, **kwargs):
609615
data = image.load(dtype=image.dtype, scale=False)
610616
src_interleave = 'bip'
611617
swap = False
618+
metadata = image.metadata.copy()
612619
else:
613-
data = image.load()
620+
data = image.load(scale=False)
614621
src_interleave = 'bip'
615622
swap = False
623+
if hasattr(image, 'metadata'):
624+
metadata = image.metadata.copy()
625+
else:
626+
metadata = {}
616627

617-
metadata = kwargs.get('metadata', {}).copy()
628+
metadata.update(kwargs.get('metadata', {}))
618629
add_image_info_to_metadata(image, metadata)
619630
if hasattr(image, 'bands'):
620631
add_band_info_to_metadata(image.bands, metadata)

0 commit comments

Comments
 (0)