Skip to content

DeepLearnPhysics/dlp_opendata_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python API

This package exposes a data API for larcv data

To use the package, just exectute the following when you start a python session

import sys
sys.path.append("<path>/dlp_opendata_api")

The main module is osf

Image API

The image API is in the osf.image_api submodule. A 3D image API is built around a image_reader_3d class.

from osf.image_api import image_reader_3d

Initialization The image reader is initialized by providing a file name (or more than one)

fname = 'dlprod_ppn_v10/dlprod_192px_00.root'
img_reader = image_reader_3d(fname)

Usage

See how many events are in the file:

img_reader.entry_count()

Get energy from event 0:

voxels, energy = img_reader.get_energy(0)

Get classes from event 1:

voxels, classes = img_reader.get_classes(1)

Get energy and classes from event 0:

voxels, energy, classes = img_reader.get_image(0)

Particle API

The particle API is in the osf.particle_api submodule.

from osf.particle_api import *

Initialization The particle reader is initialized by providing a file name (or more than one)

fname = 'dlprod_ppn_v10/particle/dlprod_particle_192px_00.root'
preader = particle_reader(fname)

Usage

See how many events there are in the file:

preader.entry_count()

Get event 0 in the file:

event = preader.get_event(0)

The event is a dictionary of particle data. If you want to get an individual particle from the event, use

p = get_particle(event, 5) # gets particle 5

Cluster API

The cluster API is in the osf.cluster_api submodule.

from osf.cluster_api import *

Initialization The cluster reader is initialized by providing a file name (or more than one)

fname = 'dlprod_ppn_v10/cluster/dlprod_cluster_192px_00.root'
creader = cluster_reader(fname)

Usage

See how many events there are in the file:

creader.entry_count()

Get cluster labels from event:

eventn = 0
voxels, labels= img_reader.get_classes(eventn)

Low-level API

For some tasks, the high-level APIs above may abstract away too many detatils. There is also a low-level API that you can use if you know what you're looking for.

See what's in a file*

fname = 'dlprod_ppn_v10/dlprod_192px_00.root'
list_data(fname)
[out]: ['cluster3d_mcst', 'sparse3d_data', 'sparse3d_fivetypes', 'particle_mcst']

Data Reader The data_reader class handles the input.

Initialization:

reader = data_reader()

Add a file to read from:

reader.add_file(fname)

Add data to read (use list_data to see options):

reader.add_data('sparse3d_data')

See how many entries are available to read:

reader.entry_count()

Set reader pointer to entry i

i = 0
reader.read(i)

Get the actual data (once pointer is set)

preader.data('sparse3d_data')

There are also several provided parsers, such as

parse_sparse3d(preader.data('sparse3d_data'))

The two high-level APIs use data_reader as a base class, so you can also do the above manipulations to image_reader_3d and particle_reader instances. However, their purpose is to wrap everything so it is a bit easier to use.

About

APIs for accessing open data set at OSF

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages