Public Member Functions | Public Attributes | Private Attributes | List of all members
PandAna.core.core.Cut Class Reference

Public Member Functions

def __init__ (self, cut, invert=False)
 
def reset_cutindices (self)
 
def __call__ (self, tables)
 
def __and__ (self, other)
 
def __invert__ (self)
 
def __or__ (self, other)
 

Public Attributes

 filteridx
 

Private Attributes

 _cut
 
 _invert
 
 _filter
 
 _cutid
 

Detailed Description

Definition at line 256 of file core.py.

Constructor & Destructor Documentation

def PandAna.core.core.Cut.__init__ (   self,
  cut,
  invert = False 
)

Definition at line 257 of file core.py.

257  def __init__(self, cut, invert=False):
258  if type(cut) is not list: cut = [cut]
259  if type(invert) is not list: invert = [invert]
260  assert len(cut) == len(invert), "invalid cut definition!"
261 
262  self._cut = list(cut)
263  self._invert = list(invert)
264 
265  # index that runs over the cutlist
266  self.filteridx = 0
267 
268  # use these to keep track of cuts already computed
269  self._filter = [0]*len(self._cut)
270  self._cutid = [0]*len(self._cut)
271 
def __init__(self, cut, invert=False)
Definition: core.py:257

Member Function Documentation

def PandAna.core.core.Cut.__and__ (   self,
  other 
)

Definition at line 323 of file core.py.

References PandAna.core.core.spectrum._cut, PandAna.core.core.Cut._cut, and PandAna.core.core.Cut._invert.

323  def __and__(self, other):
324  return Cut(self._cut + other._cut, self._invert + other._invert)
325 
def __and__(self, other)
Definition: core.py:323
def PandAna.core.core.Cut.__call__ (   self,
  tables 
)

Definition at line 277 of file core.py.

References PandAna.core.core.spectrum._cut, PandAna.core.core.Cut._cut, PandAna.core.core.Cut._cutid, PandAna.core.core.Cut._filter, PandAna.core.core.Cut._invert, plot_validation_datamc.c, PandAna.core.core.Cut.filteridx, PandAna.Demos.demo1.range, and PandAna.core.core.Cut.reset_cutindices().

277  def __call__(self, tables):
278  if not tables.gone:
279  cutlist = [(~c(tables) if b else c(tables)) for c, b in zip(self._cut, self._invert)]
280  if not tables.interactive:
281  # tables is empty anyway. takes negligible time
282  #return dummy cut series
283  return cutlist[0]
284  else:
285  cut_df = pd.concat(cutlist, axis=1).all(axis=1)
286  cutidx = cut_df.index[np.where(cut_df)]
287  tables._tables['indices'] = cutidx
288  return cut_df
289 
290  # cutid holds the filtered index list after applying the cut on the entire dataset
291  cutidx = self._cutid[self.filteridx]
292  # actual cut that was already computed
293  applycut = self._filter[self.filteridx]
294 
295  # cut is being computed for the first time
296  if cutidx is 0:
297  cut0 = self._cut[self.filteridx](tables)
298  if self._invert[self.filteridx]:
299  cut0 = ~cut0
300 
301  # find filtered index list
302  cutidx = cut0.index[np.where(cut0)]
303 
304  applycut = cut0
305  self._cutid[self.filteridx] = cutidx
306  self._filter[self.filteridx] = applycut
307 
308  self.filteridx += 1
309 
310  # check if filtered index list is empty and if so, stop computing other cuts
311  canfiltermore = all([len(cutidx.codes[k]) for k in range(len(cutidx.codes))])
312 
313  # if its not empty, run next cut on the filtered list rather than the entire dataset
314  if len(self._cut) > self.filteridx and canfiltermore:
315  return self(tables[cutidx])
316  else:
317  # use filtered index list for evaluation of the var that comes later
318  tables._tables['indices'] = cutidx
319  self.filteridx = 0
320  self.reset_cutindices()
321  return applycut
322 
def __call__(self, tables)
Definition: core.py:277
def reset_cutindices(self)
Definition: core.py:272
def PandAna.core.core.Cut.__invert__ (   self)

Definition at line 326 of file core.py.

References PandAna.core.core.spectrum._cut, PandAna.core.core.Cut._cut, PandAna.core.core.Cut._invert, and PandAna.Demos.demo1.range.

326  def __invert__(self):
327  cut = Cut(self._cut[0], not self._invert[0])
328  for i in range(1, len(self._cut)):
329  cut = cut | Cut(self._cut[i], not self._invert[i])
330  return cut
331 
def __invert__(self)
Definition: core.py:326
def PandAna.core.core.Cut.__or__ (   self,
  other 
)

Definition at line 332 of file core.py.

References fhicl.other.

332  def __or__(self, other):
333  def orcut(tables):
334  idx = tables._tables['indices']
335  df1 = self(tables)
336  tables._tables['indices'] = idx
337  df2 = other(tables)
338  # or operators are not commutative???
339  compare = pd.concat([df1,df2], axis=1, join='outer').fillna(False)
340  return compare.any(axis=1)
341  return Cut(orcut)
342 
343 
def __or__(self, other)
Definition: core.py:332
def PandAna.core.core.Cut.reset_cutindices (   self)

Definition at line 272 of file core.py.

References PandAna.core.core.spectrum._cut, PandAna.core.core.Cut._cut, PandAna.core.core.Cut._cutid, and PandAna.core.core.Cut._filter.

Referenced by PandAna.core.core.Cut.__call__().

272  def reset_cutindices(self):
273  # need to reset after use by loader
274  self._filter = [0]*len(self._cut)
275  self._cutid = [0]*len(self._cut)
276 
def reset_cutindices(self)
Definition: core.py:272

Member Data Documentation

PandAna.core.core.Cut._cut
private
PandAna.core.core.Cut._cutid
private
PandAna.core.core.Cut._filter
private
PandAna.core.core.Cut._invert
private
PandAna.core.core.Cut.filteridx

Definition at line 266 of file core.py.

Referenced by PandAna.core.core.Cut.__call__().


The documentation for this class was generated from the following file: