ESA.util.line_process_m
index
/home/lfeng/otool/ESA/util/line_process_m.py

Functions for processing text line
 
Authors: L. Feng, Edinburgh University
History: v0.9, 2012.06.30
History: v0.95, 2012.09.18
 
 
1.Functions:
========================================================
1. decode_line: split one line into terms
 
2. decode_keyword_line: split one line into keyword and values 
 
3. process_terms: select and convert items into required types. 
 
4. read_table_from_lines: decode lines into a table (recarray)
 
5. read_matrix_from_lines: decode lines into a matrix (array)

 
Modules
       
ESA.util.message_m
numpy
ESA.util.otool_obj

 
Functions
       
decode_keyword_line(line, delim_keyword, delim)
Decode one line into key word and values 
    
Inputs:
-----------------------------------------------------------
1. line:<str>: line to decode 
2. delim_keyword:<str>: the sperator between keyword and values
3. delim:<str>: sperator for value line 
 
Returns:
---------------------------------------------------------
1. keyword:<str>: keyword (left term)
2. terms:<list, t:str>: value (right term)
 
Notes:
 
1. if a line is given as line='A:1, 2,3'
decode_keyword_line(line, ':', ',') will yield
keyword='A'
terms=['1', '2', '3']
decode_line(line, delim)
splite one line into terms. 
 
Inputs:
-----------------------------------------------------------
1. line:<str>: line to decode 
2. delim:<str>: splitor for line 
    
Returns:
---------------------------------------------------------
out_terms:<list>: terms in the given line
process_terms(terms, sel_col, col_type)
select terms, and convert them into certain types
 
Inputs:
----------------------------------------------------------
1. terms:<list, t:str>: list of terms to be processes
2. sel_col:<list, t:integer>: terms to be chosen
3. col_type:<list, t:str>: types to be converted to. 
 
Returns:
-------------------------------------------------------------
1. sel_terms:<list>: selected terms 
 
Notes:
-------------------------------------------------------------
1. If one element can be converted into  desired type, it will be replaced by a filling value.
read_matrix_from_lines(lines, colno_lst, lstart, lend, delim=' ', comment_begin='#', **replaces)
read txt lines into  a matrix 
    
Inputs:
------------------------------------------------------
1. lines:<list, t:str>: lines from file 
2. colno_lst:<list, t:str_>:list of column number to be read
4. lstar:<int>: start row
5. lend:<inte>: end row
6. replaces: <dict>: the words need to be replace before conversion. 
 
Returns:
-------------------------------------------------
1.data:<array>: data matrix 
 
Notes:
----------------------------------------------------
1. Selected columns will be converted into float.
read_table_from_lines(lines, colnm_lst, colno_lst, coltype_lst, lstart, lend, delim=' ', comment_begin='#', **replaces)
read txt lines into a record table
 
Inputs:
------------------------------------------------------
1. lines:<list, t:str>: lines from file 
2. colnm_lst:<list, t:str_>:list of column name to be read
3. colno_lst:<list, t:str_>:list of column number to be read
4. coltype_lst:<list, t:str_>:list of column type to be converted to
5. lstar:<int>: start row
6. lend:<inte>: end row
7. replaces: <dict>: the words need to be replace before conversion. 
 
Returns:
-------------------------------------------------
1.dtable:<recarray>: data