Skip to content

Commit

Permalink
Correctly parse band numbers with underscores (Landsat 7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyh committed Aug 5, 2015
1 parent 855dac0 commit 29da98d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions eodatasets/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,23 +426,26 @@ def to_band(self, dataset, path):
:type final_path: pathlib.Path
:rtype: ptype.BandMetadata
>>> OrthoDriver().to_band(None, Path('/tmp/out/L8_SOMETHING_B1.tif'))
BandMetadata(path=PosixPath('/tmp/out/L8_SOMETHING_B1.tif'), number='1')
>>> OrthoDriver().to_band(None, Path('/tmp/out/L8_SOMETHING_B12.tif'))
BandMetadata(path=PosixPath('/tmp/out/L8_SOMETHING_B12.tif'), number='12')
>>> OrthoDriver().to_band(None, Path('/tmp/out/LT51030782005002ASA00_B3.TIF'))
BandMetadata(path=PosixPath('/tmp/out/LT51030782005002ASA00_B3.TIF'), number='3')
>>> OrthoDriver().to_band(None, Path('/tmp/out/LC81090852015088LGN00_B10.tif'))
BandMetadata(path=PosixPath('/tmp/out/LC81090852015088LGN00_B10.tif'), number='10')
>>> OrthoDriver().to_band(None, Path('/data/output/LE70900782007292ASA00_B6_VCID_2.TIF'))
BandMetadata(path=PosixPath('/data/output/LE70900782007292ASA00_B6_VCID_2.TIF'), number='6_vcid_2')
>>> # No bands for non-tiff files.
>>> OrthoDriver().to_band(None, Path('/tmp/out/L8_SOMETHING_MTL.txt'))
>>> OrthoDriver().to_band(None, Path('/tmp/out/LC81090852015088LGN00_MTL.txt'))
>>> OrthoDriver().to_band(None, Path('/tmp/out/passinfo'))
"""
if path.suffix != '.tif':
if path.suffix.lower() != '.tif':
return None

name = path.stem.lower()
# Images end in a band number (eg '_B12.tif'). Extract it.
last_component = path.stem.split('_')[-1].lower()
if not last_component.startswith('b'):
position = name.rfind('_b')
if position == -1:
raise ValueError('Unexpected tif image in ortho: %r' % path)
band_number = name[position+2:]

# Strip the leading 'B'
band_number = last_component[1:]
return ptype.BandMetadata(path=path, number=band_number)

def get_ga_label(self, dataset):
Expand Down

0 comments on commit 29da98d

Please sign in to comment.