grapa.parse.parser_dispatcher.FileParserDispatcher

class grapa.parse.parser_dispatcher.FileParserDispatcher

Bases: object

By default, 3 different reading modes are possible: 1. directly from data (filename=[[0,1,2,3],[5,2,7,4]])

2. column-organized datafile, with data starting at first row with a number in the first field

  1. database, with no number in the first column

File opening strategy:

1/ readDataFile

  • do some stuff with complementary input

  • read first 3 lines of the file (file_read_first3lines)

  • check if any of Graph child class can handle the file

  • if not, calls readDataFromFileTxt

2/ readDataFromFileTxt

  • look if file has a number in the first column

    (_which_default_parse_method). If so, call readDataFromFileGeneric, else call readDataFromFileDatabase.

__init__()

Methods

append_curve_from_datainput(graph, data, ...)

Initializes content of object using data given in constructor.

read(graph[, complement])

Reads a file, opens graph.filename graph: a graph object Complement: ...

readDataFromFileDatabase(graph, attributes)

fileContent: list of lists containing file content (imagine csv file) kwargs: useless here

readDataFromFileGeneric(graph, attributes[, ...])

Reads the file as a column-organized data file, with some headers lines at the beginning.

readDataFromFileTxt(graph, attributes[, ...])

Reads content of a .txt file, and parse it as a database or as a generic file.

classmethod readDataFromFileDatabase(graph: Graph, attributes, fileContent=None, **kwargs)

fileContent: list of lists containing file content (imagine csv file) kwargs: useless here

classmethod readDataFromFileGeneric(graph, attributes, fileContent=None, ifReplaceCommaByPoint=False, **kwargs)

Reads the file as a column-organized data file, with some headers lines at the beginning.

Parameters:
  • graph – the graph to put the data in

  • attributes

    provided when intantiating the Graph object. Special keyword:

    • _singlecurve: parse all data into a single Curve object

  • fileContent – if content to parse is given as a string, not from file read

  • ifReplaceCommaByPoint – if numbers are formatted with ‘,’ instead of ‘.’

  • kwargs

    the following keywords are handled:

    • delimiter: if provided, assumed the values is the text delimiter.

    • delimiterHeaders: same as delimiter, but only for the headers section

    • lstrip: a lstrip function is applied to each line when parsing the file. Values: True, or ‘# ‘ or similar

classmethod readDataFromFileTxt(graph: Graph, attributes, isfilecontent=False) bool

Reads content of a .txt file, and parse it as a database or as a generic file.