Skip to content

Commit 78595f6

Browse files
dataset.add_symlink_layer handles Layer argument (#389)
* add_symlink_layer can now handle a Layer argument * update changelog * use path api * Update Changelog.md Co-authored-by: R Schwanhold <[email protected]> Co-authored-by: R Schwanhold <[email protected]>
1 parent 20215f5 commit 78595f6

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1212
### Breaking Changes in Config & CLI
1313

1414
### Added
15+
- `dataset.add_symlink_layer` and `dataset.add_copy_layer` can now handle `Layer` arguments as well. The parameter `foreign_layer_path` was renamed to `foreign_layer`. [#389](https://github.com/scalableminds/webknossos-cuber/pull/389)
1516

1617
### Changed
1718
- Bump scipy to `1.6.0` and `scikit-image` to `0.18.0` while keeping `numpy` to under `1.20.0` [#372](https://github.com/scalableminds/webknossos-cuber/pull/372/files)

wkcuber/api/dataset.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,22 @@ def delete_layer(self, layer_name: str) -> None:
409409
rmtree(join(self.path, layer_name))
410410

411411
def add_symlink_layer(
412-
self, foreign_layer_path: Union[str, Path], make_relative: bool = False
412+
self, foreign_layer: Union[str, Path, Layer], make_relative: bool = False
413413
) -> Layer:
414414
"""
415-
Creates a symlink to the data at `foreign_layer_path` which belongs to another dataset.
415+
Creates a symlink to the data at `foreign_layer` which belongs to another dataset.
416416
The relevant information from the `datasource-properties.json` of the other dataset is copied to this dataset.
417417
Note: If the other dataset modifies its bounding box afterwards, the change does not affect this properties
418418
(or vice versa).
419419
If make_relative is True, the symlink is made relative to the current dataset path.
420420
"""
421-
foreign_layer_path = Path(os.path.abspath(foreign_layer_path))
421+
422+
if isinstance(foreign_layer, Layer):
423+
foreign_layer_path = foreign_layer.path
424+
else:
425+
foreign_layer_path = Path(foreign_layer).absolute()
426+
427+
foreign_layer_path = foreign_layer_path.resolve()
422428
layer_name = foreign_layer_path.name
423429
if layer_name in self.layers.keys():
424430
raise IndexError(
@@ -451,13 +457,18 @@ def add_symlink_layer(
451457
self.get_layer(layer_name)._setup_mag(resolution.mag.to_layer_name())
452458
return self.layers[layer_name]
453459

454-
def add_copy_layer(self, foreign_layer_path: Union[str, Path]) -> Layer:
460+
def add_copy_layer(self, foreign_layer: Union[str, Path, Layer]) -> Layer:
455461
"""
456-
Copies the data at `foreign_layer_path` which belongs to another dataset to the current dataset.
462+
Copies the data at `foreign_layer` which belongs to another dataset to the current dataset.
457463
Additionally, the relevant information from the `datasource-properties.json` of the other dataset are copied too.
458464
"""
459465

460-
foreign_layer_path = Path(os.path.abspath(foreign_layer_path))
466+
if isinstance(foreign_layer, Layer):
467+
foreign_layer_path = foreign_layer.path
468+
else:
469+
foreign_layer_path = Path(foreign_layer)
470+
471+
foreign_layer_path = foreign_layer_path.resolve()
461472
layer_name = foreign_layer_path.name
462473
if layer_name in self.layers.keys():
463474
raise IndexError(

wkcuber/api/layer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ def __init__(
8686
self.num_channels = num_channels
8787
self._mags: Dict[Mag, MagView] = {}
8888

89-
full_path = join(dataset.path, name)
90-
makedirs(full_path, exist_ok=True)
89+
makedirs(self.path, exist_ok=True)
90+
91+
@property
92+
def path(self) -> Path:
93+
return Path(join(self.dataset.path, self.name))
9194

9295
@property
9396
def mags(self) -> Dict[Mag, MagView]:

0 commit comments

Comments
 (0)