Skip to content

Commit cdb2a92

Browse files
authored
Add chunk and shard shape to CLI convert command options. (#1150)
* Add chunk and shard shape to CLI convert command options. * Update changelog. * Add comment for regex in from_str method.
1 parent 4e8c2b9 commit cdb2a92

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1919

2020
### Changed
2121
- Added options `--layer-name` and `--mag` for compress command of the CLI. [#1141](https://github.com/scalableminds/webknossos-libs/pull/1141)
22+
- Added options `--chunk-shape` and `--chunks-per-shard` for convert command of the CLI. [#1150](https://github.com/scalableminds/webknossos-libs/pull/1150)
2223

2324
### Fixed
2425
- Fixed issue with webknossos URL and context URL being considered different when opening a remote dataset due to trailing slashes. [#1137](https://github.com/scalableminds/webknossos-libs/pull/1137)

webknossos/examples/upsample_skeleton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main() -> None:
1313
"""
1414
Scales a skeleton by a given factor. The factor is applied to the voxel size and the node positions.
1515
16-
This can be usefull when the skeletons are created in a downsampled version and need to be scaled back to the finest mag.
16+
This can be useful when the skeletons are created in a downsampled version and need to be scaled back to the finest mag.
1717
"""
1818
skeleton = wk.Skeleton.load(INPUT_PATH)
1919

webknossos/webknossos/cli/convert.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from webknossos.dataset.length_unit import LengthUnit
1111
from webknossos.dataset.properties import DEFAULT_LENGTH_UNIT_STR, VoxelSize
12+
from webknossos.geometry.vec3_int import Vec3Int
1213

1314
from ..dataset import DataFormat, Dataset
1415
from ..utils import get_executor_for_args
@@ -80,6 +81,24 @@ def main(
8081
"(if not provided, final component of target path is used)"
8182
),
8283
] = None,
84+
chunk_shape: Annotated[
85+
Optional[str],
86+
typer.Option(
87+
help="Chunk shape of the target dataset. Should be a comma separated string "
88+
"(e.g. 64,64,64).",
89+
parser=Vec3Int.from_str,
90+
metavar="Vec3Int",
91+
),
92+
] = None,
93+
chunks_per_shard: Annotated[
94+
Optional[str],
95+
typer.Option(
96+
help="Shard shape of the target dataset. Should be a comma separated string "
97+
"(e.g. 64,64,64).",
98+
parser=Vec3Int.from_str,
99+
metavar="Vec3Int",
100+
),
101+
] = None,
83102
compress: Annotated[
84103
bool, typer.Option(help="Enable compression of the target dataset.")
85104
] = False,
@@ -121,6 +140,8 @@ def main(
121140
target,
122141
name=name,
123142
voxel_size_with_unit=voxel_size_with_unit,
143+
chunk_shape=chunk_shape, # type: ignore
144+
chunks_per_shard=chunks_per_shard, # type: ignore
124145
data_format=data_format,
125146
executor=executor,
126147
compress=compress,

webknossos/webknossos/geometry/vec3_int.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ def from_vec_or_int(vec_or_int: Union["Vec3IntLike", int]) -> "Vec3Int":
110110

111111
@staticmethod
112112
def from_str(string: str) -> "Vec3Int":
113-
if re.match(r"\(\d+,\d+,\d+\)", string):
113+
if re.match(r"^\(\d+,\d+,\d+\)$", string):
114+
# matches a string that consists of three comma-separated digits in parentheses
114115
return Vec3Int(tuple(map(int, re.findall(r"\d+", string))))
116+
elif re.match(r"^\d+,\d+,\d+$", string):
117+
# matches a string that consists of three digits separated by commas
118+
return Vec3Int(tuple(map(int, string.split(","))))
115119

116120
return Vec3Int.full(int(string))
117121

0 commit comments

Comments
 (0)