Skip to content

Commit

Permalink
fix: non-visual QA greyscale TDE-832 (#593)
Browse files Browse the repository at this point in the history
* fix: non-visual qa handle greyscale TDE-832

* fix: revert variable name and fix typo

* fix: formatting

* fix: remove print statement
  • Loading branch information
amfage authored Aug 10, 2023
1 parent 770039b commit afe25f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 6 additions & 5 deletions scripts/files/file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def is_error_type(self, error_type: FileTiffErrorType) -> bool:
return False

def check_no_data(self, gdalinfo: GdalInfo) -> None:
"""Add a Non Visual QA error if there is no "noDataValue" or the "noDataValue" is not equal to 255
or -9999 for DEM in the "bands".
"""Add a Non Visual QA error if there is no "noDataValue" and no alpha band for non-DEMs,
or the "noDataValue" is not equal to 255, or -9999 for DEM in the "bands".
Args:
gdalinfo: `gdalinfo` output
Expand Down Expand Up @@ -240,7 +240,7 @@ def is_no_data(self, gdalinfo: GdalInfo) -> bool:
return False

def check_band_count(self, gdalinfo: GdalInfo) -> None:
"""Add a Non Visual QA error if there is not exactly 3 or 4 bands found.
"""Add a Non Visual QA error if there is not exactly 3 or 4 bands found, or 1 band if DEM.
Args:
gdalinfo: `gdalinfo` output
Expand Down Expand Up @@ -272,22 +272,23 @@ def check_srs(self, gdalsrsinfo_tif: bytes) -> None:
self.add_error(error_type=FileTiffErrorType.SRS, error_message="srs not defined")

def check_color_interpretation(self, gdalinfo: GdalInfo) -> None:
"""Add a Non Visual QA error if the colors don't match RGB.
"""Add a Non Visual QA error if the colors don't match RGB or greyscale.
Args:
gdalinfo: `gdalinfo` output
"""
bands = gdalinfo["bands"]
missing_bands = []
band_colour_ints = {1: "Red", 2: "Green", 3: "Blue"}
band_greyscale_ints = {1: "Gray", 2: "Gray", 3: "Gray"}
optional_colour_ints = {4: "Alpha"}
if self._tiff_type == "DEM":
band_colour_ints = {1: "Gray"}
n = 1
for band in bands:
colour_int = band["colorInterpretation"]
if n in band_colour_ints:
if colour_int != band_colour_ints[n]:
if colour_int not in (band_colour_ints[n], band_greyscale_ints[n]):
missing_bands.append(f"band {n} {colour_int}")
elif n in optional_colour_ints:
if colour_int != optional_colour_ints[n]:
Expand Down
19 changes: 17 additions & 2 deletions scripts/files/tests/file_tiff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def test_check_band_count_invalid_3_DEM() -> None:
assert file_tiff.get_errors()


def test_check_color_interpretation_valid() -> None:
def test_check_color_interpretation_valid_rgb() -> None:
"""
tests check_color_interpretation with the correct color interpretation
tests check_color_interpretation with the correct RGB color interpretation
"""
gdalinfo = fake_gdal_info()
add_band(gdalinfo, color_interpretation="Red")
Expand All @@ -126,6 +126,21 @@ def test_check_color_interpretation_valid() -> None:
assert not file_tiff.get_errors()


def test_check_color_interpretation_valid_greyscale() -> None:
"""
tests check_color_interpretation with the correct greyscale color interpretation
"""
gdalinfo = fake_gdal_info()
add_band(gdalinfo, color_interpretation="Gray")
add_band(gdalinfo, color_interpretation="Gray")
add_band(gdalinfo, color_interpretation="Gray")

file_tiff = FileTiff(["test"])
file_tiff.check_color_interpretation(gdalinfo)

assert not file_tiff.get_errors()


def test_check_color_interpretation_invalid() -> None:
"""
tests check_color_interpretation with the incorrect color interpretation
Expand Down

0 comments on commit afe25f3

Please sign in to comment.