Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LarvaTagger.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Nyx
LarvaTagger.jl
Commits
0f26c94d
Commit
0f26c94d
authored
3 years ago
by
François LAURENT
Browse files
Options
Downloads
Patches
Plain Diff
file loading moved to PlanarLarvae.jl
parent
922a63b7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/LarvaTagger.jl
+1
-2
1 addition, 2 deletions
src/LarvaTagger.jl
src/files.jl
+27
-127
27 additions, 127 deletions
src/files.jl
src/models.jl
+1
-1
1 addition, 1 deletion
src/models.jl
with
29 additions
and
130 deletions
src/LarvaTagger.jl
+
1
−
2
View file @
0f26c94d
module
LarvaTagger
using
PlanarLarvae
,
PlanarLarvae
.
Chore
,
PlanarLarvae
.
Trxmat
,
PlanarLarvae
.
Datasets
,
PlanarLarvae
.
FIMTrack
,
PlanarLarvae
.
Loaders
using
PlanarLarvae
,
PlanarLarvae
.
Datasets
,
PlanarLarvae
.
Loaders
using
ObservationPolicies
using
TidyObservables
...
...
This diff is collapsed.
Click to expand it.
src/files.jl
+
27
−
127
View file @
0f26c94d
...
...
@@ -85,60 +85,6 @@ getwdcontent(controller) = getwdcontent(getworkingdir(controller))
# open/save
function
loadfile
(
path
)
# TODO: refactor
fmt
=
guessfileformat
(
path
)
hastags
=
false
existingtags
,
tagcolors
=
Set
{
Symbol
}(),
nothing
data
,
metadata
,
run
=
nothing
,
nothing
,
nothing
if
fmt
===
:
trx
data
=
read_trxmat
((
:
spine
=>
Spine
,
:
outline
=>
Outline
,
:
tags
=>
BehaviorTags
),
path
)
hastags
=
true
elseif
fmt
===
:
chore
data
=
read_chore_files
((
:
spine
=>
Spine
,
:
outline
=>
Outline
),
path
)
elseif
fmt
===
:
json
data
,
metadata
,
existingtags
,
tagcolors
=
read_json_labels
(
path
)
run
=
first
(
keys
(
data
))
hastags
=
true
elseif
fmt
===
:
fimtrack
@info
"Assuming 30 fps for FIMTrack v2 csv files"
data
=
read_fimtrack
((
:
spine
=>
Spine
,
:
outline
=>
Outline
),
path
;
fps
=
30
)
else
return
()
end
if
data
isa
PlanarLarvae
.
LarvaBase
.
Runs
@assert
length
(
data
)
==
1
data
=
first
(
values
(
data
))
end
# tracks
times
=
PlanarLarvae
.
times
(
data
)
if
data
isa
PlanarLarvae
.
LarvaBase
.
Larvae
tracks
=
[
LarvaModel
(
id
,
ts
,
times
)
for
(
id
,
ts
)
in
pairs
(
data
)]
else
tracks
=
[
LarvaModel
(
track
,
times
)
for
track
in
data
]
end
# tags
if
hastags
&&
isempty
(
existingtags
)
for
track
in
tracks
for
(
_
,
state
)
in
track
.
fullstates
union!
(
existingtags
,
convert
(
Set
,
state
.
tags
))
end
end
end
# dataset
if
isnothing
(
metadata
)
||
isempty
(
metadata
)
metadata
=
extract_metadata_from_filepath
(
path
)
run
=
get!
(
metadata
,
:
date_time
,
"NA"
)
end
output
=
Dataset
([
Run
(
run
;
metadata
...
)])
#
if
isnothing
(
tagcolors
)
return
(
tracks
=
tracks
,
timestamps
=
times
,
tags
=
existingtags
,
output
=
output
)
else
return
(
tracks
=
tracks
,
timestamps
=
times
,
tags
=
existingtags
,
tagcolors
=
tagcolors
,
output
=
output
)
end
end
function
tryopenfile
(
controller
,
path
;
reload
::
Bool
=
false
)
hub
=
gethub
(
controller
)
refresh_view
=
reload
...
...
@@ -200,7 +146,33 @@ function tryopenfile(controller, path; reload::Bool=false)
end
end
checksum
(
filename
)
=
bytes2hex
(
open
(
sha1
,
filename
))
function
loadfile
(
path
)
file
=
Loaders
.
load
(
path
)
data
=
isempty
(
file
.
run
)
?
file
.
timeseries
:
file
.
run
# tracks
times
=
PlanarLarvae
.
times
(
data
)
if
data
isa
PlanarLarvae
.
LarvaBase
.
Larvae
tracks
=
[
LarvaModel
(
id
,
ts
,
times
)
for
(
id
,
ts
)
in
pairs
(
data
)]
else
tracks
=
[
LarvaModel
(
track
,
times
)
for
track
in
values
(
data
)]
end
# dataset
metadata
=
getmetadata
(
file
)
if
isempty
(
metadata
)
metadata
=
extract_metadata_from_filepath
(
path
)
run
=
get!
(
metadata
,
:
date_time
,
"NA"
)
end
output
=
Dataset
([
Run
(
run
;
metadata
...
)])
#
labels
=
getlabels
(
file
)
existingtags
=
labels
[
:
names
]
if
haskey
(
labels
,
:
colors
)
tagcolors
=
labels
[
:
colors
]
return
(
tracks
=
tracks
,
timestamps
=
times
,
tags
=
existingtags
,
tagcolors
=
tagcolors
,
output
=
output
)
else
return
(
tracks
=
tracks
,
timestamps
=
times
,
tags
=
existingtags
,
output
=
output
)
end
end
getoutput
(
controller
)
=
gethub
(
controller
)[
:
output
]
...
...
@@ -314,75 +286,3 @@ function getoutputfile(controller)
end
return
outputfile
end
function
read_json_labels
(
path
)
run
=
decodelabels!
(
PlanarLarvae
.
Datasets
.
from_json_file
(
Run
,
path
))
labelspec
=
run
.
attributes
[
:
labels
]
labelset
=
Symbol
.
(
labelspec
[
:
names
])
tagcolors
=
labelspec
[
:
colors
]
#
existingtags
=
labelset
metadata
=
sort_metadata
(
run
.
attributes
[
:
metadata
])
if
isempty
(
metadata
)
@warn
"No metadata found"
end
#
datadir
=
dirname
(
path
)
datafile
=
get_dependencies
(
run
,
path
)[
1
]
datafmt
=
guessfileformat
(
datafile
)
data′
=
nothing
if
datafmt
===
:
trx
data′
=
read_trxmat
((
:
spine
=>
Spine
,
:
outline
=>
Outline
),
datafile
)
elseif
datafmt
===
:
chore
data′
=
read_chore_files
((
:
spine
=>
Spine
,
:
outline
=>
Outline
),
datafile
)
else
datafmt
===
:
fimtrack
@info
"Assuming 30 fps for FIMTrack v2 csv files"
data′
=
read_fimtrack
((
:
spine
=>
Spine
,
:
outline
=>
Outline
),
datafile
;
fps
=
30
)
data′
=
Dataset
([
Run
(
run
.
id
,
data′
)])
end
@assert
length
(
data′
)
==
1
runid
=
first
(
keys
(
data′
))
if
runid
!=
run
.
id
@error
"Run IDs do not match:
\"
$
(run.id)
\"
vs
\"
$
runid
\"
"
end
recordtype
=
PlanarLarvae
.
derivedtype
((
:
spine
=>
Spine
,
:
outline
=>
Outline
,
:
tags
=>
BehaviorTags
))
data
=
PlanarLarvae
.
Runs
{
recordtype
}()
data
[
runid
]
=
PlanarLarvae
.
Larvae
{
recordtype
}()
for
(
id
,
track′
)
in
pairs
(
data′
[
runid
])
newtimeseries
=
PlanarLarvae
.
TimeSeries
{
recordtype
}()
if
id
in
keys
(
run
)
track
=
run
[
id
]
tags
=
track
[
:
labels
]
for
i
in
1
:
length
(
track
.
timestamps
)
t
=
track
.
timestamps
[
i
]
tags′
=
BehaviorTags
(
labelset
,
begin
l
=
tags
[
i
]
(
l
isa
Vector
)
?
Symbol
.
(
l
)
:
[
Symbol
(
l
)]
end
)
t′
,
state
=
if
track′
isa
Track
t′
=
track′
.
timestamps
[
i
]
state
=
NamedTuple
(
track′
[
t′
])
t′
,
state
else
track′
[
i
]
end
@assert
abs
(
t
-
t′
)
<
.
01
push!
(
newtimeseries
,
(
t′
,
(
spine
=
state
.
spine
,
outline
=
state
.
outline
,
tags
=
tags′
)))
end
elseif
track′
isa
Track
for
t′
in
track′
.
timestamps
push!
(
newtimeseries
,
(
t′
,
(
spine
=
track′
[
:
spine
,
t′
],
outline
=
track′
[
:
outline
,
t′
],
tags
=
BehaviorTags
(
labelset
,
Symbol
[]))))
end
else
for
(
t′
,
state
)
in
track′
push!
(
newtimeseries
,
(
t′
,
(
spine
=
state
.
spine
,
outline
=
state
.
outline
,
tags
=
BehaviorTags
(
labelset
,
Symbol
[]))))
end
end
if
isempty
(
newtimeseries
)
@warn
"Empty time series"
track
=
id
labelled
=
(
id
in
keys
(
run
))
else
data
[
runid
][
id
]
=
newtimeseries
end
end
return
data
,
metadata
,
existingtags
,
tagcolors
end
This diff is collapsed.
Click to expand it.
src/models.jl
+
1
−
1
View file @
0f26c94d
...
...
@@ -229,7 +229,7 @@ function LarvaModel(track::Track, times::Vector{PlanarLarvae.Time})
LarvaModel
(
track
.
id
,
alignedsteps
,
path
,
PlanarLarvae
.
Datasets
.
astimeseries
(
track
),
astimeseries
(
track
),
usertags
)
end
...
...
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