Package pylal :: Module ligolw_dataUtils :: Class CompareDataRows
[hide private]
[frames] | no frames]

Class CompareDataRows

source code


A class that can perform various types of comparison tests between
arbitrary DataRow classes. The class has the following attributes:
*classA: A DataRow class. Note: this is a class, not an instance
  of a class.
*classB: A DataRow class. This can be the same type of class as
  classA, or different. Like classA, this is a class, not an instance
  of that class.
*matchCriteriaA: What column, or function of columns, to get from
  classA when doing a comparison between an instance of classA and
  an instance of classB.
*matchCriteriaB: What column, or function of columns, to get from
  classB when doing a comparison between an instance of classA and
  an instance of classB.
*_diffFunc: What function to perform to differentiate classA from classB.
  This function should be one of the functions below; it takes data to
  populate an instance of classA and an instance of classB, and returns a
  numerical value >= 0 representing the difference between these instances of
  classA and classB. This value can then be compared to the window size to
  determine if A and B are the same or not.
*window: How large of a window to use to consider an instance of
 classA equal to an instance of classB.

Example:
 >>> classA = createDataRowClass( 'sngl_inspiral' )
 >>> classB = createDataRowClass( 'sngl_inspiral' )
 >>> compF = CompareDataRows( classA, classB )
 >>> compF.set_diffFunc( compF.diffRowARowB )
 >>> compF.set_window( 0.1 )
 >>> compF.set_matchCriteriaA('mass1/mass2')
 >>> compF.set_matchCriteriaB = ('mass1/mass2')
 >>> dataA = [('mass1', '10.0'), ('mass2', '5.0')]
 >>> dataB = [('mass1', '10.1'), ('mass2', '5.0')]
 >>> compF.compare( dataA, dataB )
 True
 >>> compF.set_window(0)
 >>> compF.compare( dataA, dataB )
 False

Instance Methods [hide private]
 
__init__(self, RowClassA=None, RowClassB=None) source code
 
set_classA(self, DataRowClass) source code
 
set_classB(self, DataRowClass) source code
 
set_matchCriteriaA(self, match_criteria)
Sets the match criteria for classA.
source code
 
matchCriteriaA(self) source code
 
set_matchCriteriaB(self, match_criteria)
Sets the match criteria for classB.
source code
 
matchCriteriaB(self) source code
 
get_needed_columnsAB(self, AorB)
Retrieves which columns in the desired class is needed for the match criteria.
source code
 
set_neededColumnsA(self) source code
 
neededColumnsA(self) source code
 
set_neededColumnsB(self) source code
 
neededColumnsB(self) source code
 
set_diffFunc(self, function) source code
 
set_window(self, window) source code
 
_diff(self, a, b)
Returns the absolute value of the difference between a and b.
source code
 
compare(self, a, b)
Runs self.diffFunc on a and b and checks that that is <= self.window.
source code
 
dbWrapper(self, *args)
A database wrapper for the compare functions.
source code
 
create_dbCompF(self, connection, diffFunc, compFuncName, window)
Creates a function in the given connection to a database that allows the given diffFunc to be performed on classA and classB on the fly.
source code
 
diffRowARowB(self, dataA, dataB)
Runs self.diff on self.classA and self.classB using self.matchCriteriA and self.matchCriteriaB.
source code
 
diffSimSngl(self, simData, snglData)
Same as diffRowARowB, except that classA is assumed to be some sort of simulation table (e.g., sim_inspiral) and classB is assumed to be some sort of single-IFO table (e.g., sngl_inspiral).
source code
 
eThincaSim(self, simData, snglData)
Computes the eThinca distance between an instance of self.classA and an instance of self.classB.
source code
 
eThincaSngl(self, snglDataA, snglDataB)
Computes the eThinca distance between an instance of self.classA and an instance of self.classB.
source code
Method Details [hide private]

set_matchCriteriaA(self, match_criteria)

source code 

Sets the match criteria for classA. Also sets the columns needed for the given match criteria.

matchCriteriaA(self)

source code 
Decorators:
  • @property

set_matchCriteriaB(self, match_criteria)

