Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
km3py
km3io
Commits
20819a7d
Verified
Commit
20819a7d
authored
3 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add getitem to SummarysliceReader
parent
594a767b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!68
Rewrite the online module
Pipeline
#25164
passed with warnings
3 years ago
Stage: test
Stage: coverage
Stage: doc
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
km3io/online.py
+24
-1
24 additions, 1 deletion
km3io/online.py
tests/test_online.py
+40
-0
40 additions, 0 deletions
tests/test_online.py
with
64 additions
and
1 deletion
km3io/online.py
+
24
−
1
View file @
20819a7d
...
...
@@ -96,6 +96,22 @@ class SummarysliceReader:
*
[
getattr
(
chunk
,
bc
.
branch_address
)
for
bc
in
self
.
_subbranches
]
)
def
__getitem__
(
self
,
idx
):
if
idx
>=
len
(
self
)
or
idx
<
-
len
(
self
):
raise
IndexError
(
"
Chunk index out of range
"
)
s
=
self
.
_step_size
if
idx
<
0
:
idx
=
len
(
self
)
+
idx
chunk
=
self
.
_branch
.
arrays
(
dict
(
self
.
_subbranches
),
entry_start
=
idx
*
s
,
entry_stop
=
(
idx
+
1
)
*
s
)
return
self
.
ChunksConstructor
(
*
[
getattr
(
chunk
,
bc
.
branch_address
)
for
bc
in
self
.
_subbranches
]
)
def
__iter__
(
self
):
self
.
_chunks
=
self
.
_chunks_generator
()
return
self
...
...
@@ -107,7 +123,14 @@ class SummarysliceReader:
return
int
(
np
.
ceil
(
self
.
_branch
.
num_entries
/
self
.
_step_size
))
def
__repr__
(
self
):
return
f
"
<
{
self
.
__class__
.
__name__
}
{
self
.
_branch
.
num_entries
}
items, step_size=
{
self
.
_step_size
}
(
{
len
(
self
)
}
chunks)>
"
step_size
=
self
.
_step_size
n_items
=
self
.
_branch
.
num_entries
cls_name
=
self
.
__class__
.
__name__
n_chunks
=
len
(
self
)
return
(
f
"
<
{
cls_name
}
{
n_items
}
items, step_size=
{
step_size
}
"
f
"
(
{
n_chunks
}
chunk
{
''
if
n_chunks
==
1
else
'
s
'
}
)>
"
)
@nb.vectorize
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_online.py
+
40
−
0
View file @
20819a7d
...
...
@@ -749,6 +749,46 @@ class TestSummarysliceReader(unittest.TestCase):
sr
=
SummarysliceReader
(
data_path
(
"
online/km3net_online.root
"
),
step_size
=
3
)
assert
1
==
len
(
sr
)
def
test_getitem_raises_when_out_of_range
(
self
):
sr
=
SummarysliceReader
(
data_path
(
"
online/km3net_online.root
"
),
step_size
=
1
)
with
self
.
assertRaises
(
IndexError
):
sr
[
123
]
with
self
.
assertRaises
(
IndexError
):
sr
[
-
123
]
with
self
.
assertRaises
(
IndexError
):
sr
[
3
]
sr
[
-
3
]
# this should still work, gives the first element in this case
with
self
.
assertRaises
(
IndexError
):
sr
[
-
4
]
def
test_getitem
(
self
):
sr
=
SummarysliceReader
(
data_path
(
"
online/km3net_online.root
"
),
step_size
=
1
)
for
idx
in
range
(
len
(
sr
)):
assert
len
(
sr
[
idx
].
headers
)
==
1
assert
len
(
sr
[
idx
].
slices
)
==
1
first_frame_index
=
sr
[
0
].
headers
.
frame_index
# 126
last_frame_index
=
sr
[
2
].
headers
.
frame_index
# 128
assert
126
==
first_frame_index
assert
128
==
last_frame_index
sr
=
SummarysliceReader
(
data_path
(
"
online/km3net_online.root
"
),
step_size
=
2
)
assert
len
(
sr
[
0
].
headers
)
==
2
assert
len
(
sr
[
0
].
slices
)
==
2
assert
len
(
sr
[
1
].
headers
)
==
1
assert
len
(
sr
[
1
].
slices
)
==
1
with
self
.
assertRaises
(
IndexError
):
assert
len
(
sr
[
2
].
headers
)
==
0
assert
len
(
sr
[
2
].
slices
)
==
0
assert
first_frame_index
==
sr
[
0
].
headers
[
0
].
frame_index
assert
last_frame_index
==
sr
[
1
].
headers
[
0
].
frame_index
assert
last_frame_index
==
sr
[
-
1
].
headers
[
0
].
frame_index
assert
first_frame_index
==
sr
[
-
2
].
headers
[
0
].
frame_index
def
test_iterate_with_step_size_one
(
self
):
sr
=
SummarysliceReader
(
data_path
(
"
online/km3net_online.root
"
),
step_size
=
1
)
i
=
0
...
...
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