Skip to content
Snippets Groups Projects
Commit 3bffeb68 authored by François  LAURENT's avatar François LAURENT
Browse files

labels2tags

parent b348b926
Branches
Tags
2 merge requests!6Set of commits to be tagged v0.16,!5Experimental support for MaggotUBA's larva_dataset hdf5 files
Pipeline #115890 passed
...@@ -51,5 +51,5 @@ git-tree-sha1 = "1dec5e1c33044d972466d03ca5b8816b9861eb5f" ...@@ -51,5 +51,5 @@ git-tree-sha1 = "1dec5e1c33044d972466d03ca5b8816b9861eb5f"
lazy = true lazy = true
[[sample_training_dataset.download]] [[sample_training_dataset.download]]
url = "https://dl.pasteur.fr/fop/Wa2niN3o/sample_training_dataset.tgz" url = "https://dl.pasteur.fr/fop/DKgeHrAl/sample_training_dataset.tgz"
sha256 = "5f1fc870185252a6c4d79ce113c6d98e30107610ee11029642e2e72b7d62c1a0" sha256 = "5f1fc870185252a6c4d79ce113c6d98e30107610ee11029642e2e72b7d62c1a0"
...@@ -352,7 +352,8 @@ function astimeseries(track::Track) ...@@ -352,7 +352,8 @@ function astimeseries(track::Track)
return timeseries return timeseries
end end
function astimeseries(run::Run) function astimeseries(run::Run; labels2tags=false)
labels2tags && return astimeseries(Formats.labels2tags(run))
track = first(values(run.tracks)) track = first(values(run.tracks))
firststate = asnamedtuple(track.states, 1) firststate = asnamedtuple(track.states, 1)
T = typeof(firststate) T = typeof(firststate)
...@@ -433,6 +434,34 @@ function appendtags(timeseries, run) ...@@ -433,6 +434,34 @@ function appendtags(timeseries, run)
return newtimeseries return newtimeseries
end end
"""
labels2tags(run)
Make a copy with labels converted into behavior tags.
"""
function labels2tags(run::Run)
labels, attr = Datasets.getlabels(run)
if labels isa AbstractDict
labels = labels[:names]
end
if eltype(labels) !== Symbol
labels = Symbol.(labels)
end
labels2tags′(label) = labels2tags(labels, label)
#
tracks′= Track[]
for track in values(run.tracks)
records′= OrderedDict(rec===attr ? :tags=>labels2tags′.(vals) : rec=>vals
for (rec, vals) in pairs(track.states))
track′= Track(track.id, track.attributes, track.timestamps, records′)
push!(tracks′, track′)
end
Run(run.id, run.attributes, tracks′)
end
labels2tags(labels::Vector{Symbol}, label) = BehaviorTags(Symbol.(labels),
label isa Vector ? (isempty(label) ? Symbol[] : Symbol.(label)) : [Symbol(label)])
function asrun(runid::Datasets.RunID, timeseries::LarvaBase.Larvae, function asrun(runid::Datasets.RunID, timeseries::LarvaBase.Larvae,
attributes::Datasets.Attributes=Datasets.ConcreteAttributes()) attributes::Datasets.Attributes=Datasets.ConcreteAttributes())
tracks = Track[] tracks = Track[]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment