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
31e767d4
Commit
31e767d4
authored
2 years ago
by
pswain
Browse files
Options
Downloads
Patches
Plain Diff
documented tiler
parent
d46ae180
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
aliby/tile/tiler.py
+71
-13
71 additions, 13 deletions
aliby/tile/tiler.py
with
71 additions
and
13 deletions
aliby/tile/tiler.py
+
71
−
13
View file @
31e767d4
...
@@ -54,21 +54,38 @@ class Trap:
...
@@ -54,21 +54,38 @@ class Trap:
----------
----------
tp: integer
tp: integer
Index for a time point
Index for a time point
Returns
-------
trap_centre:
"""
"""
drifts
=
self
.
parent
.
drifts
drifts
=
self
.
parent
.
drifts
return
self
.
centre
-
np
.
sum
(
drifts
[:
tp
+
1
],
axis
=
0
)
trap_centre
=
self
.
centre
-
np
.
sum
(
drifts
[:
tp
+
1
],
axis
=
0
)
return
trap_centre
###
###
def
as_tile
(
self
,
tp
):
def
as_tile
(
self
,
tp
):
"""
"""
Return trap in the OMERO tile format of x, y, w, h
Return trap in the OMERO tile format of x, y, w, h
Also returns the padding necessary for this tile.
where x, y are at the bottom left corner of the tile
and w and h are the tile width and height.
Parameters
Parameters
----------
----------
tp: integer
tp: integer
Index for a time point
Index for a time point
Returns
-------
x: int
x-coordinate of bottom left corner of tile
y: int
y-coordinate of bottom left corner of tile
w: int
Width of tile
h: int
Height of tile
"""
"""
x
,
y
=
self
.
at_time
(
tp
)
x
,
y
=
self
.
at_time
(
tp
)
# tile bottom corner
# tile bottom corner
...
@@ -87,6 +104,11 @@ class Trap:
...
@@ -87,6 +104,11 @@ class Trap:
----------
----------
tp: integer
tp: integer
Index for a time point
Index for a time point
Returns
-------
A slice of x coordinates from left to right
A slice of y coordinates from top to bottom
"""
"""
x
,
y
,
w
,
h
=
self
.
as_tile
(
tp
)
x
,
y
,
w
,
h
=
self
.
as_tile
(
tp
)
return
slice
(
x
,
x
+
w
),
slice
(
y
,
y
+
h
)
return
slice
(
x
,
x
+
w
),
slice
(
y
,
y
+
h
)
...
@@ -427,6 +449,8 @@ class Tiler(ProcessABC):
...
@@ -427,6 +449,8 @@ class Tiler(ProcessABC):
def
get_tp_data
(
self
,
tp
,
c
):
def
get_tp_data
(
self
,
tp
,
c
):
"""
"""
Returns all traps corrected for drift.
Parameters
Parameters
----------
----------
tp: integer
tp: integer
...
@@ -435,8 +459,10 @@ class Tiler(ProcessABC):
...
@@ -435,8 +459,10 @@ class Tiler(ProcessABC):
An index for a channel
An index for a channel
"""
"""
traps
=
[]
traps
=
[]
# get OMERO image
full
=
self
.
get_tc
(
tp
,
c
)
full
=
self
.
get_tc
(
tp
,
c
)
for
trap
in
self
.
trap_locs
:
for
trap
in
self
.
trap_locs
:
# pad trap if necessary
ndtrap
=
self
.
ifoob_pad
(
full
,
trap
.
as_range
(
tp
))
ndtrap
=
self
.
ifoob_pad
(
full
,
trap
.
as_range
(
tp
))
traps
.
append
(
ndtrap
)
traps
.
append
(
ndtrap
)
return
np
.
stack
(
traps
)
return
np
.
stack
(
traps
)
...
@@ -444,6 +470,23 @@ class Tiler(ProcessABC):
...
@@ -444,6 +470,23 @@ class Tiler(ProcessABC):
###
###
def
get_trap_data
(
self
,
trap_id
,
tp
,
c
):
def
get_trap_data
(
self
,
trap_id
,
tp
,
c
):
"""
Returns a particular trap corrected for drift and padding
Parameters
----------
trap_id: integer
Number of trap
tp: integer
Index of time points
c: integer
Index of channel
Returns
-------
ndtrap: array
An array of (x, y) arrays, one for each z stack
"""
full
=
self
.
get_tc
(
tp
,
c
)
full
=
self
.
get_tc
(
tp
,
c
)
trap
=
self
.
trap_locs
.
traps
[
trap_id
]
trap
=
self
.
trap_locs
.
traps
[
trap_id
]
ndtrap
=
self
.
ifoob_pad
(
full
,
trap
.
as_range
(
tp
))
ndtrap
=
self
.
ifoob_pad
(
full
,
trap
.
as_range
(
tp
))
...
@@ -504,6 +547,14 @@ class Tiler(ProcessABC):
...
@@ -504,6 +547,14 @@ class Tiler(ProcessABC):
###
###
def
get_channel_index
(
self
,
item
):
def
get_channel_index
(
self
,
item
):
"""
Find index for channel
Parameters
----------
item: string
The channel
"""
for
i
,
ch
in
enumerate
(
self
.
channels
):
for
i
,
ch
in
enumerate
(
self
.
channels
):
if
item
in
ch
:
if
item
in
ch
:
return
i
return
i
...
@@ -519,33 +570,40 @@ class Tiler(ProcessABC):
...
@@ -519,33 +570,40 @@ class Tiler(ProcessABC):
@staticmethod
@staticmethod
def
ifoob_pad
(
full
,
slices
):
# TODO Remove when inheriting TilerABC
def
ifoob_pad
(
full
,
slices
):
# TODO Remove when inheriting TilerABC
"""
"""
Returns the slices padded if it is out of bounds
Returns the slices padded if it is out of bounds
.
Parameters
:
Parameters
----------
----------
full: (zstacks, max_size, max_size) ndarray
full: array
Entire position with zstacks as first axis
Slice of OMERO image (zstacks, x, y) - the entire position
with zstacks as first axis
slices: tuple of two slices
slices: tuple of two slices
Each slice indicates an axis to index
Delineates indiceds for the x- and y- ranges of the tile.
Returns
Returns
Trap for given slices, padded with median if needed, or np.nan if the padding is too much
-------
trap: array
A tile with all z stacks for the given slices.
If some padding is needed, the median of the image is used.
If much padding is needed, a tile of NaN is returned.
"""
"""
# number of pixels in the y direction
max_size
=
full
.
shape
[
-
1
]
max_size
=
full
.
shape
[
-
1
]
# ignore parts of the tile outside of the image
y
,
x
=
[
slice
(
max
(
0
,
s
.
start
),
min
(
max_size
,
s
.
stop
))
for
s
in
slices
]
y
,
x
=
[
slice
(
max
(
0
,
s
.
start
),
min
(
max_size
,
s
.
stop
))
for
s
in
slices
]
# get the tile including all z stacks
trap
=
full
[:,
y
,
x
]
trap
=
full
[:,
y
,
x
]
# find extent of padding needed in x and y
padding
=
np
.
array
(
padding
=
np
.
array
(
[(
-
min
(
0
,
s
.
start
),
-
min
(
0
,
max_size
-
s
.
stop
))
for
s
in
slices
]
[(
-
min
(
0
,
s
.
start
),
-
min
(
0
,
max_size
-
s
.
stop
))
for
s
in
slices
]
)
)
if
padding
.
any
():
if
padding
.
any
():
tile_size
=
slices
[
0
].
stop
-
slices
[
0
].
start
tile_size
=
slices
[
0
].
stop
-
slices
[
0
].
start
if
(
padding
>
tile_size
/
4
).
any
():
if
(
padding
>
tile_size
/
4
).
any
():
# too much of the tile is outside of the image
# fill with NaN
trap
=
np
.
full
((
full
.
shape
[
0
],
tile_size
,
tile_size
),
np
.
nan
)
trap
=
np
.
full
((
full
.
shape
[
0
],
tile_size
,
tile_size
),
np
.
nan
)
else
:
else
:
# pad tile with median value of trap image
trap
=
np
.
pad
(
trap
,
[[
0
,
0
]]
+
padding
.
tolist
(),
"
median
"
)
trap
=
np
.
pad
(
trap
,
[[
0
,
0
]]
+
padding
.
tolist
(),
"
median
"
)
return
trap
return
trap
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