Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sentinel 2 sceneid parser for single-digit UTM zones #34

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next (TBD)

* fix issue where the sequence number of a sentinel scene id can be two digit (ref: https://github.com/cogeotiff/rio-tiler-pds/pull/35)
* fix issue where `utm` is only one sigle digit (ref: https://github.com/cogeotiff/rio-tiler-pds/pull/34)

## 0.4.1 (2020-11-24)

Expand Down
8 changes: 4 additions & 4 deletions rio_tiler_pds/sentinel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def s2_sceneid_parser(sceneid: str) -> Dict:

"""
if re.match(
"^S2[AB]_L[0-2][A-C]_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]{1,2}$", sceneid
"^S2[AB]_L[0-2][A-C]_[0-9]{8}_[0-9]{1,2}[A-Z]{3}_[0-9]{1,2}$", sceneid
): # Legacy sceneid format
pattern = (
r"^S"
Expand All @@ -40,22 +40,22 @@ def s2_sceneid_parser(sceneid: str) -> Dict:
r"(?P<acquisitionMonth>[0-9]{2})"
r"(?P<acquisitionDay>[0-9]{2})"
r"_"
r"(?P<utm>[0-9]{2})"
r"(?P<utm>[0-9]{1,2})"
r"(?P<lat>\w{1})"
r"(?P<sq>\w{2})"
r"_"
r"(?P<num>[0-9]{1,2})$"
)

elif re.match(
"^S2[AB]_[0-9]{2}[A-Z]{3}_[0-9]{8}_[0-9]{1,2}_L[0-2][A-C]$", sceneid
"^S2[AB]_[0-9]{1,2}[A-Z]{3}_[0-9]{8}_[0-9]{1,2}_L[0-2][A-C]$", sceneid
): # New sceneid format
pattern = (
r"^S"
r"(?P<sensor>\w{1})"
r"(?P<satellite>[AB]{1})"
r"_"
r"(?P<utm>[0-9]{2})"
r"(?P<utm>[0-9]{1,2})"
r"(?P<lat>\w{1})"
r"(?P<sq>\w{2})"
r"_"
Expand Down
23 changes: 23 additions & 0 deletions tests/test_sentinel2.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,29 @@ def test_sentinel_newid_valid():
assert s2_sceneid_parser(SENTINEL_SCENE_L1) == expected_content


def test_sentinel_newid_valid_single_digit_utm():
"""Parse sentinel-2 valid sceneid and return metadata for single-digit UTM zone."""
expected_content = {
"sensor": "2",
"satellite": "B",
"processingLevel": "L2A",
"acquisitionYear": "2018",
"acquisitionMonth": "10",
"acquisitionDay": "02",
"utm": "2",
"lat": "C",
"sq": "MA",
"num": "0",
"scene": "S2B_2CMA_20181002_0_L2A",
"date": "2018-10-02",
"_utm": "2",
"_month": "10",
"_day": "2",
"_levelLow": "l2a",
}
assert s2_sceneid_parser("S2B_2CMA_20181002_0_L2A") == expected_content


def test_sentinel_newidl2a_valid():
"""Parse sentinel-2 valid sceneid and return metadata."""
expected_content = {
Expand Down