# Enable an interactive mode for Matplotlib plots
%matplotlib notebook
import pytimber
import time
db = pytimber.LoggingDB(spark_session=spark)
print(pytimber.__version__)
Search for parameters¶
Use the wildcard %
db.search_variables("%BEAM_INTENSITY%")
Explore the parameter tree¶
use the ipython autocomplete (TAB) after db. to see other methods interactively
db.get_variables_for_hierarchies("/LHC/Beam_Quality/Beam_1")
Get Data¶
Specify a variable name and a timestamp or an interval. Data is always returned as a dictionary of timestamp, values arrays.
db.get("HX:FILLN", time.time())
Scaling algorithms¶
getScaled can be used to exploit the time scaling functionality of Timber. Specify
- the scaleSize (an integer)
- the scaleInterval (one of ['SECOND', 'MINUTE', 'HOUR', 'DAY', 'WEEK', 'MONTH', 'YEAR'])
- the scaling algorithm (one of ['MAX','MIN','AVG','COUNT','SUM','REPEAT','INTERPOLATE'])
db.get_scaled('MSC01.ZT8.107:COUNTS','2016-08-03 16:30:00.000','2016-08-03 18:30:00.000',
scale_algorithm=pytimber.ScaleAlgorithm.SUM, scale_size=1, scale_interval=pytimber.ScaleInterval.MINUTE)
Timestamps¶
Timestamps can be give as floating point number, strings, datatime objects.
If only one timestamp is given the last value logged prior to the timestamp is given.
If the second argument is 'next' the first value logged after the timestamp is given.
If two timestamps are given the values logged in between (inclusively) are given.
Timestamp are returned as unix timestamp (seconds and fraction from 1970-01-01 00:00:00 GMT) or optionally as datetime object.
from datetime import datetime
now=time.time()
"The unixtime `%.3f` correspond to `%s` local time."%(now, datetime.fromtimestamp(now))
db.get("HX:FILLN",time.time())
db.get("HX:FILLN",'2016-08-03 16:30:00.000')
db.get("HX:FILLN",'2016-08-03 16:30:00.000',unixtime=False)
db.get("HX:FILLN",'2016-08-01 16:30:00.000','next')
db.get("HX:FILLN",'2016-08-02 16:30:00.000','2016-08-03 16:30:00.000')
Variables¶
Variables can be given as a string, as a pattern, as a list of strings.
db.get("LHC.BCTDC.A6R4.B1:BEAM_INTENSITY",now)
db.get("LHC.BCTDC.A6R4.B%:BEAM_INTENSITY",now)
db.get(["LHC.BCTDC.A6R4.B1:BEAM_INTENSITY","LHC.BCTDC.A6R4.B2:BEAM_INTENSITY"],now)
Values¶
Values can be scalar (floating point values or string) or vectors. If in a query the length of the vectors is the same, as 2D array is returned, else a list of arrays is returned instead.
# prepare for plotting
%matplotlib notebook
import matplotlib.pyplot as pl
ts = "2016-07-01 03:10:15"
ib1 = "LHC.BCTFR.A6R4.B1:BUNCH_INTENSITY"
ib2 = "LHC.BCTFR.A6R4.B2:BUNCH_INTENSITY"
data = db.get([ib1, ib2], ts, 'next')
timestamps, valuesb1 = data[ib1]
timestamps, valuesb2 = data[ib2]
pl.figure()
pl.plot(valuesb1[0])
pl.plot(valuesb2[0])
pl.xlabel("slot number")
pl.ylabel("protons per bunch")
print(valuesb1[0])
t1 = "2016-07-01 03:10:15.000"
t2 = "2016-07-01 03:11:15.000"
ib1 = "LHC.BCTFR.A6R4.B1:BUNCH_INTENSITY"
ib2 = "LHC.BCTFR.A6R4.B2:BUNCH_INTENSITY"
# Get data for ib1 and ib2
data = db.get([ib1, ib2], t1, t2)
# Unpack the data for ib1 and ib2
timestamps_ib1, values_ib1 = data[ib1]
timestamps_ib2, values_ib2 = data[ib2]
# Reshape the values for ib1 and ib2
valuesb1 = values_ib1[0].reshape((1, -1))
valuesb2 = values_ib2[0].reshape((1, -1))
pl.figure()
pl.imshow(valuesb1, aspect='auto', origin='lower')
pl.ylabel('seconds')
pl.xlabel("slot number")
pl.colorbar()
pl.clim(9e10, 12e10)
pl.figure()
pl.imshow(valuesb2, aspect='auto', origin='lower')
pl.ylabel('seconds')
pl.xlabel("slot number")
pl.colorbar()
pl.clim(9e10, 12e10)