Package ivs :: Package inout :: Module ascii
[hide private]
[frames] | no frames]

Module ascii

source code

Read and write ASCII files.

Functions [hide private]
    General Input
(list,list)
read2list(filename, **kwargs)
Load an ASCII file to list of lists.
source code
ndarray (, list)
read2array(filename, **kwargs)
Load ASCII file to a numpy array.
source code
ndarray (, list)
read2recarray(filename, **kwargs)
Load ASCII file to a numpy record array.
source code
    General Output
 
write_array(data, filename, **kwargs)
Save a numpy array to an ASCII file.
source code
    Helper functions
 
fw2info(fixwidth)
Convert fix width information to python information
source code
 
fws2info(fixwidths) source code
 
fw2python(line, fixwidths, missing_value=0)
Fixwidth info to python objects
source code
    Source specific
array,array,dict
read_harps(filename)
Return spectrum and header from a HARPS normalised file.
source code
 
read_mad(infile, add_dp=False, **kwargs)
Reads .phot from MADROT or .nad from MAD.
source code
 
read_photrot(infile, teff=None, logg=None)
Reads .phot output file of MADROT.
source code
 
read_phot(photfile, teff=None, logg=None)
Reads .phot output file of MAD.
source code
 
read_nad(nadfile, only_header=False)
Reads .nad output file of MAD.
source code
Variables [hide private]
  logger = logging.getLogger("IO.ASCII")
Function Details [hide private]

read2list(filename, **kwargs)

source code 

Load an ASCII file to list of lists.

The comments and data go to two different lists.

Also opens gzipped files.

Parameters:
  • filename (string) - name of file with the data
  • commentchar (list of str) - character(s) denoting comment rules
  • splitchar (str or None) - character seperating entries in a row (default: whitespace)
  • skip_empty (bool) - skip empty lines
  • skip_lines (integer) - skip nr of lines (including comment and empty lines)
Returns: (list,list)
list of lists (data rows) list of lists (comments lines without commentchar),

read2array(filename, **kwargs)

source code 

Load ASCII file to a numpy array.

For a list of extra keyword arguments, see <read2list>.

If you want to return a list of the columns instead of rows, just do

>>> col1,col2,col3 = ascii.read2array(myfile).T

Parameters:
  • filename (string) - name of file with the data
  • dtype (numpy dtype) - type of numpy array (default: float)
  • return_comments (bool) - flag to return comments (default: False)
Returns: ndarray (, list)
data array (, list of comments)

read2recarray(filename, **kwargs)

source code 

Load ASCII file to a numpy record array.

For a list of extra keyword arguments, see <read2list>.

IF dtypes is None, we have some room to automatically detect the contents of the columns. This is not implemented yet.

the keyword 'dtype' should be equal to a list of tuples, e.g.

dtype = [('col1','a10'),('col2','>f4'),..]

Parameters:
  • filename (string) - name of file with the data
  • dtype (list of tuples) - dtypes of record array
  • return_comments (bool) - flag to return comments (default: False)
Returns: ndarray (, list)
data array (, list of comments)

write_array(data, filename, **kwargs)

source code 

Save a numpy array to an ASCII file.

Add comments via keyword comments (a list of strings denoting every comment line). By default, the comment lines will be preceded by the commentchar. If you want to override this behaviour, set commentchar=''.

If you give a record array, you can simply set header to True to write the header, instead of specifying a list of strings.

Parameters:
  • header (list of str (or boolean for record arrays)) - optional header for column names
  • comments (list of str) - comment lines
  • commentchar (str) - comment character
  • sep (str) - separator for the columns and header names
  • axis0 (str, one of cols, rows.) - string denoting the orientation of the matrix. If you gave a list of columns, set axis0='cols', otherwise axis='rows' (default).
  • mode (char (one of 'a','w'...)) - file mode (a for appending, w for (over)writing...)
  • auto_width (bool) - automatically determine the width of the columns
  • formats (list of string formatters) - formats to use to write each column

fw2info(fixwidth)

source code 

Convert fix width information to python information

>>> fw2info('F13.4')
([float], [13])
>>> fw2info('I2')
([int], [2])
>>> fw2info('6I2')
([int, int, int, int, int, int], [2, 2, 2, 2, 2, 2])
>>> fw2info('5F12.3')
([float, float, float, float, float], [12, 12, 12, 12, 12])

read_harps(filename)

source code 

Return spectrum and header from a HARPS normalised file.

Parameters:
  • filename (str) - name of the file
Returns: array,array,dict
wavelengths,flux,header

read_mad(infile, add_dp=False, **kwargs)

source code 

Reads .phot from MADROT or .nad from MAD.

MAD is the nonadiabatic pulsation code from Marc-Antoine Dupret.

MADROT is the extension for slowly rotating stars in the traditional approximation.

This function serves a generic read function, it reads *.phot and *.nad files, both from MAD and MADROT.

Returns list of dicts

Parameters:
  • add_dp (boolean) - add period spacings information
Returns:
star info, blocks

read_photrot(infile, teff=None, logg=None)

source code 

 Reads .phot output file of MADROT.
 
 Returns list of dictionaries
 
 For quick reading, you can already give a range on teff and logg, and skip
 the rest of file.
     
 if there is a NAD file with the same name (but extension .nad instead of .phot),
 we read in the header of this file too for information on the star::
     
     #   M/M_sun =  1.40      Teff    =   6510.2    Log (L/L_sun) =  0.5168                              
     #   Log g   =  4.2748    R/R_sun =  1.4283     age (y)       =  2.3477E+08                          
     #   X       =  0.70      Z       =  0.020      alphaconv     =  1.80     overshoot =  0.40 
 
if the filename is given as C{M1.4_0.020_0.40_0.70_001-0097.phot}, we add
information on mass, Z, overshoot, X and evolution number to star_info,
except for those quantities already derived from a NAD file.

One dictionary representes information about one pulsation mode.

@param teff: range in effective temperature for file selection (value, sigma)
@type teff: tuple
@param logg: range in surface gravity for file selection (value, sigma)
@type logg: tuple

read_phot(photfile, teff=None, logg=None)

source code 

Reads .phot output file of MAD.

Returns list of dictionaries

One dictionary representes information about one pulsation mode.

read_nad(nadfile, only_header=False)

source code 

Reads .nad output file of MAD.

Returns list of dictionaries One dictionary representes information about one pulsation mode.