Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_server
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
Christopher Randolph Rhodes
model_server
Commits
69795a83
Commit
69795a83
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Added import/export functionality to patch stacks
parent
5f245c68
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!16
Completed (de)serialization of RoiSet
,
!5
Resolve "ilastik models do not validate dimensionality of input data"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
model_server/base/accessors.py
+38
-6
38 additions, 6 deletions
model_server/base/accessors.py
tests/test_accessors.py
+8
-1
8 additions, 1 deletion
tests/test_accessors.py
with
46 additions
and
7 deletions
model_server/base/accessors.py
+
38
−
6
View file @
69795a83
...
...
@@ -292,6 +292,22 @@ class PatchStack(InMemoryDataAccessor):
def
count
(
self
):
return
self
.
shape_dict
[
'
P
'
]
def
export_pyxcz
(
self
,
fpath
:
Path
):
tzcyx
=
np
.
moveaxis
(
self
.
pyxcz
,
# yxcz
[
0
,
4
,
3
,
1
,
2
],
[
0
,
1
,
2
,
3
,
4
]
)
if
self
.
is_mask
():
if
self
.
dtype
==
'
bool
'
:
data
=
(
tzcyx
*
255
).
astype
(
'
uint8
'
)
else
:
data
=
tzcyx
.
astype
(
'
uint8
'
)
tifffile
.
imwrite
(
fpath
,
data
,
imagej
=
True
)
else
:
tifffile
.
imwrite
(
fpath
,
tzcyx
,
imagej
=
True
)
@property
def
shape_dict
(
self
):
return
dict
(
zip
((
'
P
'
,
'
Y
'
,
'
X
'
,
'
C
'
,
'
Z
'
),
self
.
data
.
shape
))
...
...
@@ -321,16 +337,32 @@ class PatchStack(InMemoryDataAccessor):
return
dict
(
zip
((
'
P
'
,
'
Y
'
,
'
X
'
,
'
C
'
,
'
Z
'
),
self
.
data
.
shape
))
def
make_patch_stack_from_file
(
fpath
):
# interpret
z
-dimension as patch position
def
make_patch_stack_from_file
(
fpath
):
# interpret
t
-dimension as patch position
if
not
Path
(
fpath
).
exists
():
raise
FileNotFoundError
(
f
'
Could not find
{
fpath
}
'
)
pyxc
=
np
.
moveaxis
(
generate_file_accessor
(
fpath
).
data
,
# yxcz
[
0
,
1
,
2
,
3
],
[
1
,
2
,
3
,
0
]
try
:
tf
=
tifffile
.
TiffFile
(
fpath
)
except
Exception
:
raise
FileAccessorError
(
f
'
Unable to access data in
{
fpath
}
'
)
if
len
(
tf
.
series
)
!=
1
:
raise
DataShapeError
(
f
'
Expect only one series in
{
fpath
}
'
)
se
=
tf
.
series
[
0
]
axs
=
[
a
for
a
in
se
.
axes
if
a
in
[
*
'
TZCYX
'
]]
sd
=
dict
(
zip
(
axs
,
se
.
shape
))
for
a
in
[
*
'
TZC
'
]:
if
a
not
in
axs
:
sd
[
a
]
=
1
tzcyx
=
se
.
asarray
().
reshape
([
sd
[
k
]
for
k
in
[
*
'
TZCYX
'
]])
pyxcz
=
np
.
moveaxis
(
tzcyx
,
[
0
,
3
,
4
,
2
,
1
],
[
0
,
1
,
2
,
3
,
4
],
)
pyxcz
=
np
.
expand_dims
(
pyxc
,
axis
=
3
)
return
PatchStack
(
pyxcz
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_accessors.py
+
8
−
1
View file @
69795a83
...
...
@@ -198,4 +198,11 @@ class TestPatchStackAccessor(unittest.TestCase):
self
.
assertEqual
(
acc
.
count
,
n
)
self
.
assertEqual
(
acc
.
pczyx
.
shape
,
(
n
,
nc
,
nz
,
h
,
w
))
self
.
assertEqual
(
acc
.
hw
,
(
h
,
w
))
return
acc
\ No newline at end of file
return
acc
def
test_export_pczyx_patch_hyperstack
(
self
):
acc
=
self
.
test_pczyx
()
fp
=
output_path
/
'
patch_hyperstack.tif
'
acc
.
export_pyxcz
(
fp
)
acc2
=
make_patch_stack_from_file
(
fp
)
self
.
assertEqual
(
acc
.
shape
,
acc2
.
shape
)
\ 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