Package recsql :: Module sqlfunctions
[hide private]
[frames] | no frames]

Module sqlfunctions

source code


:mod:`recsql.sqlfunctions` --- Functions that enhance a SQLite db
=================================================================

This module contains new SQL functions to be added to a SQLite database that
can be used in the same way as the builtin functions.

Example:

  Add the functions to an existing connection in the following way (assuming
  that the db connection is available in ``self.connection``)::

     from sqlfunctions import *
     self.connection.create_function("sqrt", 1, _sqrt)
     self.connection.create_function("fformat",2,_fformat)
     self.connection.create_aggregate("std",1,_Stdev)
     self.connection.create_aggregate("median",1,_Median)
     self.connection.create_aggregate("array",1,_NumpyArray)
     self.connection.create_aggregate("histogram",4,_NumpyHistogram)
     self.connection.create_aggregate("distribution",4,_NormedNumpyHistogram)
     self.connection.create_aggregate("meanhistogram",5,_MeanHistogram)
     self.connection.create_aggregate("stdhistogram",5,_StdHistogram)
     self.connection.create_aggregate("minhistogram",5,_MinHistogram)
     self.connection.create_aggregate("maxhistogram",5,_MaxHistogram)
     self.connection.create_aggregate("medianhistogram",5,_MedianHistogram)
     self.connection.create_aggregate("zscorehistogram",5,_ZscoreHistogram)

Module content
--------------
.. See the autogenerated content in the online docs or the source code.

Classes [hide private]
  _Stdev
Implement standard deviation of the sample as SQL aggregate function.
  _Median
  _NumpyArray
  _NumpyHistogram
  _NormedNumpyHistogram
  _FunctionHistogram
Baseclass for histogrammed functions.
  _MeanHistogram
Mean of the weights in each bin.
  _StdHistogram
Standard deviation of the weights in each bin.
  _MinHistogram
Min value of the weights in each bin.
  _MaxHistogram
Max value of the weights in each bin.
  _MedianHistogram
Median value of the weights in each bin.
  _ZscoreHistogram
Z-score of the weights in each bin abs(Y - <Y>)/std(Y).
Functions [hide private]
 
histogram1d(*args, **kwargs) source code
 
_sqrt(x) source code
 
_fformat(format, x) source code
 
regularized_function(x, y, func, bins=None, range=None)
Compute func() over data aggregated in bins.
source code
Variables [hide private]
  _numpyversion = map(int, numpy.version.version.split('.'))
Function Details [hide private]

regularized_function(x, y, func, bins=None, range=None)

source code 
Compute func() over data aggregated in bins.

(x,y) --> (x', func(Y'))  with Y' = {y: y(x) where x in x' bin}

First the data is collected in bins x' along x and then func is applied to
all data points Y' that have been collected in the bin.

:Arguments:
   x  
      abscissa values (for binning)
   y
      ordinate values (func is applied)
   func
      a numpy ufunc that takes one argument, func(Y')
   bins
      number or array
   range
      limits (used with number of bins)

:Returns:
   F,edges        
      function and edges (midpoints = 0.5*(edges[:-1]+edges[1:]))