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
9c3b102a
Commit
9c3b102a
authored
4 years ago
by
Zineb Aly
Browse files
Options
Downloads
Patches
Plain Diff
count nested Arrays
parent
657223e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
km3io/offline.py
+59
-7
59 additions, 7 deletions
km3io/offline.py
with
59 additions
and
7 deletions
km3io/offline.py
+
59
−
7
View file @
9c3b102a
...
...
@@ -25,25 +25,77 @@ def fitinf(fitparam, tracks):
----------
fitparam : str
the fit parameter name according to fitparameters defined in
km3net-d
ataformat.
KM3NeT-D
ataformat.
tracks : class km3io.offline.OfflineBranch
the tracks class .
the tracks class. both full tracks branch or a slice of the
tracks branch (example tracks[:, 0]) work.
Returns
-------
awkward array
awkward array of the fit parameter
s
.
awkward array of the
values of the
fit parameter
requested
.
"""
fit
=
tracks
.
fitinf
counts
=
ak1
.
Array
([
ak1
.
num
(
i
,
axis
=
1
)
for
i
in
fit
])
index
=
fitparameters
[
fitparam
]
params
=
fit
[
counts
>
index
]
return
ak1
.
Array
([
i
[:,
index
]
for
i
in
params
])
try
:
params
=
fit
[
count_nested
(
fit
,
axis
=
2
)
>
index
]
return
ak1
.
Array
([
i
[:,
index
]
for
i
in
params
])
except
ValueError
:
# This is the case for tracks[:, 0] or any other selection.
params
=
fit
[
count_nested
(
fit
,
axis
=
1
)
>
index
]
return
params
[:,
index
]
def
fitparams
():
"""
name of the fit parameters as defined in the official
KM3NeT-Dataformat.
Returns
-------
dict_keys
fit parameters keys.
"""
return
fitparameters
.
keys
()
def
count_nested
(
Array
,
axis
=
0
):
"""
count elements in a nested awkward Array.
Parameters
----------
Array : Awkward1 Array
Array of data. Example tracks.fitinf or tracks.rec_stages.
axis : int, optional
axis = 0: to count elements in the outmost level of nesting.
axis = 1: to count elements in the first level of nesting.
axis = 2: to count elements in the second level of nesting.
Returns
-------
awkward1 Array or int
counts of elements found in a nested awkward1 Array.
"""
if
axis
==
0
:
return
ak1
.
num
(
Array
,
axis
=
0
)
if
axis
==
1
:
return
ak1
.
num
(
Array
,
axis
=
1
)
if
axis
==
2
:
return
ak1
.
count
(
Array
,
axis
=
2
)
def
best_track
(
tracks
,
strategy
=
"
first
"
,
rec_stages
=
None
):
"""
best track selection based on different strategies
Parameters
----------
tracks : class km3io.offline.OfflineBranch
the tracks branch.
strategy : str
the trategy desired to select the best tracks.
"""
if
strategy
==
"
first
"
:
return
tracks
[:,
0
]
# if strategy == "rec_stages" and rec_stages is not None:
# mask = tracks.rec_stages[]
EVENTS_MAP
=
BranchMapper
(
name
=
"
events
"
,
key
=
"
Evt
"
,
...
...
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