Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SVLT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ALMF
SVLT
Commits
b0847605
Commit
b0847605
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Expanded 3d patch stack as 3d multichannel patch stack
parent
fcb1dedf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extensions/chaeo/accessors.py
+30
-17
30 additions, 17 deletions
extensions/chaeo/accessors.py
extensions/chaeo/tests/test_accessors.py
+8
-6
8 additions, 6 deletions
extensions/chaeo/tests/test_accessors.py
with
38 additions
and
23 deletions
extensions/chaeo/accessors.py
+
30
−
17
View file @
b0847605
...
...
@@ -63,38 +63,51 @@ class MonoPatchStackFromFile(MonoPatchStack):
def
fpath
(
self
):
return
self
.
file_acc
.
fpath
class
PatchStack
3D
(
InMemoryDataAccessor
):
class
Multichannel3d
PatchStack
(
InMemoryDataAccessor
):
def
__init__
(
self
,
data
):
"""
A sequence of n
monochrome
3D images of the same size
:param data: a list of np.ndarrays of size YXZ
A sequence of n
(generally) color
3D images of the same size
:param data: a list of np.ndarrays of size YX
C
Z
"""
if
isinstance
(
data
,
list
):
# list of YXZ patches
nda
=
np
.
array
(
data
).
squeeze
()
assert
nda
.
ndim
==
4
self
.
_data
=
np
.
moveaxis
(
nda
,
[
1
,
2
,
0
,
3
],
[
0
,
1
,
2
,
3
]
)
if
isinstance
(
data
,
list
):
# list of YXCZ patches
nda
=
np
.
array
(
data
)
assert
nda
.
ndim
==
5
# self._data = np.moveaxis( # pos-YXCZ
# nda,
# [0, 1, 2, 0, 3],
# [0, 1, 2, 3]
# )
self
.
_data
=
nda
else
:
raise
InvalidDataForPatchStackError
(
f
'
Cannot create accessor from
{
type
(
data
)
}
'
)
def
iat
(
self
,
i
):
return
self
.
data
[:,
:,
i
,
:]
return
self
.
data
[
i
,
:,
:,
:
,
:]
def
iat_yxcz
(
self
,
i
):
return
np
.
expand_dims
(
self
.
iat
(
i
)
,
2
)
return
self
.
iat
(
i
)
@property
def
c
hroma
(
self
):
return
1
def
c
ount
(
self
):
return
self
.
shape_dict
[
'
P
'
]
@property
def
count
(
self
):
return
self
.
shape
[
2
]
def
data
(
self
):
"""
Return data as 5d with axes in order of pos, Y, X, C, Z
:return: np.ndarray
"""
return
self
.
_data
@property
def
shape
(
self
):
return
self
.
_data
.
shape
@property
def
shape_dict
(
self
):
return
dict
(
zip
((
'
P
'
,
'
Y
'
,
'
X
'
,
'
C
'
,
'
Z
'
),
self
.
data
.
shape
))
class
Error
(
Exception
):
pass
...
...
This diff is collapsed.
Click to expand it.
extensions/chaeo/tests/test_accessors.py
+
8
−
6
View file @
b0847605
...
...
@@ -3,7 +3,7 @@ import unittest
import
numpy
as
np
from
conf.testing
import
monozstackmask
from
extensions.chaeo.accessors
import
MonoPatchStack
,
MonoPatchStackFromFile
,
PatchStack
3D
from
extensions.chaeo.accessors
import
MonoPatchStack
,
MonoPatchStackFromFile
,
Multichannel3d
PatchStack
...
...
@@ -55,18 +55,20 @@ class TestCziImageFileAccess(unittest.TestCase):
def
test_make_3d_patch_stack_from_list
(
self
):
w
=
256
h
=
512
c
=
1
nz
=
5
n
=
4
acc
=
PatchStack
3D
([
np
.
random
.
rand
(
h
,
w
,
nz
)
for
_
in
range
(
0
,
n
)])
acc
=
Multichannel3d
PatchStack
([
np
.
random
.
rand
(
h
,
w
,
c
,
nz
)
for
_
in
range
(
0
,
n
)])
self
.
assertEqual
(
acc
.
count
,
n
)
self
.
assertEqual
(
acc
.
hw
,
(
h
,
w
))
self
.
assertEqual
(
acc
.
chroma
,
1
)
self
.
assertEqual
(
acc
.
iat
(
0
).
shape
,
(
h
,
w
,
nz
))
self
.
assertEqual
(
acc
.
chroma
,
c
)
self
.
assertEqual
(
acc
.
iat
(
0
).
shape
,
(
h
,
w
,
c
,
nz
))
def
test_3d_patch_as_yxcz_array
(
self
):
w
=
256
h
=
512
nz
=
5
c
=
1
n
=
4
acc
=
PatchStack3D
([
np
.
random
.
rand
(
h
,
w
,
nz
)
for
_
in
range
(
0
,
n
)])
self
.
assertEqual
(
acc
.
iat_yxcz
(
0
).
shape
,
(
h
,
w
,
1
,
nz
))
\ No newline at end of file
acc
=
Multichannel3dPatchStack
([
np
.
random
.
rand
(
h
,
w
,
c
,
nz
)
for
_
in
range
(
0
,
n
)])
self
.
assertEqual
(
acc
.
iat_yxcz
(
0
).
shape
,
(
h
,
w
,
c
,
nz
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment