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
30e33bad
Commit
30e33bad
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Added generic Tif accessor
parent
67e20ac1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
conf/testing.py
+10
-0
10 additions, 0 deletions
conf/testing.py
model_server/accessors.py
+28
-0
28 additions, 0 deletions
model_server/accessors.py
tests/test_accessors.py
+12
-2
12 additions, 2 deletions
tests/test_accessors.py
with
50 additions
and
2 deletions
conf/testing.py
+
10
−
0
View file @
30e33bad
...
...
@@ -12,6 +12,16 @@ czifile = {
'
z
'
:
1
,
}
filename
=
'
zmask-test-stack.tif
'
tifffile
=
{
'
filename
'
:
filename
,
'
path
'
:
root
/
filename
,
'
w
'
:
512
,
'
h
'
:
512
,
'
c
'
:
2
,
'
z
'
:
7
,
}
ilastik
=
{
'
pixel_classifier
'
:
'
demo_px.ilp
'
,
'
object_classifier
'
:
'
demo_obj.ilp
'
,
...
...
This diff is collapsed.
Click to expand it.
model_server/accessors.py
+
28
−
0
View file @
30e33bad
...
...
@@ -67,6 +67,34 @@ class GenericImageFileAccessor(GenericImageDataAccessor): # image data is loaded
raise
FileAccessorError
(
f
'
Could not find file at
{
fpath
}
'
)
self
.
fpath
=
fpath
class
TifSingleSeriesFileAccessor
(
GenericImageFileAccessor
):
def
__init__
(
self
,
fpath
:
Path
):
super
().
__init__
(
fpath
)
try
:
tf
=
tifffile
.
TiffFile
(
fpath
)
self
.
tf
=
tf
except
Exception
:
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
]
sd
=
{
ch
:
se
.
shape
[
se
.
axes
.
index
(
ch
)]
for
ch
in
se
.
axes
}
idx
=
{
k
:
sd
[
k
]
for
k
in
[
'
Y
'
,
'
X
'
,
'
C
'
,
'
Z
'
]}
yxcz
=
np
.
moveaxis
(
se
.
asarray
(),
[
se
.
axes
.
index
(
ch
)
for
ch
in
idx
],
[
0
,
1
,
2
,
3
]
)
self
.
_data
=
self
.
conform_data
(
yxcz
.
reshape
(
yxcz
.
shape
[
0
:
4
]))
def
__del__
(
self
):
self
.
tf
.
close
()
class
CziImageFileAccessor
(
GenericImageFileAccessor
):
"""
Image that is stored in a Zeiss .CZI file; may be multi-channel, and/or a z-stack,
...
...
This diff is collapsed.
Click to expand it.
tests/test_
image
.py
→
tests/test_
accessors
.py
+
12
−
2
View file @
30e33bad
...
...
@@ -2,14 +2,24 @@ import unittest
import
numpy
as
np
from
conf.testing
import
czifile
,
output_path
from
model_server.accessors
import
CziImageFileAccessor
,
DataShapeError
,
InMemoryDataAccessor
,
write_accessor_data_to_file
from
conf.testing
import
czifile
,
output_path
,
tifffile
from
model_server.accessors
import
CziImageFileAccessor
,
DataShapeError
,
InMemoryDataAccessor
,
write_accessor_data_to_file
,
TifSingleSeriesFileAccessor
class
TestCziImageFileAccess
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
pass
def
test_tiffile_is_correct_shape
(
self
):
tf
=
TifSingleSeriesFileAccessor
(
tifffile
[
'
path
'
])
self
.
assertEqual
(
tf
.
shape_dict
[
'
Y
'
],
tifffile
[
'
h
'
])
self
.
assertEqual
(
tf
.
shape_dict
[
'
X
'
],
tifffile
[
'
w
'
])
self
.
assertEqual
(
tf
.
chroma
,
tifffile
[
'
c
'
])
self
.
assertTrue
(
tf
.
is_3d
())
self
.
assertEqual
(
len
(
tf
.
data
.
shape
),
4
)
self
.
assertEqual
(
tf
.
shape
[
0
],
tifffile
[
'
h
'
])
self
.
assertEqual
(
tf
.
shape
[
1
],
tifffile
[
'
w
'
])
def
test_czifile_is_correct_shape
(
self
):
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
self
.
assertEqual
(
cf
.
shape_dict
[
'
Y
'
],
czifile
[
'
h
'
])
...
...
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