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: skip files which are not tiff #53

Merged
merged 5 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions scripts/create_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from urllib.parse import urlparse

from aws_helper import get_bucket
from file_helper import is_tiff
from format_source import format_source
from linz_logger import get_log

Expand Down Expand Up @@ -51,6 +52,9 @@ def main() -> None: # pylint: disable=too-many-locals
output_files = []

for file in source:
if not is_tiff(file):
get_log().error("create_polygon_file_not_tiff_skipped", file=file)
paulfouquet marked this conversation as resolved.
Show resolved Hide resolved
continue
with tempfile.TemporaryDirectory() as tmp_dir:
source_file_name = os.path.basename(file)
uri_parse = file
Expand Down
4 changes: 4 additions & 0 deletions scripts/file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

def get_file_name_from_path(path: str) -> str:
return os.path.basename(path)


def is_tiff(path: str) -> bool:
return path.lower().endswith((".tiff", ".tif"))
5 changes: 5 additions & 0 deletions scripts/non_visual_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from typing import Any, Dict, List

from file_helper import is_tiff
from format_source import format_source
from gdal_helper import run_gdal
from linz_logger import get_log
Expand Down Expand Up @@ -84,6 +85,10 @@ def main() -> None:
srs = gdalsrsinfo_result.stdout

for file in source:
if not is_tiff(file):
get_log().error("non_visual_qa_file_not_tiff_skipped", file=file)
continue

gdalinfo_command = ["gdalinfo", "-stats", "-json"]
gdalinfo_process = run_gdal(gdalinfo_command, file)
gdalinfo_result = {}
Expand Down
5 changes: 4 additions & 1 deletion scripts/standardising.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tempfile

from aws_helper import get_bucket, parse_path
from file_helper import get_file_name_from_path
from file_helper import get_file_name_from_path, is_tiff
from format_source import format_source
from gdal_helper import run_gdal
from linz_logger import get_log
Expand All @@ -24,6 +24,9 @@
gdal_env = os.environ.copy()

for file in source:
if not is_tiff(file):
get_log().error("standardising_file_not_tiff_skipped", file=file)
continue
with tempfile.TemporaryDirectory() as tmp_dir:
src_bucket_name, src_file_path = parse_path(file)
standardized_file_name = f"standardized_{get_file_name_from_path(src_file_path)}"
Expand Down
13 changes: 13 additions & 0 deletions scripts/tests/file_helper_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from file_helper import is_tiff


def test_is_tiff() -> None:
file_a = "file.tiff"
file_b = "file.tif"
file_c = "file.TIFF"
file_d = "file.jpg"

assert is_tiff(file_a) is True
assert is_tiff(file_b) is True
assert is_tiff(file_c) is True
assert is_tiff(file_d) is False