Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wela
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Swain Lab
wela
Commits
9ff355a4
Commit
9ff355a4
authored
9 months ago
by
pswain
Browse files
Options
Downloads
Patches
Plain Diff
change(imageviewer): one class with classmethods
parent
4dd9423f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/wela/imageviewer.py
+103
-62
103 additions, 62 deletions
src/wela/imageviewer.py
with
103 additions
and
62 deletions
src/wela/imageviewer.py
+
103
−
62
View file @
9ff355a4
import
typing
as
t
from
abc
import
ABC
from
pathlib
import
Path
from
pathlib
import
Path
import
h5py
import
h5py
...
@@ -12,25 +10,57 @@ from aliby.io.omero import UnsafeImage as OImage
...
@@ -12,25 +10,57 @@ from aliby.io.omero import UnsafeImage as OImage
from
aliby.tile.tiler
import
Tiler
from
aliby.tile.tiler
import
Tiler
def
colormap
(
channel
):
class
ImageViewer
:
"""
Find default colormap.
"""
if
"
GFP
"
in
channel
:
colormap
=
"
green
"
elif
"
Cherry
"
in
channel
or
"
RFP
"
in
channel
:
colormap
=
"
red
"
else
:
colormap
=
"
gray
"
return
colormap
def
__init__
(
self
,
h5file
):
self
.
h5file_path
=
Path
(
h5file
)
print
(
f
"
Viewing
{
str
(
self
.
h5file_path
)
}
"
)
self
.
full
=
{}
class
BaseImageViewer
(
ABC
):
@classmethod
"""
Base class for all ImageViewers.
"""
def
local
(
cls
,
h5file
:
str
,
image_file
:
str
):
"""
View images from local files.
def
__init__
(
self
,
h5file_path
):
Files are either zarr or organised in directories.
"""
Initialise from a Path to a h5 file.
"""
"""
self
.
h5file_path
=
h5file_path
iv
=
cls
(
h5file
)
print
(
f
"
Viewing
{
str
(
h5file_path
)
}
"
)
image_file_path
=
Path
(
image_file
)
self
.
full
=
{}
if
iv
.
h5file_path
.
exists
()
and
image_file_path
.
exists
():
with
dispatch_image
(
image_file_path
)(
image_file_path
)
as
image
:
tiler
=
Tiler
.
from_h5
(
image
,
iv
.
h5file_path
)
cells
=
Cells
.
from_source
(
iv
.
h5file_path
)
iv
.
tiler
=
tiler
iv
.
cells
=
cells
return
iv
else
:
if
not
iv
.
h5file_path
.
exists
():
print
(
f
"
Trouble loading
{
h5file
}
.
"
)
if
not
image_file_path
.
exists
():
print
(
f
"
Trouble loading
{
image_file
}
.
"
)
@classmethod
def
remote
(
cls
,
h5file
:
str
,
server_info
:
dict
,
omero_id
:
int
):
"""
View images from OMERO.
"""
iv
=
cls
(
h5file
)
with
h5py
.
File
(
iv
.
h5file_path
,
"
r
"
)
as
f
:
# get image_id from the h5 file
image_id
=
f
.
attrs
.
get
(
"
image_id
"
)
if
image_id
is
None
:
# get image_id from OMERO
with
Dataset
(
omero_id
,
**
server_info
)
as
dataset_om
:
positions
=
dataset_om
.
get_position_ids
()
image_id
=
positions
.
get
(
iv
.
h5file_path
.
name
.
split
(
"
.
"
)[
0
])
if
image_id
is
None
:
print
(
"
Can
'
t find an image.
"
)
else
:
print
(
f
"
Using image ID
{
image_id
}
.
"
)
iv
.
image_id
=
image_id
image
=
OImage
(
image_id
,
**
server_info
)
print
(
"
Connected to OMERO.
"
)
iv
.
tiler
=
Tiler
.
from_h5
(
image
,
iv
.
h5file_path
)
iv
.
cells
=
Cells
.
from_source
(
iv
.
h5file_path
)
return
iv
def
find_traps_with_cells
(
self
,
tpt_end
,
tpt_start
=
0
):
def
find_traps_with_cells
(
self
,
tpt_end
,
tpt_start
=
0
):
"""
List traps with cells.
"""
"""
List traps with cells.
"""
...
@@ -192,55 +222,66 @@ class BaseImageViewer(ABC):
...
@@ -192,55 +222,66 @@ class BaseImageViewer(ABC):
)
)
class
LocalImageViewer
(
BaseImageViewer
):
#
class LocalImageViewer(BaseImageViewer):
"""
#
"""
View images from local files.
#
View images from local files.
Files are either zarr or organised in directories.
#
Files are either zarr or organised in directories.
"""
#
"""
def
__init__
(
self
,
h5file
:
str
,
image_file
:
str
):
#
def __init__(self, h5file: str, image_file: str):
"""
Initialise using a h5file and a zarr file of images.
"""
#
"""Initialise using a h5file and a zarr file of images."""
h5file_path
=
Path
(
h5file
)
#
h5file_path = Path(h5file)
image_file_path
=
Path
(
image_file
)
#
image_file_path = Path(image_file)
if
h5file_path
.
exists
()
and
image_file_path
.
exists
():
#
if h5file_path.exists() and image_file_path.exists():
super
().
__init__
(
h5file_path
)
#
super().__init__(h5file_path)
with
dispatch_image
(
image_file_path
)(
image_file_path
)
as
image
:
#
with dispatch_image(image_file_path)(image_file_path) as image:
self
.
tiler
=
Tiler
.
from_h5
(
image
,
h5file_path
)
#
self.tiler = Tiler.from_h5(image, h5file_path)
self
.
cells
=
Cells
.
from_source
(
h5file_path
)
#
self.cells = Cells.from_source(h5file_path)
else
:
#
else:
if
not
h5file_path
.
exists
():
#
if not h5file_path.exists():
print
(
f
"
Trouble loading
{
h5file
}
.
"
)
#
print(f" Trouble loading {h5file}.")
if
not
image_file_path
.
exists
():
#
if not image_file_path.exists():
print
(
f
"
Trouble loading
{
image_file
}
.
"
)
#
print(f" Trouble loading {image_file}.")
class
RemoteImageViewer
(
BaseImageViewer
):
#
class RemoteImageViewer(BaseImageViewer):
"""
View images from OMERO.
"""
#
"""View images from OMERO."""
def
__init__
(
# def __init__(
self
,
h5file
:
str
,
server_info
:
t
.
Dict
[
str
,
str
],
omero_id
:
int
# self, h5file: str, server_info: t.Dict[str, str], omero_id: int
):
# ):
"""
Initialise using a h5file and importing aliby.io.omero.
"""
# """Initialise using a h5file and importing aliby.io.omero."""
h5file_path
=
Path
(
h5file
)
# h5file_path = Path(h5file)
super
().
__init__
(
h5file_path
)
# super().__init__(h5file_path)
with
h5py
.
File
(
h5file_path
,
"
r
"
)
as
f
:
# with h5py.File(h5file_path, "r") as f:
# get image_id from the h5 file
# # get image_id from the h5 file
image_id
=
f
.
attrs
.
get
(
"
image_id
"
)
# image_id = f.attrs.get("image_id")
if
image_id
is
None
:
# if image_id is None:
# get image_id from OMERO
# # get image_id from OMERO
with
Dataset
(
omero_id
,
**
server_info
)
as
dataset_om
:
# with Dataset(omero_id, **server_info) as dataset_om:
positions
=
dataset_om
.
get_position_ids
()
# positions = dataset_om.get_position_ids()
image_id
=
positions
.
get
(
h5file_path
.
name
.
split
(
"
.
"
)[
0
])
# image_id = positions.get(h5file_path.name.split(".")[0])
if
image_id
is
None
:
# if image_id is None:
print
(
"
Can
'
t find an image.
"
)
# print("Can't find an image.")
else
:
# else:
print
(
f
"
Using image ID
{
image_id
}
.
"
)
# print(f"Using image ID {image_id}.")
self
.
image_id
=
image_id
# self.image_id = image_id
image
=
OImage
(
image_id
,
**
server_info
)
# image = OImage(image_id, **server_info)
print
(
"
Connected to OMERO.
"
)
# print("Connected to OMERO.")
self
.
tiler
=
Tiler
.
from_h5
(
image
,
h5file_path
)
# self.tiler = Tiler.from_h5(image, h5file_path)
self
.
cells
=
Cells
.
from_source
(
h5file_path
)
# self.cells = Cells.from_source(h5file_path)
def
colormap
(
channel
):
"""
Find default colormap.
"""
if
"
GFP
"
in
channel
:
colormap
=
"
green
"
elif
"
Cherry
"
in
channel
or
"
RFP
"
in
channel
:
colormap
=
"
red
"
else
:
colormap
=
"
gray
"
return
colormap
def
get_files
(
def
get_files
(
...
...
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