-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify Properties in Mag and BoundingBox, add Vec3Int (#421)
* unify mag class * fix usage in test * make topleft + size private for bbox * Adapt BoundingBox to Vec3Int (todo: serialize) * have vec3 extend tuple, freeze bounding box * Fix segmentation layer initialization * freeze Mag * use attr.s instead of attr.frozen * start using Vec3Int in dataset api, add tests * add more tests * more tests, add neg * use attr.frozen again * relative path in toml * changelog * implement pr feedback * add more with_* convenience methods to bbox and vecint * fix typo in comment * implement pr feedback (part 2)
- Loading branch information
Showing
24 changed files
with
777 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Change Log | ||
|
||
All notable changes to the webknossos python library are documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/) `MAJOR.MINOR.PATCH`. | ||
For upgrade instructions, please check the respective *Breaking Changes* sections. | ||
|
||
## Unreleased | ||
[Commits](https://github.com/scalableminds/webknossos-cuber/compare/v0.8.13...HEAD) | ||
|
||
### Breaking Changes | ||
|
||
- Breaking changes were introduced for geometry classes in [#421](https://github.com/scalableminds/webknossos-libs/pull/421): | ||
- `BoundingBox` | ||
- is now immutable, use convenience methods, e.g. `bb.with_topleft((0,0,0))` | ||
- properties topleft and size are now Vec3Int instead of np.array, they are each immutable as well | ||
- all `to_`-conversions return a copy, some were renamed: | ||
- `to_array` → `to_list` | ||
- `as_np` → `to_np` | ||
- `as_wkw` → `to_wkw_dict` | ||
- `from_wkw` → `from_wkw_dict` | ||
- `as_config` → `to_config_dict` | ||
- `as_checkpoint_name` → `to_checkpoint_name` | ||
- `as_tuple6` → `to_tuple6` | ||
- `as_csv` → `to_csv` | ||
- `as_named_tuple` → `to_named_tuple` | ||
- `as_slices` → `to_slices` | ||
- `copy` → (gone, immutable) | ||
|
||
- `Mag` | ||
- is now immutable | ||
- `mag.mag` is now `mag._mag` (considered private, use to_list instead if you really need it as list) | ||
- all `to_`-conversions return a copy, some were renamed: | ||
- `to_array` → `to_list` | ||
- `scale_by` → (gone, immutable) | ||
- `divide_by` → (gone, immutable) | ||
- `as_np` → `to_np` | ||
|
||
### Added | ||
|
||
- An immutable Vec3Int class was introduced that holds three integers and provides a number of convenience methods and accessors. [#421](https://github.com/scalableminds/webknossos-libs/pull/421) | ||
|
||
### Changed | ||
|
||
- `BoundingBox` and `Mag` are now immutable attr classes containing `Vec3Int` values. See breaking changes above. | ||
|
||
### Fixed | ||
|
||
- | ||
|
||
## [0.8.13](https://github.com/scalableminds/webknossos-cuber/releases/tag/v0.8.13) - 2021-09-22 | ||
[Commits](https://github.com/scalableminds/webknossos-cuber/compare/v0.8.12...v0.8.13) | ||
|
||
This is the latest release at the time of creating this changelog. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import numpy as np | ||
|
||
from webknossos.geometry import Mag, Vec3Int | ||
|
||
|
||
def test_with() -> None: | ||
|
||
assert Vec3Int(1, 2, 3).with_x(5) == Vec3Int(5, 2, 3) | ||
assert Vec3Int(1, 2, 3).with_y(5) == Vec3Int(1, 5, 3) | ||
assert Vec3Int(1, 2, 3).with_z(5) == Vec3Int(1, 2, 5) | ||
|
||
|
||
def test_import() -> None: | ||
|
||
assert Vec3Int(1, 2, 3) == Vec3Int(1, 2, 3) | ||
assert Vec3Int((1, 2, 3)) == Vec3Int(1, 2, 3) | ||
assert Vec3Int([1, 2, 3]) == Vec3Int(1, 2, 3) | ||
assert Vec3Int(i for i in [1, 2, 3]) == Vec3Int(1, 2, 3) | ||
assert Vec3Int(np.array([1, 2, 3])) == Vec3Int(1, 2, 3) | ||
assert Vec3Int(Mag(4)) == Vec3Int(4, 4, 4) | ||
|
||
|
||
def test_export() -> None: | ||
|
||
assert Vec3Int(1, 2, 3).x == 1 | ||
assert Vec3Int(1, 2, 3).y == 2 | ||
assert Vec3Int(1, 2, 3).z == 3 | ||
assert Vec3Int(1, 2, 3)[0] == 1 | ||
assert Vec3Int(1, 2, 3)[1] == 2 | ||
assert Vec3Int(1, 2, 3)[2] == 3 | ||
assert np.array_equal(Vec3Int(1, 2, 3).to_np(), np.array([1, 2, 3])) | ||
assert Vec3Int(1, 2, 3).to_list() == [1, 2, 3] | ||
assert Vec3Int(1, 2, 3).to_tuple() == (1, 2, 3) | ||
|
||
|
||
def test_operator_arithmetic() -> None: | ||
|
||
# other is Vec3Int | ||
assert Vec3Int(1, 2, 3) + Vec3Int(4, 5, 6) == Vec3Int(5, 7, 9) | ||
assert Vec3Int(1, 2, 3) + Vec3Int(0, 0, 0) == Vec3Int(1, 2, 3) | ||
assert Vec3Int(1, 2, 3) - Vec3Int(4, 5, 6) == Vec3Int(-3, -3, -3) | ||
assert Vec3Int(1, 2, 3) * Vec3Int(4, 5, 6) == Vec3Int(4, 10, 18) | ||
assert Vec3Int(4, 5, 6) // Vec3Int(1, 2, 3) == Vec3Int(4, 2, 2) | ||
assert Vec3Int(4, 5, 6) % Vec3Int(1, 2, 3) == Vec3Int(0, 1, 0) | ||
|
||
# other is scalar int | ||
assert Vec3Int(1, 2, 3) * 3 == Vec3Int(3, 6, 9) | ||
assert Vec3Int(1, 2, 3) + 3 == Vec3Int(4, 5, 6) | ||
assert Vec3Int(1, 2, 3) - 3 == Vec3Int(-2, -1, 0) | ||
assert Vec3Int(4, 5, 6) // 2 == Vec3Int(2, 2, 3) | ||
assert Vec3Int(4, 5, 6) % 3 == Vec3Int(1, 2, 0) | ||
|
||
# other is Vec3IntLike (e.g. tuple) | ||
assert Vec3Int(1, 2, 3) + (4, 5, 6) == Vec3Int(5, 7, 9) | ||
|
||
# be wary of the tuple “+” operation: | ||
assert (1, 2, 3) + Vec3Int(4, 5, 6) == (1, 2, 3, 4, 5, 6) | ||
|
||
assert -Vec3Int(1, 2, 3) == Vec3Int(-1, -2, -3) | ||
|
||
|
||
def test_method_arithmetic() -> None: | ||
|
||
assert Vec3Int(4, 5, 6).ceildiv(Vec3Int(1, 2, 3)) == Vec3Int(4, 3, 2) | ||
assert Vec3Int(4, 5, 6).ceildiv((1, 2, 3)) == Vec3Int(4, 3, 2) | ||
assert Vec3Int(4, 5, 6).ceildiv(2) == Vec3Int(2, 3, 3) | ||
|
||
assert Vec3Int(1, 2, 6).pairmax(Vec3Int(4, 5, 3)) == Vec3Int(4, 5, 6) | ||
assert Vec3Int(1, 2, 6).pairmin(Vec3Int(4, 5, 3)) == Vec3Int(1, 2, 3) | ||
|
||
|
||
def test_repr() -> None: | ||
|
||
assert str(Vec3Int(1, 2, 3)) == "Vec3Int(1,2,3)" | ||
|
||
|
||
def test_prod() -> None: | ||
|
||
assert Vec3Int(1, 2, 3).prod() == 6 | ||
|
||
|
||
def test_contains() -> None: | ||
|
||
assert Vec3Int(1, 2, 3).contains(1) | ||
assert not Vec3Int(1, 2, 3).contains(4) | ||
|
||
|
||
def test_custom_initialization() -> None: | ||
|
||
assert Vec3Int.zeros() == Vec3Int(0, 0, 0) | ||
assert Vec3Int.ones() == Vec3Int(1, 1, 1) | ||
assert Vec3Int.full(4) == Vec3Int(4, 4, 4) | ||
|
||
assert Vec3Int.ones() - Vec3Int.ones() == Vec3Int.zeros() | ||
assert Vec3Int.full(4) == Vec3Int.ones() * 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.