From 60ee5e6e0d8108468b119d2a2224e1d746ecf49e Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 17 Feb 2021 15:14:02 -0500 Subject: [PATCH] Improve help text. Delete partially generated files when creating a geotiff fails. --- .../converter/large_image_converter/__init__.py | 10 +++++++--- .../converter/large_image_converter/__main__.py | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/utilities/converter/large_image_converter/__init__.py b/utilities/converter/large_image_converter/__init__.py index 499b833c4..f2dfa6f38 100644 --- a/utilities/converter/large_image_converter/__init__.py +++ b/utilities/converter/large_image_converter/__init__.py @@ -103,9 +103,13 @@ def _generate_geotiff(inputPath, outputPath, **kwargs): cmdopt += ['-co', 'LEVEL=%s' % options['level']] cmd = ['gdal_translate', inputPath, outputPath] + cmdopt logger.info('Convert to geotiff: %r' % (cmd)) - # subprocess.check_call(cmd) - ds = gdal.Open(inputPath, gdalconst.GA_ReadOnly) - gdal.Translate(outputPath, ds, options=cmdopt) + try: + # subprocess.check_call(cmd) + ds = gdal.Open(inputPath, gdalconst.GA_ReadOnly) + gdal.Translate(outputPath, ds, options=cmdopt) + except Exception: + os.unlink(outputPath) + raise def _generate_multiframe_tiff(inputPath, outputPath, tempPath, lidata, **kwargs): diff --git a/utilities/converter/large_image_converter/__main__.py b/utilities/converter/large_image_converter/__main__.py index d5af91104..0b5be2b24 100644 --- a/utilities/converter/large_image_converter/__main__.py +++ b/utilities/converter/large_image_converter/__main__.py @@ -11,7 +11,15 @@ def get_parser(): - parser = argparse.ArgumentParser(description='Large Image image converter') + parser = argparse.ArgumentParser(description=""" +Convert files for use with Large Image. +Output files are written as tiled tiff files. For geospatial files, these +conform to the cloud-optimized geospatial tiff format (COG). For +non-geospatial, the output image will be either 8- or 16-bits per sample per +channel. Some compression formats are always 8-bits per sample (webp, jpeg), +even if that format could support more and the original image is higher bit +depth. +""") parser.add_argument( '--version', action='version', version=large_image_converter.__version__, help='Report version') @@ -202,7 +210,11 @@ def main(args=sys.argv[1:]): import tifftools.commands info = tifftools.read_tiff(dest) - desc = json.loads(info['ifds'][0]['tags'][tifftools.Tag.ImageDescription.value]['data']) + try: + desc = json.loads(info['ifds'][0]['tags'][tifftools.Tag.ImageDescription.value]['data']) + except Exception: + logger.debug('Cannot generate statistics.') + return desc['large_image_converter']['conversion_stats'] = { 'time': end_time - start_time, 'filesize': os.path.getsize(dest),