Skip to content

Commit

Permalink
Merge pull request #9 from constantinius/tci_path
Browse files Browse the repository at this point in the history
Adding method to get the internal path to the TCI file.
  • Loading branch information
ungarj committed Aug 22, 2017
2 parents c1935fe + ea10bf9 commit 8112038
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions s2reader/s2reader.py
Expand Up @@ -285,6 +285,25 @@ def pvi_path(self):
"""Determine the PreView Image (PVI) path inside the SAFE pkg."""
return _pvi_path(self)

@cached_property
def tci_path(self):
"""Return the path to the granules TrueColorImage."""
tci_paths = [
path for path in self.dataset._product_metadata.xpath(
".//Granule[@granuleIdentifier='%s']/IMAGE_FILE/text()"
% self.granule_identifier
) if path.endswith('TCI')
]
try:
tci_path = tci_paths[0]
except IndexError:
return None

return os.path.join(
self.dataset._zip_root if self.dataset.is_zip else self.dataset.path,
tci_path
) + '.jp2'

@cached_property
def cloud_percent(self):
"""Return percentage of cloud coverage."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_s2reader.py
Expand Up @@ -80,6 +80,8 @@ def _test_attributes(test_data, safe_path):
assert isinstance(granule.metadata_path, str)
if granule.pvi_path:
assert isinstance(granule.pvi_path, str)
if granule.tci_path:
assert isinstance(granule.tci_path, str)
assert isinstance(granule.cloud_percent, float)
assert granule.footprint.is_valid
assert granule.cloudmask.is_valid
Expand Down

0 comments on commit 8112038

Please sign in to comment.