Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
napari-segment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrey ARISTOV
napari-segment
Commits
6430b1fc
Commit
6430b1fc
authored
3 years ago
by
Andrey Aristov
Browse files
Options
Downloads
Patches
Plain Diff
read zarr
parent
37533eaf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/napari_segment/_reader.py
+45
-7
45 additions, 7 deletions
src/napari_segment/_reader.py
with
45 additions
and
7 deletions
src/napari_segment/_reader.py
+
45
−
7
View file @
6430b1fc
...
@@ -5,6 +5,10 @@ It implements the Reader specification, but your plugin may choose to
...
@@ -5,6 +5,10 @@ It implements the Reader specification, but your plugin may choose to
implement multiple readers or even other plugin contributions. see:
implement multiple readers or even other plugin contributions. see:
https://napari.org/plugins/stable/guides.html#readers
https://napari.org/plugins/stable/guides.html#readers
"""
"""
import
json
import
os
import
dask
import
nd2
import
nd2
import
numpy
as
np
import
numpy
as
np
...
@@ -33,28 +37,62 @@ def napari_get_reader(path):
...
@@ -33,28 +37,62 @@ def napari_get_reader(path):
if
path
.
endswith
(
"
.nd2
"
):
if
path
.
endswith
(
"
.nd2
"
):
return
read_nd2
return
read_nd2
if
path
.
endswith
(
"
.zarr
"
):
return
read_zarr
# otherwise we return the *function* that can read ``path``.
# otherwise we return the *function* that can read ``path``.
return
reader_function
return
reader_function
def
read_zarr
(
path
):
print
(
f
"
reading
{
path
}
"
)
try
:
attrs
=
json
.
load
(
open
(
os
.
path
.
join
(
path
,
"
.zattrs
"
)))
info
=
attrs
[
"
multiscales
"
][
"
multiscales
"
][
0
]
channel_axis
=
info
[
"
channel_axis
"
]
print
(
f
"
found channel axis
{
channel_axis
}
"
)
dataset_paths
=
[
os
.
path
.
join
(
path
,
d
[
"
path
"
])
for
d
in
info
[
"
datasets
"
]
]
datasets
=
[
dask
.
array
.
from_zarr
(
p
)
for
p
in
dataset_paths
]
except
Exception
as
e
:
raise
e
return
[
(
datasets
,
{
"
channel_axis
"
:
channel_axis
,
"
colormap
"
:
[
"
gray
"
,
"
inferno
"
],
"
contrast_limits
"
:
[(
0
,
65000
),
(
0
,
6000
)],
},
"
image
"
,
)
]
def
read_nd2
(
path
):
def
read_nd2
(
path
):
print
(
f
"
opening
{
path
}
"
)
print
(
f
"
opening
{
path
}
"
)
data
=
nd2
.
ND2File
(
path
)
data
=
nd2
.
ND2File
(
path
)
print
(
data
.
sizes
)
ddata
=
data
.
to_dask
()
ddata
=
data
.
to_dask
()
# colormap = ["gray", "green"]
try
:
try
:
channel_axis
=
list
(
data
.
sizes
.
keys
()).
index
(
"
C
"
)
channel_axis
=
list
(
data
.
sizes
.
keys
()).
index
(
"
C
"
)
except
ValueError
:
except
ValueError
:
print
(
f
"
No channels,
{
data
.
sizes
}
"
)
channel_axis
=
None
channel_axis
=
None
# colormap = ["gray"]
return
[
return
[
(
(
ddata
,
ddata
,
dict
(
{
"
channel_axis
"
:
channel_axis
},
channel_axis
=
channel_axis
,
# dict(
name
=
[
ch
.
channel
.
name
for
ch
in
data
.
metadata
.
channels
],
# channel_axis=channel_axis,
colormap
=
[
"
gray
"
,
"
green
"
],
# name=[ch.channel.name for ch in data.metadata.channels],
# colormap=colormap,
# scale=data.metadata.channels[0].volume.axesCalibration[:]
# scale=data.metadata.channels[0].volume.axesCalibration[:]
# contrast_limits=[(8500, 35000), (150, 20000)],
# contrast_limits=[(8500, 35000), (150, 20000)],
),
#
),
"
image
"
,
"
image
"
,
)
)
]
]
...
...
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