Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alibylite
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
aliby
alibylite
Commits
13ed9a59
Commit
13ed9a59
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
refactor(dataset): create dispatch function
parent
9f00221f
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/aliby/io/dataset.py
+29
-5
29 additions, 5 deletions
src/aliby/io/dataset.py
with
29 additions
and
5 deletions
src/aliby/io/dataset.py
+
29
−
5
View file @
13ed9a59
...
@@ -20,6 +20,30 @@ from aliby.io.image import ImageLocalOME
...
@@ -20,6 +20,30 @@ from aliby.io.image import ImageLocalOME
from
aliby.io.omero
import
BridgeOmero
from
aliby.io.omero
import
BridgeOmero
def
dispatch_dataset
(
expt_id
:
int
or
str
,
**
kwargs
):
"""
Choose a subtype of dataset based on the identifier.
Input:
--------
expt_id: int or string serving as dataset identifier.
Returns:
--------
Callable Dataset instance, either network-dependent or local.
"""
if
isinstance
(
expt_id
,
int
):
# Is an experiment online
return
Dataset
(
x
,
**
kwargs
[
"
general
"
].
get
(
"
server_info
"
))
elif
isinstance
(
expt_id
,
str
):
# Files or Dir
expt_path
=
Path
(
expt_id
)
if
expt_path
.
is_dir
():
return
DatasetLocalDir
(
expt_path
)
else
:
return
DatasetLocalOME
(
expt_path
)
else
:
raise
Warning
(
"
Invalid expt_id
"
)
class
DatasetLocalABC
(
ABC
):
class
DatasetLocalABC
(
ABC
):
"""
"""
Abstract Base class to fetch local files, either OME-XML or raw images.
Abstract Base class to fetch local files, either OME-XML or raw images.
...
@@ -74,7 +98,7 @@ class DatasetLocalABC(ABC):
...
@@ -74,7 +98,7 @@ class DatasetLocalABC(ABC):
@abstractmethod
@abstractmethod
def
get_images
(
self
):
def
get_images
(
self
):
# Return
location
of images and their unique
name
s
# Return
a dictionary with the name
of images and their unique
identifier
s
pass
pass
...
@@ -95,15 +119,15 @@ class DatasetLocalDir(DatasetLocalABC):
...
@@ -95,15 +119,15 @@ class DatasetLocalDir(DatasetLocalABC):
)
)
def
get_images
(
self
):
def
get_images
(
self
):
return
[
return
{
folder
folder
.
name
:
folder
for
folder
in
self
.
path
.
glob
(
"
*/
"
)
for
folder
in
self
.
path
.
glob
(
"
*/
"
)
if
any
(
if
any
(
path
path
for
suffix
in
self
.
_valid_
meta_
suffixes
for
suffix
in
self
.
_valid_suffixes
for
path
in
folder
.
glob
(
f
"
*.
{
suffix
}
"
)
for
path
in
folder
.
glob
(
f
"
*.
{
suffix
}
"
)
)
)
]
}
class
DatasetLocalOME
(
DatasetLocalABC
):
class
DatasetLocalOME
(
DatasetLocalABC
):
...
...
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