# data - Data handling utilities¶

 indfloat Convert string to float, with support for inf and nan. parse_file Parse a file into a header and data.

Data handling utilities.

bumps.data.indfloat(s)[source]

Convert string to float, with support for inf and nan.

Example:

>>> from numpy import isinf, isnan
>>> print(isinf(indfloat('inf')))
True
>>> print(isinf(indfloat('-inf')))
True
>>> print(isnan(indfloat('nan')))
True

bumps.data.parse_file(file, keysep=None, sep=None, comment='#')[source]

Parse a file into a header and data.

Return a (header, data) pair, where header is a key: value dictionary and data is a numpy array.

The header section is list of key value pairs, with the comment character at the start of each line. Key and value will be separated by keysep, or by spaces if keysep = None. The data section is a sequence of floating point numbers separated by sep, or by spaces if sep is None. inf and nan are parsed as inf and nan. Comments at the end of the data line will be ignored. Data points can be commented out by including a comment character at the start of the data line, assuming the next character is a digit, plus, or decimal separator.

Quotes around keys are removed. For compatibility with the old interface, quotes around values are removed as well.

Special hack for binned data: if the first column contains bin edges, then the last row will only have the bin edge. To make the array square, we replace the bin edges with bin centers. The original bins can be found in the header using the ‘bins’ key (unless that key already exists in the header, in which case the key will be ignored).