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
551acc74
Commit
551acc74
authored
10 months ago
by
Peter Swain
Browse files
Options
Downloads
Patches
Plain Diff
feature(bud_to_bud_plot): more than one bud event
parent
3451a53e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/wela/plotting.py
+44
-17
44 additions, 17 deletions
src/wela/plotting.py
with
44 additions
and
17 deletions
src/wela/plotting.py
+
44
−
17
View file @
551acc74
...
@@ -610,6 +610,7 @@ def bud_to_bud_plot(
...
@@ -610,6 +610,7 @@ def bud_to_bud_plot(
colour
=
"
b
"
,
colour
=
"
b
"
,
group
=
None
,
group
=
None
,
nbins
=
None
,
nbins
=
None
,
no_future_buddings
=
2
,
return_signal
=
False
,
return_signal
=
False
,
df
=
None
,
df
=
None
,
title
=
None
,
title
=
None
,
...
@@ -636,9 +637,11 @@ def bud_to_bud_plot(
...
@@ -636,9 +637,11 @@ def bud_to_bud_plot(
Colour of lines.
Colour of lines.
group: str, optional
group: str, optional
The name of the group to plot.
The name of the group to plot.
nbins: int
eger
, optional
nbins: int, optional
The number of time bins to partition the interval between the
The number of time bins to partition the interval between the
first and the second budding event.
first and the second budding event.
no_future_buddings: int, optional
The number of future budding events to include. Default is 1.
return_signal: boolean, optional
return_signal: boolean, optional
If True, return the signal for each cell interpolated to the time
If True, return the signal for each cell interpolated to the time
bins.
bins.
...
@@ -673,29 +676,24 @@ def bud_to_bud_plot(
...
@@ -673,29 +676,24 @@ def bud_to_bud_plot(
t
=
t
/
60
t
=
t
/
60
tpt_i
=
np
.
argmin
((
t
-
tpt
)
**
2
)
tpt_i
=
np
.
argmin
((
t
-
tpt
)
**
2
)
# get data for bud-to-bud around tpt for each cell
# get data for bud-to-bud around tpt for each cell
local_signals
,
local_times
=
[],
[]
local_signals
,
local_times
=
get_bud_to_bud_data
(
for
i
in
range
(
signal_data
.
shape
[
0
]):
tpt_i
,
future_buddings
=
np
.
nonzero
(
buddings
[
i
,
:][
tpt_i
:])[
0
]
t
,
if
np
.
any
(
future_buddings
):
signal_data
,
end_tpt_i
=
tpt_i
+
future_buddings
[
0
]
buddings
,
past_buddings
=
np
.
nonzero
(
buddings
[
i
,
:][:
tpt_i
])[
0
]
no_future_buddings_index
=
no_future_buddings
-
1
,
if
np
.
any
(
past_buddings
):
)
start_tpt_i
=
past_buddings
[
-
1
]
local_data
=
signal_data
[
i
,
start_tpt_i
:
end_tpt_i
+
1
]
if
~
np
.
all
(
np
.
isnan
(
local_data
)):
local_signals
.
append
(
local_data
)
local_times
.
append
(
t
[
start_tpt_i
:
end_tpt_i
+
1
])
if
local_times
:
if
local_times
:
# find bins for normalised time, between 0 and
1
# find bins for normalised time, between 0 and
no_future_buddings
nbins
=
int
(
np
.
median
([
len
(
local_time
)
for
local_time
in
local_times
]))
nbins
=
int
(
np
.
median
([
len
(
local_time
)
for
local_time
in
local_times
]))
ntbins
=
np
.
linspace
(
0
,
1
,
nbins
)
ntbins
=
np
.
linspace
(
0
,
no_future_buddings
,
nbins
)
# interpolate each local signal to make a new signal
# interpolate each local signal to make a new signal
new_signal
=
np
.
nan
*
np
.
ones
((
len
(
local_signals
),
nbins
))
new_signal
=
np
.
nan
*
np
.
ones
((
len
(
local_signals
),
nbins
))
for
i
in
range
(
len
(
local_signals
)):
for
i
in
range
(
len
(
local_signals
)):
s
=
local_signals
[
i
]
s
=
local_signals
[
i
]
# normalise time between 0 and
1
# normalise time between 0 and
no_future_buddings
nt
=
local_times
[
i
]
-
local_times
[
i
][
0
]
nt
=
local_times
[
i
]
-
local_times
[
i
][
0
]
nt
/
=
nt
[
-
1
]
nt
=
nt
/
nt
[
-
1
]
*
no_future_buddings
# interpolate into the bins
# interpolate into the bins
new_signal
[
i
,
:]
=
np
.
interp
(
new_signal
[
i
,
:]
=
np
.
interp
(
ntbins
,
ntbins
,
...
@@ -727,3 +725,32 @@ def bud_to_bud_plot(
...
@@ -727,3 +725,32 @@ def bud_to_bud_plot(
plt
.
show
(
block
=
False
)
plt
.
show
(
block
=
False
)
if
return_signal
:
if
return_signal
:
return
new_signal
return
new_signal
def
get_bud_to_bud_data
(
tpt_i
,
t
,
signal_data
,
buddings
,
no_future_buddings_index
=
0
):
"""
Get data for bud-to-bud around tpt for each cell.
Parameters
----------
no_future_buddings_index: int
The index to select future buddings, with 0 representing the next
budding event.
"""
local_signals
,
local_times
=
[],
[]
for
i
in
range
(
signal_data
.
shape
[
0
]):
future_buddings
=
np
.
nonzero
(
buddings
[
i
,
:][
tpt_i
:])[
0
]
if
np
.
any
(
future_buddings
)
and
(
future_buddings
.
size
>
no_future_buddings_index
):
end_tpt_i
=
tpt_i
+
future_buddings
[
no_future_buddings_index
]
past_buddings
=
np
.
nonzero
(
buddings
[
i
,
:][:
tpt_i
])[
0
]
if
np
.
any
(
past_buddings
):
start_tpt_i
=
past_buddings
[
-
1
]
local_data
=
signal_data
[
i
,
start_tpt_i
:
end_tpt_i
+
1
]
if
~
np
.
all
(
np
.
isnan
(
local_data
)):
local_signals
.
append
(
local_data
)
local_times
.
append
(
t
[
start_tpt_i
:
end_tpt_i
+
1
])
return
local_signals
,
local_times
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