struc_array
index
/users/schrei_f/src/py4CAtS/lite/src/struc_array.py

Structured arrays --- some convenience functions to read and manipulate:
 
loadStrucArray:           Read a tabular ascii file and return a structured array
strucArrayChangeNames:    Change field names of some entries of a structured array
strucArrayExtractFields:  Extract some field entries of a structured array
strucArrayDeleteFields:   Delete some field entries of a structured array
strucArrayAddField:       Add a new field (data array) to a structured array
dict2strucArray:          Transform a dictionary of arrays into a structured numpy array
 
Documentation:
  http://docs.scipy.org/doc/numpy/user/basics.rec.html
  http://www.scipy.org/Cookbook/Recarray
 
Example:
  atm=loadStrucArray('midLatSummer.xy', -2, changeNames={'pressure':'p', 'temperature':'T'})

 
Functions
       
dict2strucArray(arrayDict, changeNames=None)
Transform a dictionary containing some arrays (of equal length) into a structured numpy array.
loadStrucArray(inFile, key2names=-1, changeNames=None, commentChar='#', verbose=False)
Read a tabular ascii file and return a structured array (closely related to record array, but more efficient).
 
key2names      identifies the row (record) in the file's header section (comments) where to read the field names.
               *  an integer specifying the row (0 for the very first, -1 for the last)
               *  a single word identical to the very first field name
               *  a string ending with ':' (e.g. "what:", the following words are taken as the field names)
               Alternatively you can explicitely specify the column ID's:
               *  a string (or list) with names (words, exactly as many as data columns)
changeNames    a dictionary to translate field names found in the file header.
 
NOTE:  If the dataset has more columns than names given, the extra columns are ignored.
       Blanks are not allowed in field names read from the file header.
strucArrayAddField(strucArray, newField, newName)
Add a new field (data array) to a structured array.
strucArrayChangeNames(strucArray, changeNames=None)
Change field names of some entries of a structured array.
strucArrayDeleteFields(strucArray, delete)
Delete some field entries of a structured array and return a smaller structured array.
strucArrayExtractFields(strucArray, extract)
Extract some field entries of a structured array and return a smaller structured array.