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
0cb3d522
Commit
0cb3d522
authored
3 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
extend Writer
Former-commit-id: 9a3489325bf848362c0cbd27cc8949cca029376e
parent
eccf820d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/io/writer.py
+36
-5
36 additions, 5 deletions
core/io/writer.py
with
36 additions
and
5 deletions
core/io/writer.py
+
36
−
5
View file @
0cb3d522
from
itertools
import
accumulate
import
h5py
import
h5py
import
pandas
as
pd
import
pandas
as
pd
...
@@ -5,15 +7,44 @@ from postprocessor.core.io.base import BridgeH5
...
@@ -5,15 +7,44 @@ from postprocessor.core.io.base import BridgeH5
def
Writer
(
BridgeH5
):
def
Writer
(
BridgeH5
):
def
__init__
(
self
,
filename
):
"""
self
.
_hdf
=
h5py
.
File
(
filename
,
"
a
"
)
Class in charge of transforming data into compatible formats
Decoupling interface from implementation!
:hdfname: Name of file to write into
"""
def
__init__
(
self
,
hdfname
):
self
.
_hdf
=
h5py
.
Hdf
(
hdfname
,
"
a
"
)
def
write
(
self
,
address
,
data
):
def
write
(
self
,
address
,
data
):
self
.
_
file
.
add_group
(
address
)
self
.
_
hdf
.
add_group
(
address
)
if
type
(
data
)
is
pd
.
DataFrame
:
if
type
(
data
)
is
pd
.
DataFrame
:
self
.
write_df
(
address
,
data
)
self
.
write_df
(
address
,
data
)
elif
type
(
data
)
is
np
.
array
:
elif
type
(
data
)
is
np
.
array
:
self
.
write_np
(
address
,
data
)
self
.
write_np
(
address
,
data
)
def
write_df
(
self
,
adress
,
df
):
def
write_np
(
self
,
address
,
array
):
self
.
_file
.
get
(
address
)[()]
=
data
pass
def
write_df
(
self
,
df
,
tps
,
path
):
print
(
"
writing to
"
,
path
)
for
item
in
accummulate
(
path
.
split
(
"
/
"
)[:
-
2
]):
if
item
not
in
self
.
_hdf
:
self
.
_hdf
.
create_group
(
item
)
pos_group
=
f
[
path
.
split
(
"
/
"
)[
1
]]
if
path
not
in
pos_group
:
pos_group
.
create_dataset
(
name
=
path
,
shape
=
df
.
shape
,
dtype
=
df
.
dtypes
[
0
])
new_dset
=
f
[
path
]
new_dset
[()]
=
df
.
values
if
len
(
df
.
index
.
names
)
>
1
:
trap
,
cell_label
=
zip
(
*
list
(
df
.
index
.
values
))
new_dset
.
attrs
[
"
trap
"
]
=
trap
new_dset
.
attrs
[
"
cell_label
"
]
=
cell_label
new_dset
.
attrs
[
"
idnames
"
]
=
[
"
trap
"
,
"
cell_label
"
]
else
:
new_dset
.
attrs
[
"
trap
"
]
=
list
(
df
.
index
.
values
)
new_dset
.
attrs
[
"
idnames
"
]
=
[
"
trap
"
]
pos_group
.
attrs
[
"
processed_timepoints
"
]
=
tps
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