Skip to content
Snippets Groups Projects
Commit 59dee842 authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.pyxbldc
# C extensions
*.so
# Version info for PyPI
km3noroot/version.txt
# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.eggs
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
.coverage.*
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Rope
.ropeproject
# Sphinx documentation
doc/_build/
doc/auto_examples/
doc/modules/
doc/api
# VI swap files
*.swp
*.swo
# PyCharm files
.idea
# jupyter files
.ipynb_checkpoints/
#
junit*.xml
reports
# misc
*~
*.dqd
*.dat
.pytest_cache/
.DS_Store
# venv, pyenv tmp
.python-version
venv
image: docker.km3net.de/base/python:3
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
key: "$CI_COMMIT_REF_SLUG"
stages:
- test
- coverage
- doc
.virtualenv_template: &virtualenv_definition |
python -V
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements-dev.txt
make install
.junit_template: &junit_definition
artifacts:
reports:
junit: "reports/junit*.xml"
test-py3.5:
image: docker.km3net.de/base/python:3.5
stage: test
script:
- *virtualenv_definition
- make test
<<: *junit_definition
test-py3.6:
image: docker.km3net.de/base/python:3.6
stage: test
script:
- *virtualenv_definition
- make test
<<: *junit_definition
test-py3.7:
image: docker.km3net.de/base/python:3.7
stage: test
script:
- *virtualenv_definition
- make test
<<: *junit_definition
code-style:
image: docker.km3net.de/base/python:3.7
stage: test
script:
- *virtualenv_definition
- yapf -r -d -e "venv" .
allow_failure: true
coverage:
image: docker.km3net.de/base/python:3.6
stage: coverage
script:
- *virtualenv_definition
- "make test-cov|grep TOTAL| awk '{printf \"COVERAGE: %.2f%%\", (1-$3/$2)*100 }'"
coverage: '/COVERAGE:\s*([0-9]*\.[0-9]*%)/'
# - make test-cov
# coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
artifacts:
paths:
- reports/coverage
pages:
image: docker.km3net.de/base/python:3.6
stage: doc
script:
- *virtualenv_definition
- cd doc && make clean && make html
- mv _build/html ../public/
- cd .. && mv reports/coverage public/coverage
artifacts:
paths:
- public
cache: {}
only:
- tags
- master
LICENSE 0 → 100644
The MIT License (MIT)
Copyright (c) 2014 Tamas Gal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Makefile 0 → 100644
PKGNAME=km3io
default: build
all: install
install:
pip install .
install-dev:
pip install -r requirements-dev.txt
pip install -e .
clean:
python setup.py clean --all
test:
py.test --junitxml=./reports/junit.xml -o junit_suite_name=$(PKGNAME) $(PKGNAME)
test-cov:
py.test --cov ./ --cov-report term-missing --cov-report xml:reports/coverage.xml --cov-report html:reports/coverage $(PKGNAME)
test-loop:
py.test $(PKGNAME)
ptw --ext=.py,.pyx --ignore=doc $(PKGNAME)
flake8:
py.test --flake8
pep8: flake8
docstyle:
py.test --docstyle
lint:
py.test --pylint
dependencies:
pip install -Ur requirements.txt
.PHONY: yapf
yapf:
yapf -i -r $(PKGNAME)
yapf -i setup.py
.PHONY: all clean install install-dev test test-nocov flake8 pep8 dependencies docstyle
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'km3io'
copyright = '2019, Zineb Aly, Tamas Gal, Johannes Schumann'
author = 'Zineb Aly, Tamas Gal, Johannes Schumann'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
.. km3io documentation master file, created by
sphinx-quickstart on Fri Nov 1 14:27:13 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to km3io's documentation!
=====================================
.. toctree::
:maxdepth: 2
:caption: Contents:
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
import uproot
class DataReader:
def __init__(self, file_path):
self.file_path = file_path
self.data = uproot.open(self.file_path)['E']
self.lazy_data = self.data.lazyarrays()
def event_reader(self, key):
"""event_reader function reads data stored in a branch of interest in an event tree.
Parameters
----------
key : str
name of the branch of interest in event data.
Returns
-------
lazyarray
Lazyarray of all data stored in a branch of interest (in an event tree). A lazyarray is an array-like
object that reads data on demand. Here, only the first and last chunks of data are
read in memory, and not all data in the array. The output of event_reader can be used
with all `Numpy's universal functions <https://docs.scipy.org/doc/numpy/reference/ufuncs.html>`.
Raises
------
NameError
Some branches in an Aanet file structure are "fake branches" and do not contain data. Therefore,
the keys corresponding to these fake branches are not read.
"""
evt_tree = self.data['Evt']
evt_keys = self._event_keys(evt_tree)
if key in evt_keys:
evt_key_lazy = self.lazy_data[key]
return evt_key_lazy
else:
raise NameError("The event key must be one of the following: 'id', 'det_id', 'mc_id', 'run_id', 'mc_run_id', 'frame_index', 'trigger_mask', 'trigger_counter', 'overlays', 'hits', 'trks', 'w', 'w2list', 'w3list', 'mc_t', 'mc_hits', 'mc_trks', 'comment', 'index', 'flags', 't.fSec', 't.fNanoSec' ")
def _event_keys(self, evt_tree):
"""_event_keys function returns a list of all the keys of interest
for data analysis, and removes the keys of empty "fake branches"
found in Aanet event files.
Parameters
----------
evt_tree : aanet event (Evt) tree.
Returns
-------
list of str
list of all the event keys.
"""
fake_branches = ['Evt', 'AAObject', 'TObject','t']
t_baskets = ['t.fSec', 't.fNanoSec']
#
all_keys_evt = [key.decode('utf-8') for key in evt_tree.keys() if key.decode('utf-8') not in fake_branches] + t_baskets
return all_keys_evt
def hits_reader(self, hits_key):
"""hits_reader function reads data stored in a branch of interest in hits tree from an Aanet
event file.
Parameters
----------
hits_key : str
name of the branch of interest in hits tree.
Returns
-------
lazyarray
Lazyarray of all data stored in a branch of interest (in hits tree). A lazyarray is an array-like
object that reads data on demand. Here, only the first and last chunks of data are
read in memory, and not all data in the array. The output of event_reader can be used
with all `Numpy's universal functions <https://docs.scipy.org/doc/numpy/reference/ufuncs.html>`.
Raises
------
NameError
the hits.key stored in an Aanet file must be used to access the branch of interest
from hits tree data.
"""
hits_tree = self.data['Evt']['hits']
hits_keys = [key.decode('utf8') for key in hits_tree.keys()]
if hits_key in hits_keys:
hits_key_lazy = self.lazy_data[hits_key]
return hits_key_lazy
else:
raise NameError("The hits key must be one of the following: 'hits.fUniqueID', 'hits.fBits', 'hits.usr', 'hits.usr_names', 'hits.id', 'hits.dom_id', 'hits.channel_id', 'hits.tdc', 'hits.tot', 'hits.trig', 'hits.pmt_id', 'hits.t', 'hits.a', 'hits.pos.x', 'hits.pos.y', 'hits.pos.z', 'hits.dir.x', 'hits.dir.y', 'hits.dir.z', 'hits.pure_t', 'hits.pure_a', 'hits.type', 'hits.origin', 'hits.pattern_flags'")
def tracks_reader(self, tracks_key ):
"""tracks_reader function reads data stored in a branch of interest in tracks tree
from an Aanet event file.
Parameters
----------
tracks_key : str
name of the branch of interest in tracks tree.
Returns
-------
lazyarray
Lazyarray of all data stored in a branch of interest (in tracks tree). A lazyarray is an array-like
object that reads data on demand. Here, only the first and last chunks of data are
read in memory, and not all data in the array. The output of event_reader can be used
with all `Numpy's universal functions <https://docs.scipy.org/doc/numpy/reference/ufuncs.html>`.
Raises
------
NameError
the trks.key stored in an Aanet file must be used to access the branch of interest
from tracks tree data.
"""
tracks_tree = self.data['Evt']['trks']
tracks_keys = [key.decode('utf8') for key in tracks_tree.keys()]
if tracks_key in tracks_keys:
tracks_key_lazy = self.lazy_data[tracks_key]
return tracks_key_lazy
else:
raise NameError("The tracks key must be one the following: 'trks.fUniqueID', 'trks.fBits', 'trks.usr', 'trks.usr_names', 'trks.id', 'trks.pos.x', 'trks.pos.y', 'trks.pos.z', 'trks.dir.x', 'trks.dir.y', 'trks.dir.z', 'trks.t', 'trks.E', 'trks.len', 'trks.lik', 'trks.type', 'trks.rec_type', 'trks.rec_stages', 'trks.fitinf', 'trks.hit_ids', 'trks.error_matrix', 'trks.comment'")
import unittest
class TestImport(unittest.TestCase):
def test_import(self):
import km3io
This diff is collapsed.
pytest
pytest-cov
pytest-flake8
pytest-pylint
pytest-watch
sphinx
yapf
setup.py 0 → 100644
#!/usr/bin/env python
# Filename: setup.py
"""
The km3io setup script.
"""
from setuptools import setup
import sys
with open('requirements.txt') as fobj:
requirements = [l.strip() for l in fobj.readlines()]
try:
with open("README.rst") as fh:
long_description = fh.read()
except UnicodeDecodeError:
long_description = "km3io, a library to read KM3NeT files without ROOT"
setup(
name='km3io',
url='http://git.km3net.de/km3py/km3io',
description='KM3NeT I/O without ROOT',
long_description=long_description,
author='Zineb Aly, Tamas Gal, Johannes Schumann',
author_email='zaly@km3net.de, jschumann@km3net.de, tgal@km3net.de',
packages=['km3io'],
include_package_data=True,
platforms='any',
setup_requires=['setuptools_scm'],
use_scm_version={
'write_to': 'km3io/version.txt',
'tag_regex': r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
},
install_requires=requirements,
python_requires='>=3.5',
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Programming Language :: Python',
],
)
__author__ = 'Zineb Aly, Tamas Gal and Johannes Schumann'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment