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
897da295
Commit
897da295
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
refactor(signal): use decorator to parse input
parent
0c6d7660
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
+25
-12
25 additions, 12 deletions
src/agora/io/signal.py
with
25 additions
and
12 deletions
src/agora/io/signal.py
+
25
−
12
View file @
897da295
...
...
@@ -9,6 +9,7 @@ import pandas as pd
from
utils_find_1st
import
cmp_larger
,
find_1st
from
agora.io.bridge
import
BridgeH5
from
agora.io.decorators
import
_first_arg_str_to_df
class
Signal
(
BridgeH5
):
...
...
@@ -122,18 +123,24 @@ class Signal(BridgeH5):
).
T
return
lineage
def
apply_prepost
(
self
,
dataset
:
str
,
skip_pick
:
t
.
Optional
[
bool
]
=
None
):
@_first_arg_str_to_df
def
apply_prepost
(
self
,
data
:
t
.
Union
[
str
,
pd
.
DataFrame
],
merges
:
np
.
ndarray
=
None
,
picks
:
t
.
Optional
[
bool
]
=
None
,
):
"""
Apply modifier operations (picker, merger) to a given dataframe.
"""
merges
=
self
.
get_merges
()
df
=
self
.
get_
raw
(
dataset
)
merged
=
copy
(
d
f
)
if
merges
is
None
:
merges
=
self
.
get_
merges
(
)
merged
=
copy
(
d
ata
)
if
merges
.
any
():
# Split in two dfs, one with rows relevant for merging and one
# without them
valid_merges
=
validate_merges
(
merges
,
np
.
array
(
list
(
d
f
.
index
)))
valid_merges
=
validate_merges
(
merges
,
np
.
array
(
list
(
d
ata
.
index
)))
# TODO use the same info from validate_merges to select both
valid_indices
=
[
...
...
@@ -141,18 +148,18 @@ class Signal(BridgeH5):
for
x
in
(
np
.
unique
(
valid_merges
.
reshape
(
-
1
,
2
),
axis
=
0
))
]
merged
=
self
.
apply_merge
(
d
f
.
loc
[
valid_indices
],
d
ata
.
loc
[
valid_indices
],
valid_merges
,
)
nonmergeable_ids
=
d
f
.
index
.
difference
(
valid_indices
)
nonmergeable_ids
=
d
ata
.
index
.
difference
(
valid_indices
)
merged
=
pd
.
concat
(
(
merged
,
d
f
.
loc
[
nonmergeable_ids
]),
names
=
d
f
.
index
.
names
(
merged
,
d
ata
.
loc
[
nonmergeable_ids
]),
names
=
d
ata
.
index
.
names
)
with
h5py
.
File
(
self
.
filename
,
"
r
"
)
as
f
:
if
"
modifiers/picks
"
in
f
and
not
skip_
pick
:
if
"
modifiers/picks
"
in
f
and
not
pick
s
:
picks
=
self
.
get_picks
(
names
=
merged
.
index
.
names
)
# missing_cells = [i for i in picks if tuple(i) not in
# set(merged.index)]
...
...
@@ -163,7 +170,7 @@ class Signal(BridgeH5):
[
tuple
(
x
)
for
x
in
merged
.
index
]
)
]
return
merged
.
loc
[
picks
]
else
:
if
isinstance
(
merged
.
index
,
pd
.
MultiIndex
):
empty_lvls
=
[[]
for
i
in
merged
.
index
.
names
]
...
...
@@ -236,7 +243,7 @@ class Signal(BridgeH5):
return
df
def
get_raw
(
self
,
dataset
,
in_minutes
=
True
):
def
get_raw
(
self
,
dataset
:
str
,
in_minutes
:
bool
=
True
):
try
:
if
isinstance
(
dataset
,
str
):
with
h5py
.
File
(
self
.
filename
,
"
r
"
)
as
f
:
...
...
@@ -268,7 +275,13 @@ class Signal(BridgeH5):
else
:
return
None
def
dataset_to_df
(
self
,
f
:
h5py
.
File
,
path
:
str
):
def
dataset_to_df
(
self
,
f
:
h5py
.
File
,
path
:
str
)
->
pd
.
DataFrame
:
"""
Fetch DataFrame from results storage file.
"""
assert
path
in
f
,
f
"
{
path
}
not in
{
f
}
"
dset
=
f
[
path
]
index_names
=
copy
(
self
.
index_names
)
...
...
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