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
3a9f500a
Commit
3a9f500a
authored
4 years ago
by
Tamas Gal
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
abac4dd0
9f4af33c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#11599
failed
4 years ago
Stage: test
Stage: coverage
Stage: doc
Stage: release
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
km3io/__init__.py
+1
-19
1 addition, 19 deletions
km3io/__init__.py
km3io/offline.py
+17
-2
17 additions, 2 deletions
km3io/offline.py
km3io/patches.py
+17
-0
17 additions, 0 deletions
km3io/patches.py
tests/test_offline.py
+17
-1
17 additions, 1 deletion
tests/test_offline.py
with
52 additions
and
22 deletions
km3io/__init__.py
+
1
−
19
View file @
3a9f500a
import
numpy
as
np
import
awkward
as
ak
import
awkward1
as
ak1
from
pkg_resources
import
get_distribution
,
DistributionNotFound
version
=
get_distribution
(
__name__
).
version
...
...
@@ -9,18 +5,4 @@ version = get_distribution(__name__).version
from
.offline
import
OfflineReader
from
.online
import
OnlineReader
from
.gseagen
import
GSGReader
# to avoid infinite recursion
old_getitem
=
ak
.
ChunkedArray
.
__getitem__
def
new_getitem
(
self
,
item
):
"""
Monkey patch the getitem in awkward.ChunkedArray to apply
awkward1.Array masks on awkward.ChunkedArray
"""
if
isinstance
(
item
,
(
ak1
.
Array
,
ak
.
ChunkedArray
)):
return
ak1
.
Array
(
self
)[
item
]
else
:
return
old_getitem
(
self
,
item
)
ak
.
ChunkedArray
.
__getitem__
=
new_getitem
from
.
import
patches
This diff is collapsed.
Click to expand it.
km3io/offline.py
+
17
−
2
View file @
3a9f500a
...
...
@@ -4,7 +4,7 @@ import warnings
import
numba
as
nb
import
awkward1
as
ak1
from
.definitions
import
mc_header
,
fitparameters
from
.definitions
import
mc_header
,
fitparameters
,
reconstruction
from
.tools
import
cached_property
,
to_num
,
unfold_indices
from
.rootio
import
Branch
,
BranchMapper
...
...
@@ -21,6 +21,18 @@ def _nested_mapper(key):
return
'
_
'
.
join
(
key
.
split
(
'
.
'
)[
1
:])
def
rec_types
():
"""
name of the reconstruction type as defined in the official
KM3NeT-Dataformat.
Returns
-------
dict_keys
reconstruction types.
"""
return
reconstruction
.
keys
()
def
fitinf
(
fitparam
,
tracks
):
"""
Access fit parameters in tracks.fitinf.
...
...
@@ -140,7 +152,7 @@ def mask(rec_stages, stages):
return
builder
.
snapshot
()
==
1
def
best_track
(
tracks
,
strategy
=
"
first
"
,
rec_stages
=
None
):
def
best_track
(
tracks
,
strategy
=
"
first
"
,
rec_type
=
None
,
rec_stages
=
None
):
"""
best track selection based on different strategies
Parameters
...
...
@@ -154,6 +166,9 @@ def best_track(tracks, strategy="first", rec_stages=None):
return
tracks
[:,
0
]
if
strategy
==
"
rec_stages
"
and
rec_stages
is
not
None
:
return
tracks
[
mask
(
tracks
.
rec_stages
,
rec_stages
)]
if
strategy
==
"
default
"
and
rec_type
is
not
None
:
return
tracks
[
tracks
.
rec_type
==
reconstruction
[
rec_type
]][
tracks
.
lik
==
ak1
.
max
(
tracks
.
lik
,
axis
=
1
)][:,
0
]
EVENTS_MAP
=
BranchMapper
(
name
=
"
events
"
,
...
...
This diff is collapsed.
Click to expand it.
km3io/patches.py
0 → 100644
+
17
−
0
View file @
3a9f500a
import
awkward
as
ak
import
awkward1
as
ak1
# to avoid infinite recursion
old_getitem
=
ak
.
ChunkedArray
.
__getitem__
def
new_getitem
(
self
,
item
):
"""
Monkey patch the getitem in awkward.ChunkedArray to apply
awkward1.Array masks on awkward.ChunkedArray
"""
if
isinstance
(
item
,
(
ak1
.
Array
,
ak
.
ChunkedArray
)):
return
ak1
.
Array
(
self
)[
item
]
else
:
return
old_getitem
(
self
,
item
)
ak
.
ChunkedArray
.
__getitem__
=
new_getitem
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/test_offline.py
+
17
−
1
View file @
3a9f500a
...
...
@@ -4,7 +4,7 @@ import awkward1 as ak1
from
pathlib
import
Path
from
km3io
import
OfflineReader
from
km3io.offline
import
_nested_mapper
,
Header
,
fitinf
,
fitparams
,
count_nested
,
_find
,
mask
,
best_track
from
km3io.offline
import
_nested_mapper
,
Header
,
fitinf
,
fitparams
,
count_nested
,
_find
,
mask
,
best_track
,
rec_types
SAMPLES_DIR
=
Path
(
__file__
).
parent
/
'
samples
'
OFFLINE_FILE
=
OfflineReader
(
SAMPLES_DIR
/
'
aanet_v2.0.0.root
'
)
...
...
@@ -41,6 +41,13 @@ class TestFitinf(unittest.TestCase):
assert
"
JGANDALF_BETA0_RAD
"
in
keys
class
TestRecoTypes
(
unittest
.
TestCase
):
def
test_reco_types
(
self
):
keys
=
set
(
rec_types
())
assert
"
JPP_RECONSTRUCTION_TYPE
"
in
keys
class
TestBestTrack
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
tracks
=
OFFLINE_FILE
.
events
.
tracks
...
...
@@ -50,10 +57,19 @@ class TestBestTrack(unittest.TestCase):
rec_stages_tracks
=
best_track
(
self
.
tracks
,
strategy
=
"
rec_stages
"
,
rec_stages
=
[
1
,
3
,
5
,
4
])
default_best
=
best_track
(
self
.
tracks
,
strategy
=
"
default
"
,
rec_type
=
"
JPP_RECONSTRUCTION_TYPE
"
)
assert
first_tracks
.
dir_z
[
0
]
==
self
.
tracks
.
dir_z
[
0
][
0
]
assert
first_tracks
.
dir_x
[
1
]
==
self
.
tracks
.
dir_x
[
1
][
0
]
assert
rec_stages_tracks
.
rec_stages
[
0
]
==
[
1
,
3
,
5
,
4
]
assert
rec_stages_tracks
.
rec_stages
[
1
]
==
[
1
,
3
,
5
,
4
]
assert
default_best
.
lik
[
0
]
==
ak1
.
max
(
self
.
tracks
.
lik
[
0
])
assert
default_best
.
lik
[
1
]
==
ak1
.
max
(
self
.
tracks
.
lik
[
1
])
assert
default_best
.
rec_type
[
0
]
==
4000
class
TestCountNested
(
unittest
.
TestCase
):
...
...
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