EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit 9f74c327 authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Fixes to calc step

parent d560b3e2
No related branches found
No related tags found
No related merge requests found
......@@ -4,29 +4,36 @@ import subprocess
from typing import List
from glob import glob
import shutil
import logging
from osgeo import gdal, osr
from ..util import replace_ext
logger = logging.getLogger(__name__)
def calc_step(source_dir: os.PathLike, target_dir: os.PathLike, formulas: List[dict]):
for i, item in enumerate(formulas):
# get first filename as a base
filename = next(glob(join(source_dir, item['inputs']['glob'])))
filename = glob(join(source_dir, list(item['inputs'].values())[0]['glob']))
target_filename = join(
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)
logger.warn('Calc output filename %s already exists' % target_filename)
calc_formula(source_dir, item['inputs'], target_filename, item['formula'], item.get('data_type', 'Float32'))
# take all original files with from the last step
for filename in glob('%s/*' % source_dir):
shutil.copy(filename, join(target_dir, basename(filename)))
target_filename = join(target_dir, basename(filename))
if isfile(target_filename):
logger.warn('Calc output filename %s already exists' % target_filename)
shutil.copy(filename, target_filename)
def calc_formula(source_dir: os.PathLike, inputs: List[dict], target_filename: os.PathLike, formula: str, data_type: str="Float32", nodata_value: float=None):
......@@ -39,10 +46,10 @@ def calc_formula(source_dir: os.PathLike, inputs: List[dict], target_filename: o
for name, locator in inputs:
# select first
filename = next(glob(join(source_dir, locator['glob'])))
filename = glob(join(source_dir, locator['glob']))[0]
cmd.extend([
"-%s" % name, filename,
"-%s_band=%d" % locator.get('band', 1),
"--%s_band=%d" % locator.get('band', 1),
])
if nodata_value is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment