cofunc
index
/home/djung/lib/cofunc/__init__.py

Implement a class that represents a continuous function.
 
To do:
--> like "mean", implement functions like "min", "max", "sum" that accept
    coFunc objects
--> ease plotting data of coFunc objects?
--> integrate the function
--> provide standard coFunc objects like "Sin", "Cos", "Tan" etc.
--> nD coFunc objects?
--> add math to coFunc2d

 
Package Contents
       

 
Classes
       
__builtin__.object
coFunc2d
_abcoll.Sequence(_abcoll.Sized, _abcoll.Iterable, _abcoll.Container)
coFunc
Sin

 
class Sin(coFunc)
    Create coFunc object representing a sinusoidal function.
 
 
Method resolution order:
Sin
coFunc
_abcoll.Sequence
_abcoll.Sized
_abcoll.Iterable
_abcoll.Container
__builtin__.object

Methods defined here:
__init__(self, range=(-10, 10), step=0.1, amp=1, freq=1, phase=0)

Data and other attributes defined here:
__abstractmethods__ = frozenset([])
__created__ = '2012-07-12'

Methods inherited from coFunc:
__abs__(self)
__add__(self, other)
__call__(self, x, kind='linear', bounds_error=True, fill_value=nan)
Get the value of the quantity at any given position x. Interpolate
if needed. If bounds_error is True, error if x is out of range.
Otherwise, return fill_value for x values out of range.
__getitem__(self, index)
__len__(self)
__mod__(self, other)
__mul__(self, other)
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rdiv__(self, other)
__repr__(self)
Return string representation.
__rmul__(self, other)
__rsub__(self, other)
__str__(self)
Return short string representation.
__sub__(self, other)
a2cf(self, attrname)
Convert a sequence-like attribute to a coFunc object where the
y-data is the attribute and the x-data is the original x-data of this
coFunc object.
add(self, *points)
Add data points (2-tuples) to the function.
box(self)
Return bounding box, i.e. [x_min, x_max, y_min, y_max].
centroid(self)
Return the geometric center of all x-y data points.
combine(self, *others, **kwargs)
Combine the x-y pairs of this continuous function object with those
of the given others. Returns a new continuous function instance. If cut
is True, only the intersection of the x-axes is used, the rest of the
input functions is cut away. Raise an exception if the x-axes do not
intersect.
copy(self)
Return copy of this continuous function object.
cut(self, range=None, lower=None, upper=None)
Cut away all data points whose x-value is outside of the given
"range", or those that are smaller than "lower" or greater than
"upper".
diff(self, n=1)
Calculate the n-th order differential of the function.
globalmax(self)
Return global maximum of the function.
globalmin(self)
Return global minimum of the function.
localmax(self, endpoints=False)
Return all local maxima of the function. If endpoints is False,
exclude the first and the last data point from the search.
localmin(self, endpoints=False)
Return all local minima of the function. If endpoints is False,
exclude the first and the last data point from the search.
noise(self)
Measure for the "noisiness" (roughly, inverse of "continuity") of
the data. Key question: How well can the x-y value pairs be fitted by
one continuous curve?
sort(self)
Sort data points by x-values.
xy(self)
Return x and y data as tuple (similar to what zip() does, but more
efficient, as the raw data arrays are directly returned).

Data and other attributes inherited from coFunc:
__modified__ = '2012-10-16'

Methods inherited from _abcoll.Sequence:
__contains__(self, value)
__iter__(self)
__reversed__(self)
count(self, value)
S.count(value) -> integer -- return number of occurrences of value
index(self, value)
S.index(value) -> integer -- return first index of value.
Raises ValueError if the value is not present.

Class methods inherited from _abcoll.Sized:
__subclasshook__(cls, C) from abc.ABCMeta

Data descriptors inherited from _abcoll.Sized:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from _abcoll.Sized:
__metaclass__ = <class 'abc.ABCMeta'>
Metaclass for defining Abstract Base Classes (ABCs).
 
Use this metaclass to create an ABC.  An ABC can be subclassed
directly, and then acts as a mix-in class.  You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).

 
class coFunc(_abcoll.Sequence)
    Represent a continuous function using discrete datapoints (x-y value
pairs).  Because of the assumption that the x-y value pairs represent a
computer approximation of some continuous function, various mathematical
operations can be implemented that seem natural from a mathematical
viewpoint, but not as trivial in a computer environment where data can have
different x-axis discretisations etc.
 
Possible extensions:
--> R->R, C->C, N->N, Z->Z? Different data types?
--> different dimensions? Mappings like R->R^3? R^2->R^3?
--> xlabel, ylabel
--> ease plotting the function
--> integrals
--> cut/trim the function (get a certain part of it) (also in y-direction)
--> yerr, xerr? make a new class for that?
    also method to return coFunc(x, yerr), coFunc(x, xerr)
 
 
Method resolution order:
coFunc
_abcoll.Sequence
_abcoll.Sized
_abcoll.Iterable
_abcoll.Container
__builtin__.object

