Skip to content

xbuffat/pytimber

This branch is 244 commits behind rdemaria/pytimber:master.

Repository files navigation

pytimber

Python wrapping of the CERN Accelerator Logging Service (CALS) API.

Installation

Install a Python distribution (e.g. Anaconda) and a recent Java version (1.8), then install pytimber using pip:

pip install git+https://github.com/rdemaria/pytimber.git --process-dependency-links

This will also install cmmnbuild-dep-manager to provide automatic resolution of Java dependencies for CERN packages. It is required to use pytimber with other CERN libraries, such as PyJapc.

Installation notes

  • For Windows, this pre-compiled version of JPype seems to work best.

Usage

Import:

import pytimber
ldb = pytimber.LoggingDB()

Search for variables:

print(ldb.search('HX:BETA%'))

Get data:

t1 = '2015-05-13 00:00:00.000'
t2 = '2015-05-15 00:00:00.000'
d = ldb.get('HX:FILLN', t1, t2)
print(d)
t1 = '2015-05-13 12:00:00.000'
t2 = '2015-05-13 12:00:01.000'
d = ldb.get('LHC.BQBBQ.CONTINUOUS_HS.B1:ACQ_DATA_H', t1, t2)
print(d)

Explore variable hierarchies:

ldb.tree
print(dir(ldb.tree))
print(ldb.tree.LHC.Collimators.BPM.bpmColl.get_vars())

Get data for a particular LHC fill:

fill = ldb.getLHCFillData(4760)
t1 = fill['startTime']
t2 = fill['endTime']
d = ldb.get('LHC.BQBBQ.CONTINUOUS_HS.B1:ACQ_DATA_H', t1, t2)
print(d)

Find all fill number in the last 48 hours that contained a ramp:

t2 = datetime.datetime.now()
t1 = t2 - datetime.timedelta(hours=48)
fills = ldb.getLHCFillsByTime(t1, t2, beam_modes='RAMP')
print([f['fillNumber'] for f in fills])

By default all times are returned as Unix timestamps. If you pass unixtime=False to get(), getAligned(), getLHCFillData() or getLHCFillsByTime() then datetime objects are returned instead.

Usage with PageStore

pytimber can be combined with PageStore for local data storage.

Installation (assuming pytimber is already installed):

pip install git+https://github.com/rdemaria/pagestore.git

Usage example:

import pytimber
import pagestore

ldb = pytimber.LoggingDB()
mydb = pagestore.PageStore('mydata.db', './datadb')

t1 = time.mktime(time.strptime('Fri Apr 25 00:00:00 2016'))
mydb.store(ldb.get('%RQTD%I_MEAS', t1, t1+60))
mydb.store(ldb.get('%RQTD%I_MEAS', t1+60, t1+120))

mydata = mydb.get('RPMBB.UA47.RQTD.A45B2:I_MEAS', t1+90, t1+110)
data = ldb.get('RPMBB.UA47.RQTD.A45B2:I_MEAS', t1+90, t1+110)
for k in data:
  print(mydata[k][0] - data[k][0])
  print(mydata[k][1] - data[k][1])

About

Python Wrapping of CALS API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.7%
  • Shell 0.3%