chisurf.fio.ascii module

class chisurf.fio.ascii.Csv(*args, filename=None, colspecs=None, use_header=False, x_on=True, y_on=True, col_x=0, col_y=1, col_ex=2, col_ey=3, reverse=False, error_x_on=False, directory='.', skiprows=9, verbose=False, file_type='csv', **kwargs)[source]

Bases: object

Csv is a class to handle coma separated value files.

Parameters

kwargs

Examples

Two-column data

>>> import chisurf.fio.ascii
>>> csv = chisurf.fio.ascii.Csv(skiprows=10)
>>> filename = './test/data/tcspc/ibh_sample/Decay_577D.txt'
>>> csv.load(filename)
>>> csv.data
array([  1.00000000e+00,   2.00000000e+00,   3.00000000e+00, ...,
 4.09400000e+03,   4.09500000e+03,   4.09600000e+03])
 >>> csv.data_y
 array([ 0.,  0.,  0., ...,  0.,  0.,  0.])
 >>> max(csv.data_y)
 50010.0

One-column Jordi data

>>> csv = chisurf.fio.ascii.Csv(skiprows=11)
>>> filename =  './test/data/tcspc/ibh_sample/Decay_577D.txt'
>>> csv.load(filename)
>>> csv.data_x
array([  1.00000000e+00,   2.00000000e+00,   3.00000000e+00, ...,
 4.09400000e+03,   4.09500000e+03,   4.09600000e+03])
 >>> csv.data_y
 array([ 0.,  0.,  0., ...,  0.,  0.,  0.])
 >>> max(csv.data_y)
 50010.0
property data

Numpy array of the data

Return type

array

property filename

The currently open filename (after setting this parameter the file is opened)

Return type

str

property header

A list of the column headers

Return type

List[str]

load(self, filename: 'str', skiprows: 'int' = None, use_header: 'bool' = None, verbose: 'bool' = False, delimiter: 'str' = None, file_type: 'str' = None, infer_delimiter: 'bool' = True, usecols: 'typing.List[int]' = None, **kwargs) → 'None'[source]

This method loads a filename to the Csv object :type filename: str :param filename: string specifying the file :type skiprows: Optional[int] :param skiprows: number of rows to skip in the file. By default the value of the instance is used :type verbose: bool :param verbose: The method is verbose if verbose is set to True of the verbose attribute of the instance is True.

Return type

None

property n_cols

The number of columns

Return type

int

property n_points

The number of data points corresponds to the number of rows :py:attribute`.CSV.n_rows`

Return type

int

property n_rows

The number of rows

Return type

int

save(self, data: 'np.ndarray', filename: 'str', delimiter: 'str' = 't', file_type: 'str' = 'txt', header: 'str' = '')[source]
chisurf.fio.ascii.load_xy(filename: 'str', verbose: 'bool' = False, usecols: 'typing.Tuple[int, int]' = None, skiprows: 'int' = 0, delimiter: 'str' = 't') → 'typing.Tuple[np.array, np.array]'[source]
Return type

Tuple[array, array]

chisurf.fio.ascii.save_xy(filename: 'str', x: 'np.ndarray', y: 'np.ndarray', verbose: 'bool' = False, fmt: 'str' = '%.3ft%.3f', header_string: 'str' = None) → 'None'[source]

Saves data x, y to file in format (csv). x and y should have the same length.

Parameters
  • filename (str) – string Target filename

  • x (ndarray) – array

  • y (ndarray) – array

  • verbose (bool) – bool

  • header_string (Optional[str]) –

  • fmt (str) –

Return type

None