csv_data_file.py

csv_data_file.py#

aviary.utils.csv_data_file.read_data_file(filename: (<class 'str'>, <class 'pathlib.Path'>), metadata=None, aliases=None, save_comments=False)[source]

Read data file in Aviary format, which is data delimited by commas with any amount of whitespace allowed between data entries. Spaces are not allowed in openMDAO variables, so any spaces in header entries are replaced with underscores.

Parameters:
  • filename ((str, Path)) – filename or filepath of data file to be read

  • metadata (dict, optional) – metadata to check validity of variable names provided in data file. Columns with variable names that can’t be found in metadata will be skipped. If not provided, all validly formatted columns are always read.

  • aliases (dict, optional) – optional dictionary to define a mapping of variables to allowable aliases in the data file header. Keys are variable names, to be used in openMDAO, values are a list of headers that correspond to that variable. Alias matching is not case-sensitive, and underscores and spaces are treated as equivalent.

  • save_comments (bool, optional) – flag if comments in data file should be returned along with data. Defaults to False.

Returns:

  • data (NamedValues) – data read from file in NamedValues format, including variable name, units, and values (stored in a numpy array)

  • comments (list of str) – any comments from file, with comment characters (‘#’) stripped out (only if save_comments=True)

aviary.utils.csv_data_file.write_data_file(filename: (<class 'str'>, <class 'pathlib.Path'>) = None, data: ~aviary.utils.named_values.NamedValues = None, comments: (<class 'str'>, <class 'list'>) = [], include_timestamp: bool = False)[source]

Write data to a comma-separated values (csv) format file using the Aviary data table format.

Parameters:
  • filename ((str, Path)) – filename or filepath for data file to be written

  • data (NamedValues) – NamedValues object containing data that will be written to file, which includes variable name, units, and values

  • comments ((str, list of str), optional) – optional comments that will be included in the top of the output file, before data begins

  • include_timestamp (bool, optional) – optional flag to set if timestamp and user should be include in file comments