Skip to content

Commit 1c5b170

Browse files
authored
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
1 parent 4af2d9f commit 1c5b170

File tree

9 files changed

+31
-20
lines changed

9 files changed

+31
-20
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name="wkcuber",
55
packages=find_packages(exclude=("tests",)),
6-
version="0.2.13",
6+
version="0.2.14",
77
install_requires=["scipy", "numpy", "pillow", "pyyaml", "wkw", "cluster_tools>=1.19"],
88
description="A cubing tool for webKnossos",
99
author="Norman Rzepka",

wkcuber/__main__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from .downsampling import downsample_mags, downsample_mags_anisotropic, DEFAULT_EDGE_LEN
77
from .compress import compress_mag_inplace
88
from .metadata import write_webknossos_metadata
9-
from .utils import add_verbose_flag, add_distribution_flags, add_anisotropic_flag
9+
from .utils import (
10+
add_verbose_flag,
11+
add_distribution_flags,
12+
add_anisotropic_flag,
13+
setup_logging,
14+
)
1015
from .mag import Mag
1116

1217

@@ -44,9 +49,7 @@ def create_parser():
4449

4550
if __name__ == "__main__":
4651
args = create_parser().parse_args()
47-
48-
if args.verbose:
49-
logging.basicConfig(level=logging.DEBUG)
52+
setup_logging(args)
5053

5154
scale = tuple(float(x) for x in args.scale.split(","))
5255
bounding_box = cubing(

wkcuber/compress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
add_distribution_flags,
1616
get_executor_for_args,
1717
wait_and_ensure_success,
18+
setup_logging,
1819
)
1920
from .metadata import detect_resolutions
2021
from typing import List
@@ -148,6 +149,5 @@ def compress_mags(
148149

149150
if __name__ == "__main__":
150151
args = create_parser().parse_args()
151-
if args.verbose:
152-
logging.basicConfig(level=logging.DEBUG)
152+
setup_logging(args)
153153
compress_mags(args.source_path, args.layer_name, args.target_path, args.mag, args)

wkcuber/convert_knossos.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
add_distribution_flags,
1616
get_executor_for_args,
1717
wait_and_ensure_success,
18+
setup_logging,
1819
)
1920
from .knossos import KnossosDataset, CUBE_EDGE_LEN
2021

@@ -98,9 +99,7 @@ def convert_knossos(
9899

99100
if __name__ == "__main__":
100101
args = create_parser().parse_args()
101-
102-
if args.verbose:
103-
logging.basicConfig(level=logging.DEBUG)
102+
setup_logging(args)
104103

105104
convert_knossos(
106105
args.source_path,

wkcuber/cubing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
add_distribution_flags,
1616
get_executor_for_args,
1717
wait_and_ensure_success,
18+
setup_logging,
1819
)
1920
from .image_readers import image_reader
2021

@@ -216,9 +217,7 @@ def cubing(source_path, target_path, layer_name, dtype, batch_size, args=None) -
216217

217218
if __name__ == "__main__":
218219
args = create_parser().parse_args()
219-
220-
if args.verbose:
221-
logging.basicConfig(level=logging.DEBUG)
220+
setup_logging(args)
222221

223222
cubing(
224223
args.source_path,

wkcuber/downsampling.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
get_executor_for_args,
2424
wait_and_ensure_success,
2525
add_anisotropic_flag,
26+
setup_logging,
2627
)
2728

2829
DEFAULT_EDGE_LEN = 256
@@ -530,9 +531,7 @@ def detect_larger_and_smaller_dimension(scale):
530531

531532
if __name__ == "__main__":
532533
args = create_parser().parse_args()
533-
534-
if args.verbose:
535-
logging.basicConfig(level=logging.DEBUG)
534+
setup_logging(args)
536535

537536
from_mag = Mag(args.from_mag)
538537
max_mag = Mag(args.max)

wkcuber/metadata.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Optional
1111
from .mag import Mag
1212
from typing import List
13+
from .utils import add_verbose_flag, setup_logging
1314

1415

1516
def get_datasource_path(dataset_path):
@@ -41,6 +42,8 @@ def create_parser():
4142
)
4243
group.add_argument("--max_id", help="set max id of segmentation.", default=0)
4344

45+
add_verbose_flag(parser)
46+
4447
return parser
4548

4649

@@ -288,8 +291,9 @@ def detect_layers(dataset_path, max_id, compute_max_id, exact_bounding_box=None)
288291

289292

290293
if __name__ == "__main__":
291-
logging.basicConfig(level=logging.DEBUG)
292294
args = create_parser().parse_args()
295+
setup_logging(args)
296+
293297
if not args.refresh:
294298
assert (
295299
args.name is not None

wkcuber/tile_cubing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
add_distribution_flags,
1818
get_executor_for_args,
1919
wait_and_ensure_success,
20+
setup_logging,
2021
)
2122
from .cubing import create_parser, read_image_file
2223
from .image_readers import image_reader
@@ -170,9 +171,7 @@ def tile_cubing(
170171

171172
if __name__ == "__main__":
172173
args = create_parser().parse_args()
173-
174-
if args.verbose:
175-
logging.basicConfig(level=logging.DEBUG)
174+
setup_logging(args)
176175

177176
tile_cubing(
178177
args.source_path,

wkcuber/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def add_anisotropic_flag(parser):
7676
parser.set_defaults(anisotropic=False)
7777

7878

79+
def setup_logging(args):
80+
81+
logging.basicConfig(
82+
level=(logging.DEBUG if args.verbose else logging.INFO),
83+
format="%(asctime)s %(levelname)s %(message)s",
84+
)
85+
86+
7987
def find_files(source_path, extensions):
8088
# Find all files with a matching file extension
8189
return (

0 commit comments

Comments
 (0)