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
d29beecc
Commit
d29beecc
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
fix(extraction): merge validation works
parent
f1aba90c
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/agora/io/signal.py
+48
-11
48 additions, 11 deletions
src/agora/io/signal.py
with
48 additions
and
11 deletions
src/agora/io/signal.py
+
48
−
11
View file @
d29beecc
...
@@ -129,24 +129,23 @@ class Signal(BridgeH5):
...
@@ -129,24 +129,23 @@ class Signal(BridgeH5):
merges
=
self
.
get_merges
()
merges
=
self
.
get_merges
()
df
=
self
.
get_raw
(
dataset
)
df
=
self
.
get_raw
(
dataset
)
merged
=
copy
(
df
)
merged
=
copy
(
df
)
if
merges
.
any
():
if
merges
.
any
():
# Split in two dfs, one with rows relevant for merging and one
# Split in two dfs, one with rows relevant for merging and one
# without them
# without them
valid_merges
=
merges
[
valid_merges
=
validate_merges
(
merges
,
np
.
array
(
list
(
df
.
index
)))
(
merges
[:,
:,
:,
None
]
==
np
.
array
(
list
(
df
.
index
)).
T
[:,
None
,
:]
)
.
all
(
axis
=
(
1
,
2
))
.
any
(
axis
=
1
)
]
# Casting allows fast multiindexing
# TODO use the same info from validate_merges to select both
valid_indices
=
[
tuple
(
x
)
for
x
in
(
np
.
unique
(
valid_merges
.
reshape
(
-
1
,
2
),
axis
=
0
))
]
merged
=
self
.
apply_merge
(
merged
=
self
.
apply_merge
(
df
.
loc
[
map
(
tuple
,
valid_merges
.
reshape
(
-
1
,
2
))
],
df
.
loc
[
valid_indices
],
valid_merges
,
valid_merges
,
)
)
nonmergeable_ids
=
df
.
index
.
difference
(
valid_
merges
.
reshape
(
-
1
,
2
)
)
nonmergeable_ids
=
df
.
index
.
difference
(
valid_
indices
)
merged
=
pd
.
concat
(
merged
=
pd
.
concat
(
(
merged
,
df
.
loc
[
nonmergeable_ids
]),
names
=
df
.
index
.
names
(
merged
,
df
.
loc
[
nonmergeable_ids
]),
names
=
df
.
index
.
names
...
@@ -339,7 +338,8 @@ class Signal(BridgeH5):
...
@@ -339,7 +338,8 @@ class Signal(BridgeH5):
@staticmethod
@staticmethod
def
join_tracks_pair
(
target
:
pd
.
Series
,
source
:
pd
.
Series
):
def
join_tracks_pair
(
target
:
pd
.
Series
,
source
:
pd
.
Series
):
"""
"""
Join two tracks
Join two tracks and return the new value of the target.
TODO replace this with arrays only.
"""
"""
tgt_copy
=
copy
(
target
)
tgt_copy
=
copy
(
target
)
end
=
find_1st
(
target
.
values
[::
-
1
],
0
,
cmp_larger
)
end
=
find_1st
(
target
.
values
[::
-
1
],
0
,
cmp_larger
)
...
@@ -388,3 +388,40 @@ class Signal(BridgeH5):
...
@@ -388,3 +388,40 @@ class Signal(BridgeH5):
if
end
<=
self
.
max_span
if
end
<=
self
.
max_span
]
]
return
tuple
((
stage
,
ntps
)
for
stage
,
ntps
in
zip
(
self
.
stages
,
spans
))
return
tuple
((
stage
,
ntps
)
for
stage
,
ntps
in
zip
(
self
.
stages
,
spans
))
def
validate_merges
(
merges
:
np
.
ndarray
,
indices
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Select rows from the first array that are present in both.
We use casting for fast multiindexing
Parameters
----------
merges : np.ndarray
2-D array where columns are (trap, mother, daughter) or 3-D array where
dimensions are (X, (trap,mother), (trap,daughter))
indices : np.ndarray
2-D array where each column is a different level.
Returns
-------
np.ndarray
3-D array with elements in both arrays.
Examples
--------
FIXME: Add docs.
"""
if
merges
.
ndim
<
3
:
# Reshape into 3-D array for casting if neded
merges
=
np
.
stack
((
merges
[:,
[
0
,
1
]],
merges
[:,
[
0
,
2
]]),
axis
=
1
)
# Compare existing merges with available indices
# Swap trap and label axes for the merges array to correctly cast
# valid_ndmerges = merges.swapaxes(1, 2)[..., None] == indices.T[:, None, :]
valid_ndmerges
=
merges
[...,
None
]
==
indices
.
T
[
None
,
...]
valid_merges
=
merges
[
valid_ndmerges
.
all
(
axis
=
2
).
any
(
axis
=
2
).
any
(
axis
=
1
)]
# valid_merges = merges[allnan.any(axis=1)]
return
valid_merges
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