Skip to content

Commit b5ed11f

Browse files
move compress_inplace. fix __main__ usage of Mag
1 parent 21f17d7 commit b5ed11f

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

wkcuber/__main__.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from argparse import ArgumentParser
2-
from os import path
3-
from uuid import uuid4
2+
43
import logging
5-
import shutil
64

75
from .cubing import cubing, BLOCK_LEN
86
from .downsampling import downsample_mags, DEFAULT_EDGE_LEN
9-
from .compress import compress_mag
7+
from .compress import compress_mag_inplace
108
from .metadata import write_webknossos_metadata
119
from .utils import add_verbose_flag, add_jobs_flag
10+
from .mag import Mag
1211

1312

1413
def create_parser():
@@ -72,18 +71,6 @@ def create_parser():
7271
return parser
7372

7473

75-
def compress_mag_inplace(target_path, layer_name, mag, jobs):
76-
compress_target_path = "{}.compress-{}".format(target_path, uuid4())
77-
compress_mag(target_path, layer_name, compress_target_path, mag, jobs)
78-
79-
shutil.rmtree(path.join(args.target_path, args.layer_name, str(mag)))
80-
shutil.move(
81-
path.join(compress_target_path, layer_name, str(mag)),
82-
path.join(target_path, layer_name, str(mag)),
83-
)
84-
shutil.rmtree(compress_target_path)
85-
86-
8774
if __name__ == "__main__":
8875
args = create_parser().parse_args()
8976

@@ -105,8 +92,8 @@ def compress_mag_inplace(target_path, layer_name, mag, jobs):
10592
downsample_mags(
10693
args.target_path,
10794
args.layer_name,
108-
1,
109-
args.max_mag,
95+
Mag(1),
96+
Mag(args.max_mag),
11097
args.dtype,
11198
"default",
11299
DEFAULT_EDGE_LEN,

wkcuber/compress.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
from argparse import ArgumentParser
77
from os import path, makedirs
8+
from uuid import uuid4
89
from .mag import Mag
910

1011
from .utils import (
@@ -88,6 +89,18 @@ def compress_mag(source_path, layer_name, target_path, mag: Mag, jobs):
8889
logging.info("Mag {0} succesfully compressed".format(str(mag)))
8990

9091

92+
def compress_mag_inplace(target_path, layer_name, mag: Mag, jobs):
93+
compress_target_path = "{}.compress-{}".format(target_path, uuid4())
94+
compress_mag(target_path, layer_name, compress_target_path, mag, jobs)
95+
96+
shutil.rmtree(path.join(args.target_path, args.layer_name, str(mag)))
97+
shutil.move(
98+
path.join(compress_target_path, layer_name, str(mag)),
99+
path.join(target_path, layer_name, str(mag)),
100+
)
101+
shutil.rmtree(compress_target_path)
102+
103+
91104
def compress_mags(
92105
source_path, layer_name, target_path=None, mags: List[Mag] = None, jobs=1
93106
):

0 commit comments

Comments
 (0)