Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aliby-mirror
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
aliby-mirror
Commits
f31d1b10
Commit
f31d1b10
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
feat(grouper): add mode "families" and "daughter"
parent
9231b2b4
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/agora/io/signal.py
+5
-3
5 additions, 3 deletions
src/agora/io/signal.py
src/agora/utils/kymograph.py
+42
-0
42 additions, 0 deletions
src/agora/utils/kymograph.py
src/postprocessor/grouper.py
+25
-4
25 additions, 4 deletions
src/postprocessor/grouper.py
with
72 additions
and
7 deletions
src/agora/io/signal.py
+
5
−
3
View file @
f31d1b10
...
@@ -41,11 +41,13 @@ class Signal(BridgeH5):
...
@@ -41,11 +41,13 @@ class Signal(BridgeH5):
def
__getitem__
(
self
,
dsets
:
t
.
Union
[
str
,
t
.
Collection
]):
def
__getitem__
(
self
,
dsets
:
t
.
Union
[
str
,
t
.
Collection
]):
if
isinstance
(
dsets
,
str
)
and
dsets
.
endswith
(
"
imBackground
"
):
if
isinstance
(
dsets
,
str
):
# or isinstance(Dsets,dsets.endswith("imBackground"):
df
=
self
.
get_raw
(
dsets
)
df
=
self
.
get_raw
(
dsets
)
elif
isinstance
(
dsets
,
str
):
#
elif isinstance(dsets, str):
df
=
self
.
apply_prepost
(
dsets
)
#
df = self.apply_prepost(dsets)
elif
isinstance
(
dsets
,
list
):
elif
isinstance
(
dsets
,
list
):
is_bgd
=
[
dset
.
endswith
(
"
imBackground
"
)
for
dset
in
dsets
]
is_bgd
=
[
dset
.
endswith
(
"
imBackground
"
)
for
dset
in
dsets
]
...
...
This diff is collapsed.
Click to expand it.
src/agora/utils/kymograph.py
+
42
−
0
View file @
f31d1b10
...
@@ -2,8 +2,11 @@
...
@@ -2,8 +2,11 @@
import
typing
as
t
import
typing
as
t
from
copy
import
copy
from
copy
import
copy
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
index_row
=
t
.
Tuple
[
str
,
str
,
int
,
int
]
def
add_index_levels
(
def
add_index_levels
(
df
:
pd
.
DataFrame
,
additional_ids
:
t
.
Dict
[
str
,
pd
.
Series
]
=
{}
df
:
pd
.
DataFrame
,
additional_ids
:
t
.
Dict
[
str
,
pd
.
Series
]
=
{}
...
@@ -16,3 +19,42 @@ def add_index_levels(
...
@@ -16,3 +19,42 @@ def add_index_levels(
new_df
[
k
]
=
srs
new_df
[
k
]
=
srs
new_df
.
set_index
(
k
,
inplace
=
True
,
append
=
True
)
new_df
.
set_index
(
k
,
inplace
=
True
,
append
=
True
)
return
new_df
return
new_df
def
drop_level
(
df
:
pd
.
DataFrame
,
name
:
str
=
"
mother_label
"
,
as_list
:
bool
=
True
)
->
t
.
Union
[
t
.
List
[
index_row
],
pd
.
Index
]:
"""
Drop index level
Parameters
----------
df : pd.DataFrame
dataframe whose multiindex we will drop
name : str
name of index level to drop
as_list : bool
Whether to return as a list instead of an index
Examples
--------
FIXME: Add docs.
"""
short_index
=
df
.
index
.
droplevel
(
name
)
if
as_list
:
short_index
=
short_index
.
to_list
()
return
short_index
def
intersection_matrix
(
index1
:
pd
.
MultiIndex
,
index2
:
pd
.
MultiIndex
)
->
np
.
ndarray
:
"""
Use casting to obtain the boolean mask of the intersection of two multiindices
"""
if
not
isinstance
(
index1
,
np
.
ndarray
):
index1
=
np
.
array
(
index1
.
to_list
())
if
not
isinstance
(
index2
,
np
.
ndarray
):
index2
=
np
.
array
(
index2
.
to_list
())
return
(
index1
[...,
None
]
==
index2
.
T
).
all
(
axis
=
1
)
This diff is collapsed.
Click to expand it.
src/postprocessor/grouper.py
+
25
−
4
View file @
f31d1b10
...
@@ -13,9 +13,11 @@ import matplotlib.pyplot as plt
...
@@ -13,9 +13,11 @@ import matplotlib.pyplot as plt
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
import
seaborn
as
sns
import
seaborn
as
sns
from
postprocessor.chainer
import
Chainer
from
pathos.multiprocessing
import
Pool
from
pathos.multiprocessing
import
Pool
from
agora.utils.kymograph
import
drop_level
,
intersection_matrix
from
postprocessor.chainer
import
Chainer
class
Grouper
(
ABC
):
class
Grouper
(
ABC
):
"""
Base grouper class.
"""
"""
Base grouper class.
"""
...
@@ -83,7 +85,7 @@ class Grouper(ABC):
...
@@ -83,7 +85,7 @@ class Grouper(ABC):
standard
:
t
.
Optional
[
bool
]
=
False
,
standard
:
t
.
Optional
[
bool
]
=
False
,
**
kwargs
,
**
kwargs
,
):
):
"""
Concate
"""
Concate
nate multiple signals
Parameters
Parameters
----------
----------
...
@@ -390,12 +392,31 @@ def concat_signal_ind(
...
@@ -390,12 +392,31 @@ def concat_signal_ind(
raise
(
NotImplementedError
)
raise
(
NotImplementedError
)
elif
mode
==
"
raw
"
:
elif
mode
==
"
raw
"
:
combined
=
chainer
.
get_raw
(
path
,
**
kwargs
)
combined
=
chainer
.
get_raw
(
path
,
**
kwargs
)
elif
mode
==
"
daughters
"
:
combined
=
chainer
.
get_raw
(
path
,
**
kwargs
)
combined
=
combined
.
loc
[
combined
.
index
.
get_level_values
(
"
mother_label
"
)
>
0
]
elif
mode
==
"
families
"
:
elif
mode
==
"
families
"
:
combined
=
chainer
[
path
]
combined
=
chainer
.
get_raw
(
path
,
**
kwargs
)
daughter_ids
=
combined
.
index
[
combined
.
index
.
get_level_values
(
"
mother_label
"
)
>
0
]
mother_id_mask
=
intersection_matrix
(
daughter_ids
.
droplevel
(
"
cell_label
"
),
drop_level
(
combined
,
"
mother_label
"
,
as_list
=
False
),
).
any
(
axis
=
0
)
combined
=
combined
.
loc
[
combined
.
index
[
mother_id_mask
].
union
(
daughter_ids
)
]
combined
[
"
position
"
]
=
position
combined
[
"
position
"
]
=
position
combined
[
"
group
"
]
=
group
combined
[
"
group
"
]
=
group
combined
.
set_index
([
"
group
"
,
"
position
"
],
inplace
=
True
,
append
=
True
)
combined
.
set_index
([
"
group
"
,
"
position
"
],
inplace
=
True
,
append
=
True
)
combined
.
index
=
combined
.
index
.
swaplevel
(
-
2
,
0
).
swaplevel
(
-
1
,
1
)
# combined.index = combined.index.swaplevel(-2, 0).swaplevel(-1, 1)
combined
.
index
=
combined
.
index
.
reorder_levels
(
(
"
group
"
,
"
position
"
,
"
trap
"
,
"
cell_label
"
,
"
mother_label
"
)
)
return
combined
return
combined
...
...
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