Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.5%) to scientific vocabulary
Last synced: 7 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: KM3NeT
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 14.3 MB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Created over 6 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog Contributing License Codemeta

README.rst

The km3io Python package
========================

.. image:: https://git.km3net.de/km3py/km3io/badges/master/pipeline.svg
    :target: https://git.km3net.de/km3py/km3io/pipelines

.. image:: https://git.km3net.de/km3py/km3io/badges/master/coverage.svg
    :target: https://km3py.pages.km3net.de/km3io/coverage

.. image:: https://git.km3net.de/examples/km3badges/-/raw/master/docs-latest-brightgreen.svg
    :target: https://km3py.pages.km3net.de/km3io

.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.7382620.svg
   :target: https://doi.org/10.5281/zenodo.7382620

This software provides a set of Python classes to read KM3NeT ROOT files
without having ROOT, Jpp or aanet installed. It only depends on Python 3.5+ and the amazing `uproot `__ package and gives you access to the data via `numpy `__ and `awkward `__ arrays.

It's very easy to use and according to the `uproot `__ benchmarks, it is able to outperform the original ROOT I/O performance. 

Installation
============

Install km3io using pip::

    pip install km3io 

or conda::

    conda install km3io

To get the latest (stable) development release::

    pip install git+https://git.km3net.de/km3py/km3io.git

Docker::

    docker run -it docker.km3net.de/km3io

Singularity::

    wget https://sftp.km3net.de/singularity/km3io_v0.27.2.sif  # pick the version you like
    singularity shell km3io_v0.27.2.sif

**Reminder:** km3io is **not** dependent on aanet, ROOT or Jpp!

Questions
=========

If you have a question about km3io, please proceed as follows:

- Read the documentation below.
- Explore the `examples `__ in the documentation.
- Haven't you found an answer to your question in the documentation, post a git issue with your question showing us an example of what you have tried first, and what you would like to do.
- Have you noticed a bug, please post it in a git issue, we appreciate your contribution.


Introduction
------------

Most of km3net data is stored in root files. These root files are created using
the `KM3NeT Dataformat library
`__ A ROOT file created with
`Jpp `__ is an "online" file and all other
software usually produces "offline" files.

