Skip to content

Latest commit

 

History

History
397 lines (318 loc) · 18.4 KB

File metadata and controls

397 lines (318 loc) · 18.4 KB




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]
Returns the index of first item in the `iterable` that satisfies the `condition`.

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]
Return the kcol-th column from xdata

Parameters
xdata 2D array_like or Table
     the data array kcol int
     column index

isBetween( xs, x, xe ) [source]
Return True when x falls between xs and xe or on xs or xe.
     where the order of xs, xe is unknown.

getKwargs( **kwargs ) [source]
Return kwargs as dictionary

setAttribute( obj, name, value, type=None, islist=False, isnone=False ) [source]

setNoneAttributes( obj, name, value, listNone ) [source]
Set an attribute to an object.

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]
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
  • 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]
Set a singular attribute contained in dictionary dictSingle into the attr-list. It also checks the type.

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]
Return the length of any item. Singletons have length 1; None has length 0..

isList( item, cls ) [source]
Return a array of x when x is a number

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]
Return (True,False) if item is a instance of cls
        (True,True) if item is a (list|ndarray) of instances of cls
        (False,False) if not

subclassof( sub, cls ) [source]
Transfer attributes from src to des. If copy is True try to copy the attributes, otherwise link it.

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]
Determine if sub inherits from the class cls

Parameters

  • sub : class object
         supposed sub class
  • cls : class object
         supposed parent class

printlist( val, nitems=8 ) [source]

shortName( val ) [source]
Print the attributes of a class.

nicenumber( x ) [source]
Return a short version the string representation: upto first non-letter.

average( xx, weights=None, circular=None ) [source]

Parameters

  • statement : str
         statement to be traced

toRect( rp, phi=None ) [source]
Return (x,y) coordinates from (rho,phi)

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]
Return (x,y,z) coordinates from (rho,phi,theta)

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]
Return (rho,phi,theta) coordinates from (x,y,z)

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]
Return (rho,phi) coordinates from (x,y)

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]
Return the coordinates of an arrow point from (xyz[0]) to (xyz[1])

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]
Return minimum, maximum, range and midpoint of an array

Parameters

  • x : array
         the array
  • range : bool (False)
         return range (max - min) too
  • mid : bool (False)
         return midpoint (max + min) / 2 too