| Module Tools | [source] |
|---|
This module contains a mixed bag of "usefull" methods.
| getItem( ilist, k ) | [source] |
|---|
Return the k-th item of the ilist
or the last when not enough
or the ilist itself when it is not a list
Parameters
- ilist : an item or a list of items
List to obtain an item from - k : int
item to be returned
| firstIndex( iterable, condition=lambda x: True ) | [source] |
|---|
If the condition is not given, it returns 0
Parameters
- iterable : iterable
to find the first item in - condition : lambda function
the condition
Raises
StopIteration: if no item satysfing the condition is found.
Examples
firstIndex( (1,2,3), condition=lambda x: x % 2 == 0)
2
firstIndex( range( 3, 100 ) )
3
firstIndex( () )
Traceback (most recent call last)
...
StopIteration
| getColumnData( xdata, kcol ) | [source] |
|---|
Parameters
xdata 2D array_like or Table
the data array
kcol int
column index
| isBetween( xs, x, xe ) | [source] |
|---|
where the order of xs, xe is unknown.
| getKwargs( **kwargs ) | [source] |
|---|
| setAttribute( obj, name, value, type=None, islist=False, isnone=False ) | [source] |
|---|
| setNoneAttributes( obj, name, value, listNone ) | [source] |
|---|
Parameters
- obj : object
to set the attribute to - name : str
of the attribute - value : any
of the attribute - type : class
check class of the object - islist : boolean
check if it is a list of type - isnone : boolean
value could be a None
Raises
TypeError : if any checks fails
| setListOfAttributes( obj, name, value, dictList ) | [source] |
|---|
Parameters
- obj : object
to place the attribute in - name : str
of the attribute - value : any
of the attribute - listNone : list of names
that could have a None value
Returns
True on succesful insertion. False otherwise.
Raises
TypeError if the type is not as in the dictionary
| setSingleAttributes( obj, name, value, dictSingle ) | [source] |
|---|
""" Set attribute contained in dictionary dictList into the attr-list. A list is a native list or a numpy.ndarray. It also checks the type. if values is a singular item of the proper type it will be inserted as [value].
Parameters
- obj : object
to place the attribute in - name : str
of the attribute - value : any
of the attribute - dictList : dictionary
of possible attributes {"name": type}
Returns
True on succesful insertion. False otherwise.
Raises
TypeError if the type is not as in the dictionary
| makeNext( x, k ) | [source] |
|---|
Parameters
- obj : object
to place the attribute in - name : str
of the attribute - value : any
of the attribute - dictSingle : dictionary
of possible attributes {"name": type}
Returns
True on succesful insertion. False otherwise.
Raises
TypeError if the type is not as in the dictionary
| length( x ) | [source] |
|---|
""" Return next item of x, and last item if x is exhausted. Or x itself if x is singular.
| toArray( x, ndim=1, dtype=None ) | [source] |
|---|
| isList( item, cls ) | [source] |
|---|
Parameters
- x : any number, list/array of numbers or []
to be converted to numpy.ndarray - ndim : int
minimum number of dimensions present - dtype : type
conversion to type (None : as is)
| isInstance( item, cls ) | [source] |
|---|
(True,True) if item is a (list|ndarray) of instances of cls
(False,False) if not
| subclassof( sub, cls ) | [source] |
|---|
Parameters
- src : object
source of the attributes - des : object
destiny for the attributes - copy : bool
if True: copy
| printclass( cls, nitems=8, printId=False ) | [source] |
|---|
Parameters
- sub : class object
supposed sub class - cls : class object
supposed parent class
| printlist( val, nitems=8 ) | [source] |
|---|
| shortName( val ) | [source] |
|---|
| nicenumber( x ) | [source] |
|---|
| average( xx, weights=None, circular=None ) | [source] |
|---|
Parameters
- statement : str
statement to be traced
| toRect( rp, phi=None ) | [source] |
|---|
Angles are measured counterclockwise from north to east North is Down (-y) and East is to the Right (+x)
Parameters
- rp : array of pairs [rho,phi] or tuple of (rhos,phis)
rp[:,0] : separation of the stars
rp[:,1] : angle from north (down) CCW to east (right) - phi : array
When phi is given, rp is interpeted as rho.
Returns
2d-array if the input is a 2d-array or
tuple of 2 arrays if the input is a tuple of 2 arrays or phi is given
| toRect3D( rho, phi, theta ) | [source] |
|---|
The angle phi is measured counterclockwise from north to east North is Down (-y) and East is to the Right (+x) The angle theta is measured form the (x,y) plane. Up is positive (+) and down is negative (-)
Parameters
- rho : array of float
Separation between the stars - phi : array of float
angle in (x,y) plane from -y (North,down) to +x (East,right) - theta : array of float
angle between z and star 2
Returns
- (x,y,z) : tuple of 3 arrays
| toSpher3D( x, y, z ) | [source] |
|---|
See toRect3D()
Parameters
- x : array of float
x position - y : array of float
y position - z : array of float
z position
Returns
- (rho,phi,theta) : tuple of 3 arrays
| toSpher( xy, y=None ) | [source] |
|---|
Angles are measured counterclockwise from north to east North is Down (-y) and East is to the Right (+x)
Parameters
- xy : array of pairs [x,y] or tuple of (x array,y array)
xy[:,0] : x position
xy[:,1] : y position - y : array
when given xy is interpreted as x
Returns
2d-array if the input is a 2d-array or
tuple of 2 arrays if the input is a tuple of 2 arrays or when y is given
| arrow( x, y, z=None, scale=1.0 ) | [source] |
|---|
The returned 2-d coordinates are at
tail, top, left-head, right-head, top
the returned 3-d coordinates are at
tail, top, left-head, right-head, top, read-head, near-head, top
Parameters
- x : array of length 2 (at least)
x-coordinates - y : array of length 2 (at least)
y-coordinates - z : array of length 2 or None n None return 2D array else 3D
- scale : float
scale factor. End point stays in place
| minmax( x, range=False, mid=False ) | [source] |
|---|
Parameters
- x : array
the array - range : bool (False)
return range (max - min) too - mid : bool (False)
return midpoint (max + min) / 2 too