Skip to content

Commit b688c84

Browse files
sm1llanormanrz
andauthored
Set default data format with enviroment variable (#958)
* Set default data format with enviroment variable * format * Add env variable for chunks per shard * Parse Vec3Int from string * parse vec3int with regex * add type annotation * Update changelog * fix linting error --------- Co-authored-by: Norman Rzepka <[email protected]>
1 parent 3b484c8 commit b688c84

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

webknossos/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1515
### Breaking Changes
1616

1717
### Added
18+
- The `DEFAULT_DATA_FORMAT` and `DEFAULT_CHUNKS_PER_SHARD` can now be set with the env variables `WK_DEFAULT_DATA_FORMAT` and `WK_DEFAULT_CHUNKS_PER_SHARD`
19+
- A `Vec3Int` can now be initialized with a string containing an int or a tuple.
1820

1921
### Changed
2022
- Upgrades mypy to 1.6. [#956](https://github.com/scalableminds/webknossos-libs/pull/956)

webknossos/webknossos/dataset/defaults.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
import os
2+
13
from ..geometry import Vec3Int
24
from .data_format import DataFormat
35

46
DEFAULT_WKW_FILE_LEN = 32
57
DEFAULT_CHUNK_SHAPE = Vec3Int.full(32)
6-
DEFAULT_CHUNKS_PER_SHARD = Vec3Int.full(32)
8+
DEFAULT_DATA_FORMAT = (
9+
DataFormat(os.environ["WK_DEFAULT_DATA_FORMAT"])
10+
if "WK_DEFAULT_DATA_FORMAT" in os.environ
11+
else DataFormat.WKW
12+
)
13+
DEFAULT_CHUNKS_PER_SHARD = (
14+
Vec3Int.from_str(os.environ["WK_DEFAULT_CHUNKS_PER_SHARD"])
15+
if "WK_DEFAULT_CHUNKS_PER_SHARD" in os.environ
16+
else Vec3Int.full(32)
17+
)
718
DEFAULT_CHUNKS_PER_SHARD_ZARR = Vec3Int.full(1)
819
DEFAULT_CHUNKS_PER_SHARD_FROM_IMAGES = Vec3Int(128, 128, 1)
920
DEFAULT_BIT_DEPTH = 8
10-
DEFAULT_DATA_FORMAT = DataFormat.WKW
1121
PROPERTIES_FILE_NAME = "datasource-properties.json"
1222
ZGROUP_FILE_NAME = ".zgroup"
1323
ZATTRS_FILE_NAME = ".zattrs"

webknossos/webknossos/geometry/vec3_int.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from operator import add, floordiv, mod, mul, sub
23
from typing import Any, Callable, Iterable, List, Optional, Tuple, Union, cast
34

@@ -72,6 +73,13 @@ def from_vec_or_int(vec_or_int: Union["Vec3IntLike", int]) -> "Vec3Int":
7273
else:
7374
return Vec3Int(vec_or_int)
7475

76+
@staticmethod
77+
def from_str(string: str) -> "Vec3Int":
78+
if re.match(r"\(\d+,\d+,\d+\)", string):
79+
return Vec3Int(tuple(map(int, re.findall(r"\d+", string))))
80+
else:
81+
return Vec3Int.full(int(string))
82+
7583
@property
7684
def x(self) -> int:
7785
return self[0]

0 commit comments

Comments
 (0)