ATLAS Offline Software
Public Member Functions | Static Private Attributes | List of all members
python.trfUtils.analytic Class Reference

Analytics service class. More...

Collaboration diagram for python.trfUtils.analytic:

Public Member Functions

def __init__ (self, **kwargs)
 
def fit (self, x, y, model='linear')
 Fitting function For a linear model: y(x) = slope * x + intersect. More...
 
def slope (self)
 
def getFittedData (self, filename, x_name='Time', y_name='pss', precision=2, tails=False, minPoints=5)
 
def extractFromTable (self, table, x_name, y_name)
 
def formatBytes (self, size)
 

Static Private Attributes

 _fit
 

Detailed Description

Analytics service class.

Definition at line 1252 of file trfUtils.py.

Constructor & Destructor Documentation

◆ __init__()

def python.trfUtils.analytic.__init__ (   self,
**  kwargs 
)

Definition at line 1256 of file trfUtils.py.

1256  def __init__(self, **kwargs):
1257  self._fit = None
1258 

Member Function Documentation

◆ extractFromTable()

def python.trfUtils.analytic.extractFromTable (   self,
  table,
  x_name,
  y_name 
)

Definition at line 1335 of file trfUtils.py.

1335  def extractFromTable(self, table, x_name, y_name):
1336  headerUpperVersion = {'pss':'PSS', 'swap':'Swap', 'rss':'RSS', 'vmem':'VMEM'}
1337  x = table.get(x_name, [])
1338  if '+' not in y_name:
1339  y = table.get(y_name, [])
1340  if len(y)==0:
1341  y = table.get(headerUpperVersion[y_name], [])
1342  else:
1343  try:
1344  y1_name = y_name.split('+')[0]
1345  y2_name = y_name.split('+')[1]
1346  y1_value = table.get(y1_name, [])
1347  y2_value = table.get(y2_name, [])
1348  if len(y1_value)==0 or len(y2_value)==0:
1349  y1_value = table.get(headerUpperVersion[y1_name], [])
1350  y2_value = table.get(headerUpperVersion[y2_name], [])
1351  except Exception as e:
1352  msg.warning('exception caught: {0}'.format(e))
1353  x = []
1354  y = []
1355  else:
1356  # create new list with added values (1,2,3) + (4,5,6) = (5,7,9)
1357  y = [x0 + y0 for x0, y0 in zip(y1_value, y2_value)]
1358 
1359  return x, y
1360 

◆ fit()

def python.trfUtils.analytic.fit (   self,
  x,
  y,
  model = 'linear' 
)

Fitting function For a linear model: y(x) = slope * x + intersect.

Parameters
xlist of input data (list of floats or ints).
ylist of input data (list of floats or ints).
modelmodel name (string).

Definition at line 1264 of file trfUtils.py.

1264  def fit(self, x, y, model='linear'):
1265  try:
1266  self._fit = Fit(x=x, y=y, model=model)
1267  except Exception as e:
1268  msg.warning('fit failed! {0}'.format(e))
1269 
1270  return self._fit
1271 

◆ formatBytes()

def python.trfUtils.analytic.formatBytes (   self,
  size 
)

Definition at line 1363 of file trfUtils.py.

1363  def formatBytes(self, size):
1364  # decimal system
1365  power = 1000
1366  n = 1
1367  power_labels = {1: 'K', 2: 'M', 3: 'G', 4: 'T'}
1368  while size > power:
1369  size /= power
1370  n += 1
1371  return round(size, 2), power_labels[n]+'B/s'
1372 
1373 

◆ getFittedData()

def python.trfUtils.analytic.getFittedData (   self,
  filename,
  x_name = 'Time',
  y_name = 'pss',
  precision = 2,
  tails = False,
  minPoints = 5 
)

Definition at line 1292 of file trfUtils.py.

1292  def getFittedData(self, filename, x_name='Time', y_name='pss', precision=2, tails=False, minPoints=5):
1293  _memFileToTable = memFileToTable()
1294  fitResult = {}
1295  table = _memFileToTable.getTable(filename, header=None, separator="\t")
1296  if table:
1297  # extract data to be fitted
1298  x, y = self.extractFromTable(table, x_name, y_name)
1299  # remove tails if desired
1300  # this is useful e.g. for memory monitor data where the first and last values
1301  # represent allocation and de-allocation, ie not interesting
1302  # here tail is defined to be first and last 20% of data
1303  if not tails:
1304  tail = int(len(x)/5)
1305  msg.info('removing tails from the memory monitor data; 20% from each side')
1306  x = x[tail:]
1307  x = x[:-tail]
1308  y = y[tail:]
1309  y = y[:-tail]
1310 
1311  if len(x)==len(y) and len(x) > minPoints:
1312  msg.info('fitting {0} vs {1}'.format(y_name, x_name))
1313  try:
1314  fit = self.fit(x, y)
1315  _slope = self.slope()
1316  except Exception as e:
1317  msg.warning('failed to fit data, x={0}, y={1}: {2}'.format(x, y, e))
1318  else:
1319  if _slope:
1320  slope = round(fit.slope(), precision)
1321  chi2 = round(fit.chi2(), precision)
1322  fitResult = {"slope": slope, "chi2": chi2}
1323  if slope:
1324  HRslope, unit = self.formatBytes(slope)
1325  msg.info('slope of the fitted line: {0} {1} (using {2} data points, chi2={3})'.format(HRslope, unit, len(x), chi2))
1326  else:
1327  msg.warning('wrong length of table data, x={0}, y={1} (must be same and length>={2})'.format(x, y, minPoints))
1328 
1329  return fitResult
1330 

◆ slope()

def python.trfUtils.analytic.slope (   self)

Definition at line 1273 of file trfUtils.py.

1273  def slope(self):
1274  slope = None
1275 
1276  if self._fit:
1277  slope = self._fit.slope()
1278  else:
1279  msg.warning('Fit has not been defined')
1280 
1281  return slope
1282 

Member Data Documentation

◆ _fit

python.trfUtils.analytic._fit
staticprivate

Definition at line 1254 of file trfUtils.py.


The documentation for this class was generated from the following file:
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
MuonValidation_CreateResolutionProfiles.fit
def fit(h, emin, emax)
Definition: MuonValidation_CreateResolutionProfiles.py:69
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18