Skip to content

Commit

Permalink
Merge pull request #2 from NASA-IMPACT/sr_hdf
Browse files Browse the repository at this point in the history
Return invalid for fmask valid pixels less than 2%.
  • Loading branch information
sharkinsspatial authored Sep 17, 2020
2 parents 234190f + cb453b1 commit 79b86ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
14 changes: 10 additions & 4 deletions parse_fmask/parse_fmask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import re


@click.command()
Expand All @@ -7,11 +8,16 @@
type=click.STRING,
)
def main(fmaskoutput):
lines = fmaskoutput.splitlines()
if "0.00%" in lines[len(lines) - 3]:
click.echo("invalid")
else:
result = re.search(r"\d+%|([0-9]\d?)\.\d", fmaskoutput)
if result is None:
click.echo("valid")
else:
clear_percentage = result.group()
value = float(clear_percentage)
if value < 2:
click.echo("invalid")
else:
click.echo("valid")


if __name__ == "__main__":
Expand Down
33 changes: 13 additions & 20 deletions tests/test_parse_fmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@


def test_parse_fmask_invalid():
fmaskoutput = \
"""Fmask 4.2 start ...
Cloud/cloud shadow/snow dilated by 3/3/0 pixels.
probability threshold of 20.00%.
or calculate TOA reflectances.
potential clouds, cloud shadows, snow, and water.
clear pixel in this image (clear-sky pixels = 102Fmask 4.2 finished (3.95 minutes)
for L1C_T37WFN_A017436_20200708T084600 with 0.00% clear pixels
Input file size is 5490, 5490
0...10...20...30...40...50...60...70...80...90...100 - done."""
fmaskoutput = "for L1C_T37WFN_A017436_20200708T084600 with 0.01% clear pixels"

runner = CliRunner(echo_stdin=True)
result = runner.invoke(main, [
Expand All @@ -23,16 +14,18 @@ def test_parse_fmask_invalid():


def test_parse_fmask_valid():
fmaskoutput = \
"""Fmask 4.2 start ...
Cloud/cloud shadow/snow dilated by 3/3/0 pixels.
probability threshold of 20.00%.
or calculate TOA reflectances.
potential clouds, cloud shadows, snow, and water.
clear pixel in this image (clear-sky pixels = 102Fmask 4.2 finished (3.95 minutes)
for L1C_T37WFN_A017436_20200708T084600 with 99.01% clear pixels
Input file size is 5490, 5490
0...10...20...30...40...50...60...70...80...90...100 - done."""
fmaskoutput = "for L1C_T23XNB_A017440_20200708T152810 with 21.03% clear pixels"

runner = CliRunner(echo_stdin=True)
result = runner.invoke(main, [
fmaskoutput
], catch_exceptions=False)
assert result.exit_code == 0
assert result.stdout == "valid\n"


def test_parse_fmask_no_percent():
fmaskoutput = "for L1C_T23XNB_A017440_20200708T152810 with clear pixels"

runner = CliRunner(echo_stdin=True)
result = runner.invoke(main, [
Expand Down

0 comments on commit 79b86ad

Please sign in to comment.