From 537f13bdfb7a95307bab6a1ed01e1771e2f44d4f Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Mon, 12 Aug 2019 11:01:48 +0200 Subject: [PATCH] Make scale parameter required (#116) * make scale parameter required and remove scale parameter from downsampling tool * remove scale parameter from tests as well * ensure an initial datasource-properties.json is written directly after cubing and refreshed again after downsampling * do meta data generation test directly after cubing so that downsampling can access the datasource properties --- .circleci/config.yml | 8 +++--- tests/scripts/anisotropic_downsampling.sh | 1 - .../scripts/simple_anisotropic_tiff_cubing.sh | 1 - wkcuber/__main__.py | 18 +++++++------ wkcuber/downsampling.py | 25 ++++++++----------- wkcuber/utils.py | 2 +- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cba2b0e48..03207157d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,6 +65,10 @@ jobs: name: Test simple tiff cubing (no compression) command: tests/scripts/simple_tiff_cubing_no_compression.sh + - run: + name: Test metadata generation + command: tests/scripts/meta_generation.sh + - run: name: Test KNOSSOS conversion command: tests/scripts/knossos_conversion.sh @@ -89,10 +93,6 @@ jobs: name: Test in-place compression command: tests/scripts/in_place_compression.sh - - run: - name: Test metadata generation - command: tests/scripts/meta_generation.sh - - run: name: Remove reference magnification data command: rm -r testdata/tiff_mag_2_reference/ diff --git a/tests/scripts/anisotropic_downsampling.sh b/tests/scripts/anisotropic_downsampling.sh index 18ffc3436..ff81c836f 100755 --- a/tests/scripts/anisotropic_downsampling.sh +++ b/tests/scripts/anisotropic_downsampling.sh @@ -37,7 +37,6 @@ docker run \ --max 16 \ --buffer_cube_size 128 \ --layer_name color \ - --scale 11.24,11.24,25 \ /testoutput/tiff [ -d testoutput/tiff/color/8-8-2 ] [ -d testoutput/tiff/color/16-16-4 ] diff --git a/tests/scripts/simple_anisotropic_tiff_cubing.sh b/tests/scripts/simple_anisotropic_tiff_cubing.sh index 2f9dbd912..2d37fff49 100755 --- a/tests/scripts/simple_anisotropic_tiff_cubing.sh +++ b/tests/scripts/simple_anisotropic_tiff_cubing.sh @@ -10,7 +10,6 @@ docker run \ --batch_size 8 \ --layer_name color \ --max 8 \ - --scale 11.24,25,11.24 \ --name awesome_data \ /testdata/tiff /testoutput/tiff3 [ -d testoutput/tiff3/color ] diff --git a/wkcuber/__main__.py b/wkcuber/__main__.py index 1adc944c7..26c381900 100644 --- a/wkcuber/__main__.py +++ b/wkcuber/__main__.py @@ -5,7 +5,7 @@ DEFAULT_EDGE_LEN, ) from .compress import compress_mag_inplace -from .metadata import write_webknossos_metadata +from .metadata import write_webknossos_metadata, refresh_metadata from .utils import add_isotropic_flag, setup_logging, add_scale_flag from .mag import Mag @@ -50,6 +50,14 @@ def create_parser(): args, ) + write_webknossos_metadata( + args.target_path, + args.name, + scale, + compute_max_id=False, + exact_bounding_box=bounding_box, + ) + if not args.no_compress: compress_mag_inplace(args.target_path, args.layer_name, Mag(1), args) @@ -78,10 +86,4 @@ def create_parser(): args, ) - write_webknossos_metadata( - args.target_path, - args.name, - scale, - compute_max_id=False, - exact_bounding_box=bounding_box, - ) + refresh_metadata(args.target_path) diff --git a/wkcuber/downsampling.py b/wkcuber/downsampling.py index 6fb57425d..5e4fddf4e 100644 --- a/wkcuber/downsampling.py +++ b/wkcuber/downsampling.py @@ -21,7 +21,6 @@ get_executor_for_args, wait_and_ensure_success, add_isotropic_flag, - add_scale_flag, setup_logging, ) @@ -109,7 +108,6 @@ def create_parser(): action="store_true", ) - add_scale_flag(parser) add_verbose_flag(parser) add_isotropic_flag(parser) add_distribution_flags(parser) @@ -604,9 +602,7 @@ def detect_larger_and_smaller_dimension(scale): from_mag = Mag(args.from_mag) max_mag = Mag(args.max) - scale = ( - [float(x) for x in args.scale.split(",")] if hasattr(args, "scale") else None - ) + if args.anisotropic_target_mag: anisotropic_target_mag = Mag(args.anisotropic_target_mag) @@ -621,16 +617,15 @@ def detect_larger_and_smaller_dimension(scale): args, ) elif not args.isotropic: - if scale is None: - try: - scale = read_datasource_properties(args.path)["scale"] - except Exception as exc: - logging.error( - "Could not determine scale which is necessary " - "to find target magnifications for anisotropic downsampling. " - "Does the provided dataset have a datasource-properties.json file?" - ) - raise exc + try: + scale = read_datasource_properties(args.path)["scale"] + except Exception as exc: + logging.error( + "Could not determine scale which is necessary " + "to find target magnifications for anisotropic downsampling. " + "Does the provided dataset have a datasource-properties.json file?" + ) + raise exc downsample_mags_anisotropic( args.path, diff --git a/wkcuber/utils.py b/wkcuber/utils.py index bc6bd80c6..8dd135b6a 100644 --- a/wkcuber/utils.py +++ b/wkcuber/utils.py @@ -66,7 +66,7 @@ def add_scale_flag(parser): "--scale", "-s", help="Scale of the dataset (e.g. 11.2,11.2,25). This is the size of one voxel in nm.", - default="1,1,1", + required=True, )