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
39d3a644
Commit
39d3a644
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
fix(meta): allow metadata absence
parent
1ebd37bd
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/metadata.py
+26
-17
26 additions, 17 deletions
src/agora/io/metadata.py
with
26 additions
and
17 deletions
src/agora/io/metadata.py
+
26
−
17
View file @
39d3a644
...
...
@@ -9,6 +9,7 @@ ALIBY decides on using different metadata parsers based on two elements:
If parameters is a string pointing to a metadata file, ALIBY picks a parser based on the file format.
If parameters is True (as a boolean), ALIBY searches for any available file and uses the first valid one.
If there are no metadata files, ALIBY requires indicating indices for tiler, segmentation and extraction.
"""
import
glob
import
os
...
...
@@ -67,7 +68,9 @@ def flatten_dict(nested_dict, separator="/"):
Flattens nested dictionary
"""
df
=
pd
.
json_normalize
(
nested_dict
,
sep
=
separator
)
return
df
.
to_dict
(
orient
=
"
records
"
)[
0
]
flattened
=
df
.
to_dict
(
orient
=
"
records
"
)
or
{}
return
flattened
# Needed because HDF5 attributes do not support datetime objects
...
...
@@ -109,22 +112,20 @@ def parse_logfiles(
# ACQ_FILE = 'flavin_htb2_glucose_long_ramp_DelftAcq.txt'
# LOG_FILE = 'flavin_htb2_glucose_long_ramp_Delftlog.txt'
log_parser
=
Parser
(
log_grammar
)
try
:
log_file
=
find_file
(
root_dir
,
"
*log.txt
"
)
except
FileNotFoundError
:
raise
ValueError
(
"
Experiment log file not found.
"
)
with
open
(
log_file
,
"
r
"
)
as
f
:
log_parsed
=
log_parser
.
parse
(
f
)
acq_parser
=
Parser
(
acq_grammar
)
try
:
acq_file
=
find_file
(
root_dir
,
"
*[Aa]cq.txt
"
)
except
FileNotFoundError
:
raise
ValueError
(
"
Experiment acq file not found.
"
)
with
open
(
acq_file
,
"
r
"
)
as
f
:
acq_parsed
=
acq_parser
.
parse
(
f
)
parsed
=
{
**
acq_parsed
,
**
log_parsed
}
log_file
=
find_file
(
root_dir
,
"
*log.txt
"
)
acq_file
=
find_file
(
root_dir
,
"
*[Aa]cq.txt
"
)
parsed
=
{}
if
log_file
and
acq_file
:
with
open
(
log_file
,
"
r
"
)
as
f
:
log_parsed
=
log_parser
.
parse
(
f
)
with
open
(
acq_file
,
"
r
"
)
as
f
:
acq_parsed
=
acq_parser
.
parse
(
f
)
parsed
=
{
**
acq_parsed
,
**
log_parsed
}
for
key
,
value
in
parsed
.
items
():
if
isinstance
(
value
,
datetime
):
...
...
@@ -186,7 +187,9 @@ def parse_swainlab_metadata(filedir: t.Union[str, PosixPath]):
if
filedir
.
is_file
():
filedir
=
filedir
.
parent
legacy_parse
=
parse_logfiles
(
filedir
)
minimal_meta
=
get_meta_from_legacy
(
legacy_parse
)
minimal_meta
=
(
get_meta_from_legacy
(
legacy_parse
)
if
legacy_parse
else
{}
)
return
minimal_meta
...
...
@@ -195,5 +198,11 @@ def dispatch_metadata_parser(filepath: t.Union[str, PosixPath]):
"""
Function to dispatch different metadata parsers that convert logfiles into a
basic metadata dictionary. Currently only contains the swainlab log parsers.
Input:
--------
filepath: str existing file containing metadata, or folder containing naming conventions
"""
return
parse_swainlab_metadata
(
filepath
)
parsed_meta
=
parse_swainlab_metadata
(
filepath
)
return
parsed_meta
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