Skip to content

Commit

Permalink
fix: move command to common loc
Browse files Browse the repository at this point in the history
  • Loading branch information
MDavidson17 committed Aug 23, 2023
1 parent 8e456b6 commit d841a7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 20 additions & 0 deletions scripts/gdal/gdal_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,23 @@ def get_transform_srs_command(source_epsg: str, target_epsg: str) -> List[str]:
"-r",
"bilinear",
]


def get_ascii_translate_command() -> List[str]:
"""Get a `translate` command to transform the ascii files to tiff.
Args:
Returns:
a list of arguments to run `gdal_translate`
"""
return [
"gdal_translate",
"-of",
"GTiff",
# Ensure all CPUs are used for gdal translate
"-co",
"num_threads=all_cpus",
"-co",
"COMPRESS=lzw",
]
6 changes: 2 additions & 4 deletions scripts/translate_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import os
import tempfile

from scripts.aws.aws_helper import get_session, is_s3
from scripts.files.fs import find_sidecars, write_all
from scripts.files.fs_s3 import bucket_name_from_path, list_uri
from scripts.gdal.gdal_helper import run_gdal
from scripts.gdal.gdal_preset import get_ascii_translate_command


def main() -> None:
Expand Down Expand Up @@ -33,8 +32,7 @@ def main() -> None:
# translate from ascii to geotiff using GDAL
filename = os.path.splitext(os.path.basename(asc))[1]
tiff = os.path.join(tmp_path, f"{filename}.tiff")
command = ["gdal_translate", "-of", "GTiff", asc, tiff]
run_gdal(command)
run_gdal(get_ascii_translate_command(), input_file=asc, output_file=tiff)
tiffs.append(tiff)
write_all(inputs=tiffs, target=arguments.target)

Expand Down

0 comments on commit d841a7e

Please sign in to comment.