km3io is a Python package that provides access to offline files with its
``OfflineReader`` class and a special one to read gSeaGen files. All of these
ROOT files can be read without installing any other software like Jpp, aanet or
ROOT. km3io v1.1 and earlier also support the access to online files (events,
summaryslices and timeslices). This feature has been dropped due to a lack of
mainteinance power and inf favour of the `KM3io.jl `__` Julia Package, which
provides high-performances access to all ROOT files and should also be
prioritised over ``km3io`` when performance matters (which does, most of the
time).

Data in km3io is returned as ``awkward.Array`` which is an advance Numpy-like container type to store
contiguous data for high performance computations.
Such an ``awkward.Array`` supports any level of nested arrays and records which can have different lengths, in contrast to Numpy where everything has to be rectangular.

The example is shown below shows the array which contains the ``dir_z`` values
of each track of the first 4 events. The type ``4 * var * float64`` means that
it has 4 subarrays with variable lengths of type ``float64``:

.. code-block:: python3

    >>> import km3io
    >>> from km3net_testdata import data_path
    >>> f = km3io.OfflineReader(data_path("offline/numucc.root"))
    >>> f[:4].tracks.dir_z
    

The same concept applies to all other branches, including ``hits``, ``mc_hits``,
``mc_tracks``, ``t_sec`` etc.

Architecture overview
---------------------

``km3io`` utilises ``uproot`` behind the scenes and creates a lazy and thin
wrapper which offers convenient slicing and iterations by delaying the access to
the actual ROOT data branches to the very last moment. When using the iteration
functionality, the data is loaded in chunks and the iteration is done over e.g.
events in each chunk or a bunch of frames in case of the summaryslice reader.

The base class for the event-based readout is the ``km3io.rootio.EventReader``
class. When subclassing this class, the branches, aliases and nested branches
need to be defined in the static variables which are then used to mask unwanted
attributes. Especially in case of the Offline ROOT format, where the "one class
fits all" design was chosen, it is distracting that e.g. a `Hit` has many
attributes which make no sense depending on the context (MC hit, raw hit etc.).
By specifing the branches explicitely, the user API will only expose the
meaningful fields.

The online ROOT format support is partly still based on ``uproot3``.

Many of the utility functions are using Numba to achieve the best possible
performance. ``km3io`` does not offer alternative implementations, so Numba is a
strict dependency and an integral part of the implementation.


Offline files reader
--------------------

In general an offline file has two attributes to access data: the header and the events. Let's start with the header.

Reading the file header
"""""""""""""""""""""""

To read an offline file start with opening it with the ``OfflineReader``:

.. code-block:: python3

  >>> import km3io
  >>> from km3net_testdata import data_path
  >>> f = km3io.OfflineReader(data_path("offline/numucc.root"))

Accessing is as easy as typing:

.. code-block:: python3

  >>> f.header
  

Printing it will give an overview of the structure:

.. code-block:: python3

  >>> print(f.header)
  MC Header:
  DAQ(livetime=394)
  PDF(i1=4, i2=58)
  can(zmin=0, zmax=1027, r=888.4)
  can_user: can_user(field_0=0.0, field_1=1027.0, field_2=888.4)
  coord_origin(x=0, y=0, z=0)
  cut_in(Emin=0, Emax=0, cosTmin=0, cosTmax=0)
  cut_nu(Emin=100, Emax=100000000.0, cosTmin=-1, cosTmax=1)
  cut_primary(Emin=0, Emax=0, cosTmin=0, cosTmax=0)
  cut_seamuon(Emin=0, Emax=0, cosTmin=0, cosTmax=0)
  decay: decay(field_0='doesnt', field_1='happen')
  detector: NOT
  drawing: Volume
  genhencut(gDir=2000, Emin=0)
  genvol(zmin=0, zmax=1027, r=888.4, volume=2649000000.0, numberOfEvents=100000)
  kcut: 2
  livetime(numberOfSeconds=0, errorOfSeconds=0)
  model(interaction=1, muon=2, scattering=0, numberOfEnergyBins=1, field_4=12)
  ngen: 100000.0
  norma(primaryFlux=0, numberOfPrimaries=0)
  nuflux: nuflux(field_0=0, field_1=3, field_2=0, field_3=0.5, field_4=0.0, field_5=1.0, field_6=3.0)
  physics(program='GENHEN', version='7.2-220514', date=181116, time=1138)
  seed(program='GENHEN', level=3, iseed=305765867, field_3=0, field_4=0)
  simul(program='JSirene', version=11012, date='11/17/18', time=7)
  sourcemode: diffuse
  spectrum(alpha=-1.4)
  start_run(run_id=1)
  target: isoscalar
  usedetfile: false
  xlat_user: 0.63297
  xparam: OFF
  zed_user: zed_user(field_0=0.0, field_1=3450.0)

To read the values in the header one can call them directly, as the structures
are simple ``namedtuple``-like objects:

.. code-block:: python3

  >>> f.header.DAQ.livetime
  394
  >>> f.header.cut_nu.Emin
  100
  >>> f.header.genvol.numberOfEvents
  100000


Reading offline events
""""""""""""""""""""""

Events are at the top level of an offline file, so that each branch of an event
is directly accessible at the ``OfflineReader`` instance. The ``.keys()`` method
can be used to list the available attributes. Notice that some of them are aliases
for backwards compatibility (like ``mc_tracks`` and ``mc_trks``). Another
backwards compatibility feature is the ``f.events`` attribute which is simply
mapping everything to ``f``, so that ``f.events.mc_tracks`` is the same as
``f.mc_tracks``.

.. code-block:: python3

  >>> f
  OfflineReader (10 events)
  >>> f.keys()
  {'comment', 'det_id', 'flags', 'frame_index', 'hits', 'id', 'index',
  'mc_hits', 'mc_id', 'mc_run_id', 'mc_t', 'mc_tracks', 'mc_trks',
  'n_hits', 'n_mc_hits', 'n_mc_tracks', 'n_mc_trks', 'n_tracks',
  'n_trks', 'overlays', 'run_id', 't_ns', 't_sec', 'tracks',
  'trigger_counter', 'trigger_mask', 'trks', 'usr', 'usr_names',
  'w', 'w2list', 'w3list'}
  >>> f.tracks
  
  >>> f.events.tracks
  

The ``[10]`` denotes that there are ``10`` events available, each containing a sub-array of ``tracks``.

Using  completion gives an overview of available data. Alternatively the attribute `fields`
can be used on event-branches and to see what is available for reading.

.. code-block:: python3

  >>> f.tracks.fields
  ['id',
  'pos_x',
  'pos_y',
  'pos_z',
  'dir_x',
  'dir_y',
  'dir_z',
  't',
  'E',
  'len',
  'lik',
  'rec_type',
  'rec_stages',
  'fitinf']


Reading the reconstructed values like energy and direction of an event can be done with:

.. code-block:: python3

  >>> f.events.tracks.E
  

The ``Array`` in this case is an `awkward `__ array with the data type
``10 * var * float64`` which means that there are ``10`` sub-arrays with ``var``iable lengths of type ``float64``.
Awkward arrays allow high-performance access to arrays which are not rectangular (in contrast to ``numpy``).
Read the documention of AwkwardArray to learn how to work with these structures efficiently. One example
to retrieve the energy of the very first reconstructed track for the first three events is:

.. code-block:: python3

  >>> f.events.tracks.E[:3, 0]
  

Online files reader
-------------------

The support to read online ROOT files has been dropped in ``km3io`` v1.2.

Owner

  • Name: KM3NeT
  • Login: KM3NeT
  • Kind: organization

Inofficial collection of open source KM3NeT software

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "license": "https://spdx.org/licenses/MIT",
  "codeRepository": "git+https://git.km3net.de/km3py/km3io.git",
  "contIntegration": "https://git.km3net.de/km3py/km3io/-/pipelines",
  "dateCreated": "2019-11-15",
  "datePublished": "2019-11-15",
  "dateModified": "2023-06-15",
  "downloadUrl": "https://git.km3net.de/km3py/km3io",
  "issueTracker": "https://git.km3net.de/km3py/km3io/-/issues",
  "name": "km3io",
  "softwareVersion": "1.0.0",
  "maintainer": "Tamas Gal <tamas.gal@fau.de>",
  "readme": "https://git.km3net.de/km3py/km3io/-/blob/master/README.rst",
  "description": "Pure Python I/O library for KM3NeT related files.",
  "applicationCategory": "Astroparticle physics",
  "developmentStatus": "active",
  "referencePublication": "https://doi.org/10.5281/zenodo.808829",
  "releaseNotes": "https://km3py.pages.km3net.de/km3io/changelog.html",
  "copyrightHolder": "KM3NeT Collaboration",
  "keywords": [
    "i/o",
    "astroparticle physics",
    "km3net"
  ],
  "programmingLanguage": [
    "Python 3"
  ],
  "operatingSystem": [
    "Linux",
    "macOS",
    "Windows"
  ],
  "relatedLink": [
    "https://km3py.pages.km3net.de/km3io/"
  ],
  "author": [
    {
      "@type": "Person",
      "@id": "https://orcid.org/0000-0001-7821-8673",
      "givenName": "Tamas",
      "familyName": "Gal",
      "email": "tamas.gal@fau.de",
      "affiliation": {
        "@type": "Organization",
        "name": "Friedrich-Alexander-University Erlangen-Nuremberg, Erlangen Centre for Astroparticle Physics"
      }
    }
  ],
  "contributor": [
    {
      "@type": "Person",
      "@id": "https://orcid.org/0000-0003-3722-086X",
      "givenName": "Johannes",
      "familyName": "Schumann",
      "affiliation": {
        "@type": "Organization",
        "name": "Friedrich-Alexander-University Erlangen-Nuremberg, Erlangen Centre for Astroparticle Physics"
      }
    },
    {
      "@type": "Person",
      "@id": "https://orcid.org/0000-0002-5593-2580",
      "givenName": "Zineb",
      "familyName": "Aly"
    }
  ]
}

GitHub Events

Total
  • Push event: 9
  • Fork event: 1
  • Create event: 5
Last Year
  • Push event: 9
  • Fork event: 1
  • Create event: 5

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 684
  • Total Committers: 11
  • Avg Commits per committer: 62.182
  • Development Distribution Score (DDS): 0.243
Past Year
  • Commits: 22
  • Committers: 2
  • Avg Commits per committer: 11.0
  • Development Distribution Score (DDS): 0.045
Top Committers
Name Email Commits
Tamas Gal t****l@k****e 518
zineb aly a****z@g****m 97
Zineb Aly z****y@k****e 52
Johannes Schumann j****n@f****e 9
Valentin Pestel v****l@k****e 2
lhennig l****g@k****e 1
Manu Le Guirriec e****c@k****e 1
Stefan Reck s****k@k****e 1
Massimiliano Lincetto m****o@k****e 1
Lodewijk Nauta l****a@k****e 1
BoukeJisse Jung b****g@k****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

Dockerfile docker
  • debian buster-slim build
pyproject.toml pypi
setup.py pypi