Methods defined here:
__abs__(self)
__add__(self, other)
__call__(self, x, kind='linear', bounds_error=True, fill_value=nan)
Get the value of the quantity at any given position x. Interpolate
if needed. If bounds_error is True, error if x is out of range.
Otherwise, return fill_value for x values out of range.
__getitem__(self, index)
__init__(self, x=[], y=[], dtype=None, attrs={})
Initialize the continuous function object.
__len__(self)
__mod__(self, other)
__mul__(self, other)
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rdiv__(self, other)
__repr__(self)
Return string representation.
__rmul__(self, other)
__rsub__(self, other)
__str__(self)
Return short string representation.
__sub__(self, other)
a2cf(self, attrname)
Convert a sequence-like attribute to a coFunc object where the
y-data is the attribute and the x-data is the original x-data of this
coFunc object.
add(self, *points)
Add data points (2-tuples) to the function.
box(self)
Return bounding box, i.e. [x_min, x_max, y_min, y_max].
centroid(self)
Return the geometric center of all x-y data points.
combine(self, *others, **kwargs)
Combine the x-y pairs of this continuous function object with those
of the given others. Returns a new continuous function instance. If cut
is True, only the intersection of the x-axes is used, the rest of the
input functions is cut away. Raise an exception if the x-axes do not
intersect.
copy(self)
Return copy of this continuous function object.
cut(self, range=None, lower=None, upper=None)
Cut away all data points whose x-value is outside of the given
"range", or those that are smaller than "lower" or greater than
"upper".
diff(self, n=1)
Calculate the n-th order differential of the function.
globalmax(self)
Return global maximum of the function.
globalmin(self)
Return global minimum of the function.
localmax(self, endpoints=False)
Return all local maxima of the function. If endpoints is False,
exclude the first and the last data point from the search.
localmin(self, endpoints=False)
Return all local minima of the function. If endpoints is False,
exclude the first and the last data point from the search.
noise(self)
Measure for the "noisiness" (roughly, inverse of "continuity") of
the data. Key question: How well can the x-y value pairs be fitted by
one continuous curve?
sort(self)
Sort data points by x-values.
xy(self)
Return x and y data as tuple (similar to what zip() does, but more
efficient, as the raw data arrays are directly returned).

Data and other attributes defined here:
__abstractmethods__ = frozenset([])
__created__ = '2012-06-27'
__modified__ = '2012-10-16'

Methods inherited from _abcoll.Sequence:
__contains__(self, value)
__iter__(self)
__reversed__(self)
count(self, value)
S.count(value) -> integer -- return number of occurrences of value
index(self, value)
S.index(value) -> integer -- return first index of value.
Raises ValueError if the value is not present.

Class methods inherited from _abcoll.Sized:
__subclasshook__(cls, C) from abc.ABCMeta

Data descriptors inherited from _abcoll.Sized:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from _abcoll.Sized:
__metaclass__ = <class 'abc.ABCMeta'>
Metaclass for defining Abstract Base Classes (ABCs).
 
Use this metaclass to create an ABC.  An ABC can be subclassed
directly, and then acts as a mix-in class.  You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).

 
class coFunc2d(__builtin__.object)
    Represent a continuous 2D function using discrete datapoints (x-y-z
value triples).  Because of the assumption that the x-y-z value triples
represent a computer approximation of a continuous 2D function, various
mathematical operations can be implemented that seem like natural from a
mathematical point of view, but not as trivial in a computer environment
where the data can have different x- and y-axis discretisations etc.
 
To do:
--> add math
--> return slices (intersections with planes) as 1D coFunc objects
 
  Methods defined here:
__abs__(self)
Return new coFunc2d object with the absolute z-values of this
object.
__call__(self, x, y, kind='linear', bounds_error=True, fill_value=nan)
Get the function value at any given coordinate (x, y). Interpolate
if needed. If bounds_error is True, error if (x, y) is out of range.
Otherwise, return fill_value for (x, y) out of range.
__getitem__(self, index)
__init__(self, x=[], y=[], z=[], dtype=None, attrs={})
Initialize the continuous 2D function object.
__len__(self)
__repr__(self)
Return complete string representation.
__str__(self)
Return short string representation.
a2cf(self, attrname)
Convert an array-like attribute to a coFunc2d object where the
z-data is the attribute and the x- and y-data are the original x- and
y-data of this coFunc2d object.
add(self, *points)
Add data points (3-tuples) to the function object.
box(self)
Return bounding box, i.e. [x_min, x_max, y_min, y_max, z_min,
z_max].
copy(self)
Return copy of this continuous 2D function object.
xyz(self)
Return x, y and z data as tuple (similar to what zip() does, but
more efficient, as the raw data arrays are directly returned).

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
__main__()
combine(cofuncs, cut=False)
Combine the x-y pairs of the given continuous function objects. Return a
new continuous function instance. If cut is True, only the intersection of
the x-axes is kept, the rest of the input functions is cut away. In that
case, raise an exception if the x-axes do not intersect.
intersection(cofuncs, enhance=1)
Return intersection of x-values of the given coFunc objects. Enhance the
resolution of the new axis by the given factor.
mean(cofuncs)
Return the mean of the given coFunc objects.
var(cofuncs)
Return the variance of the given coFunc objects.