From 1c5b1700127426d1b9102a9628f593b228a02848 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Wed, 12 Jun 2019 16:42:28 +0200 Subject: [PATCH] add timestamps to logging and default to info (#96) * add timestamps to logging and default to info * formatting * format * fix imports * format * bump version to 0.2.14 --- setup.py | 2 +- wkcuber/__main__.py | 11 +++++++---- wkcuber/compress.py | 4 ++-- wkcuber/convert_knossos.py | 5 ++--- wkcuber/cubing.py | 5 ++--- wkcuber/downsampling.py | 5 ++--- wkcuber/metadata.py | 6 +++++- wkcuber/tile_cubing.py | 5 ++--- wkcuber/utils.py | 8 ++++++++ 9 files changed, 31 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index 8dd5aa1d0..0babf0464 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="wkcuber", packages=find_packages(exclude=("tests",)), - version="0.2.13", + version="0.2.14", install_requires=["scipy", "numpy", "pillow", "pyyaml", "wkw", "cluster_tools>=1.19"], description="A cubing tool for webKnossos", author="Norman Rzepka", diff --git a/wkcuber/__main__.py b/wkcuber/__main__.py index e3e887957..37aeb9692 100644 --- a/wkcuber/__main__.py +++ b/wkcuber/__main__.py @@ -6,7 +6,12 @@ from .downsampling import downsample_mags, downsample_mags_anisotropic, DEFAULT_EDGE_LEN from .compress import compress_mag_inplace from .metadata import write_webknossos_metadata -from .utils import add_verbose_flag, add_distribution_flags, add_anisotropic_flag +from .utils import ( + add_verbose_flag, + add_distribution_flags, + add_anisotropic_flag, + setup_logging, +) from .mag import Mag @@ -44,9 +49,7 @@ def create_parser(): if __name__ == "__main__": args = create_parser().parse_args() - - if args.verbose: - logging.basicConfig(level=logging.DEBUG) + setup_logging(args) scale = tuple(float(x) for x in args.scale.split(",")) bounding_box = cubing( diff --git a/wkcuber/compress.py b/wkcuber/compress.py index 95dffe4eb..c6c131733 100644 --- a/wkcuber/compress.py +++ b/wkcuber/compress.py @@ -15,6 +15,7 @@ add_distribution_flags, get_executor_for_args, wait_and_ensure_success, + setup_logging, ) from .metadata import detect_resolutions from typing import List @@ -148,6 +149,5 @@ def compress_mags( if __name__ == "__main__": args = create_parser().parse_args() - if args.verbose: - logging.basicConfig(level=logging.DEBUG) + setup_logging(args) compress_mags(args.source_path, args.layer_name, args.target_path, args.mag, args) diff --git a/wkcuber/convert_knossos.py b/wkcuber/convert_knossos.py index 1d21b7e83..8934db5d3 100644 --- a/wkcuber/convert_knossos.py +++ b/wkcuber/convert_knossos.py @@ -15,6 +15,7 @@ add_distribution_flags, get_executor_for_args, wait_and_ensure_success, + setup_logging, ) from .knossos import KnossosDataset, CUBE_EDGE_LEN @@ -98,9 +99,7 @@ def convert_knossos( if __name__ == "__main__": args = create_parser().parse_args() - - if args.verbose: - logging.basicConfig(level=logging.DEBUG) + setup_logging(args) convert_knossos( args.source_path, diff --git a/wkcuber/cubing.py b/wkcuber/cubing.py index 98cfa4566..abd770e03 100644 --- a/wkcuber/cubing.py +++ b/wkcuber/cubing.py @@ -15,6 +15,7 @@ add_distribution_flags, get_executor_for_args, wait_and_ensure_success, + setup_logging, ) from .image_readers import image_reader @@ -216,9 +217,7 @@ def cubing(source_path, target_path, layer_name, dtype, batch_size, args=None) - if __name__ == "__main__": args = create_parser().parse_args() - - if args.verbose: - logging.basicConfig(level=logging.DEBUG) + setup_logging(args) cubing( args.source_path, diff --git a/wkcuber/downsampling.py b/wkcuber/downsampling.py index 2e88779ff..3603e712a 100644 --- a/wkcuber/downsampling.py +++ b/wkcuber/downsampling.py @@ -23,6 +23,7 @@ get_executor_for_args, wait_and_ensure_success, add_anisotropic_flag, + setup_logging, ) DEFAULT_EDGE_LEN = 256 @@ -530,9 +531,7 @@ def detect_larger_and_smaller_dimension(scale): if __name__ == "__main__": args = create_parser().parse_args() - - if args.verbose: - logging.basicConfig(level=logging.DEBUG) + setup_logging(args) from_mag = Mag(args.from_mag) max_mag = Mag(args.max) diff --git a/wkcuber/metadata.py b/wkcuber/metadata.py index 7a2ba9d5c..e0b3b4758 100644 --- a/wkcuber/metadata.py +++ b/wkcuber/metadata.py @@ -10,6 +10,7 @@ from typing import Optional from .mag import Mag from typing import List +from .utils import add_verbose_flag, setup_logging def get_datasource_path(dataset_path): @@ -41,6 +42,8 @@ def create_parser(): ) group.add_argument("--max_id", help="set max id of segmentation.", default=0) + add_verbose_flag(parser) + return parser @@ -288,8 +291,9 @@ def detect_layers(dataset_path, max_id, compute_max_id, exact_bounding_box=None) if __name__ == "__main__": - logging.basicConfig(level=logging.DEBUG) args = create_parser().parse_args() + setup_logging(args) + if not args.refresh: assert ( args.name is not None diff --git a/wkcuber/tile_cubing.py b/wkcuber/tile_cubing.py index 6e56962c6..3f2615410 100644 --- a/wkcuber/tile_cubing.py +++ b/wkcuber/tile_cubing.py @@ -17,6 +17,7 @@ add_distribution_flags, get_executor_for_args, wait_and_ensure_success, + setup_logging, ) from .cubing import create_parser, read_image_file from .image_readers import image_reader @@ -170,9 +171,7 @@ def tile_cubing( if __name__ == "__main__": args = create_parser().parse_args() - - if args.verbose: - logging.basicConfig(level=logging.DEBUG) + setup_logging(args) tile_cubing( args.source_path, diff --git a/wkcuber/utils.py b/wkcuber/utils.py index 8f5d9a4f8..124047b48 100644 --- a/wkcuber/utils.py +++ b/wkcuber/utils.py @@ -76,6 +76,14 @@ def add_anisotropic_flag(parser): parser.set_defaults(anisotropic=False) +def setup_logging(args): + + logging.basicConfig( + level=(logging.DEBUG if args.verbose else logging.INFO), + format="%(asctime)s %(levelname)s %(message)s", + ) + + def find_files(source_path, extensions): # Find all files with a matching file extension return (