source code 

Sets the match criteria for classB. Also sets the columns needed for the given match criteria.

matchCriteriaB(self)

source code 
Decorators:
  • @property

get_needed_columnsAB(self, AorB)

source code 

Retrieves which columns in the desired class is needed for the match
criteria.

Parameters
----------
AorB: str
    Either 'A' or 'B'; which class to get the columns for.

Returns
-------
needed_cols: list
    The list of needed columns; see get_needed_columns for
    details.

neededColumnsA(self)

source code 
Decorators:
  • @property

neededColumnsB(self)

source code 
Decorators:
  • @property

_diff(self, a, b)

source code 

Returns the absolute value of the difference between a and b.

Parameters
----------
a: float or integer
b: float or integer

Returns
-------
difference: float or integer
    The abs difference between a and b.

compare(self, a, b)

source code 

Runs self.diffFunc on a and b and checks that that is <= self.window.

Parameters
----------
a: instance of classA row
    The data passed to the first argument of self.diffFunc.
b: instance of classB row
    The data passed to the second argument of self.diffFunc.

Returns
-------
comparison: bool
    True if self.diffFunc(a, b) is <= self.window; False otherwise.

dbWrapper(self, *args)

source code 

A database wrapper for the compare functions.

Parameters
----------
args: list
    A list of values. The first len(self.neededColumnsA) is assumed to
    be the data for classA, in the order that neededColumnsA is in.
    The rest of the values are assumed to be the data for classB, in
    the order that neededColumnsB is in.

Returns
-------
comparison: bool
    The result of self.compare, where the first argument passed is
    the data from classA and the second is data from classB.

create_dbCompF(self, connection, diffFunc, compFuncName, window)

source code 

Creates a function in the given connection to a database that allows
the given diffFunc to be performed on classA and classB on the fly.
The matchCriteria and the neededColumns for each class must be already
set (this should happen simultaneously by using set_matchCriteria(A|B).

Parameters
----------
connection: sqlite3.connection
    A connection to SQLite database.
diffFunc: function
    The function to use to do comparisons; must be one of the
    functions defined in this class.
compFuncName: str
    What to call the call function in the database; must be unique.
window: float
    The size of the window to use when determining whether or not
    classA and classB are the same.

diffRowARowB(self, dataA, dataB)

source code 


Runs self.diff on self.classA and self.classB using self.matchCriteriA
and self.matchCriteriaB. A or B can be any DataRow class; the only
requirement is that their match criteria (set by
self.matchCriteria(A|B)) be a function of their slots. Special match
criteria are 'startTime' and 'endTime'. In this case,
(start|end)_time+1e-9*(start|end)_time_ns will calculated.

Parameters
----------
dataA: list
    A list of tuples with data to populate this instance of classA.
    The first value of each tuple is the column name, the second the
    value, e.g., ('ifo', 'H1').
dataB: list
    A list of data tuples to populate this instance of classB.

Returns
-------
diff: float
    The return of self._diff(a,b), where a(b) is the matchCritieraA(B)
    function run on dataA(B).

diffSimSngl(self, simData, snglData)

source code 

Same as diffRowARowB, except that classA is assumed to be some sort of simulation table (e.g., sim_inspiral) and classB is assumed to be some sort of single-IFO table (e.g., sngl_inspiral). This assumption only matters if 'startTime' or 'endTime' are the match criteria for classA. In that case, the observatory that recorded the event in classB is retrieved from classB.ifo. This is then used to pick out the appropriate end|start time to use from classA. For example, if H1 is the ifo in the snglData, then h_(end|start)_time+1e-9*h_(end|start)_time_ns will be retrieved from the simData.

eThincaSim(self, simData, snglData)

source code 

Computes the eThinca distance between an instance of self.classA and an instance of self.classB. This assumes that classA inherited from the SimInspiral class and classB inherited from the SnglInspiral class.

eThincaSngl(self, snglDataA, snglDataB)

source code 

Computes the eThinca distance between an instance of self.classA and an instance of self.classB. This assumes that both classA and classB inherited from the SnglInspiral class.