diff --git a/preprocessor/preprocessor/steps/calc.py b/preprocessor/preprocessor/steps/calc.py index ad27cdb6699383c134a4eadb0909c5068790567b..a208a417b238e4182d8eb2b1245f545be08daf4a 100644 --- a/preprocessor/preprocessor/steps/calc.py +++ b/preprocessor/preprocessor/steps/calc.py @@ -1,9 +1,5 @@ import os -from os.path import basename, dirname, join -from math import ceil, floor -import logging -import uuid -import os +from os.path import basename, dirname, join, isfile import subprocess from typing import List from glob import glob @@ -21,6 +17,10 @@ def calc_step(source_dir: os.PathLike, target_dir: os.PathLike, formulas: List[d target_dir, replace_ext(basename(filename), item.get('output_postfix', '_proc%d' % i) + '.tif', False) ) + # fail if a file would be overridden + # TODO: maybe just log an error + if isfile(target_filename): + raise Exception('Calc output filename %s already exists' % target_filename) calc_formula(source_dir, item['inputs'], target_filename, item['formula'], item.get('data_type', 'Float32')) diff --git a/preprocessor/preprocessor/steps/output.py b/preprocessor/preprocessor/steps/output.py index ac1bdd86ee83749f1b9007e8631994b4d58cb5c1..e7d99d2710cc3cd32d7c6a8b0c6a0aff1175f736 100644 --- a/preprocessor/preprocessor/steps/output.py +++ b/preprocessor/preprocessor/steps/output.py @@ -19,7 +19,7 @@ def output_step(source_dir: os.PathLike, target_dir: os.PathLike, options: dict= # warp each individual file warped_files = [] - for filename in glob(join(source_dir, '*')): + for filename in glob(join(source_dir, '*.tif')): target_filename = join(target_dir, replace_ext(basename(filename), extension)) gdal.Warp(target_filename, filename, options=gdal.WarpOptions( **options