Reference for component developers

Array input and output

class anduril.arrayio.AndurilOutputArray(commandfile=None, port_name=None, filetype='', folder=None)

Bases: object

AndurilOutputArray automatically creates file names and writes them to the array file in disk when asked of keys with __getitem__. E.g.

>>> filename = andurilOutputArrayObject["myKey"]

You can also explicitely give the file name:

>>> andurilOutputArrayObject.write("myKey","path/to/my/file.txt")
close()
get_folder()
set_type(newtype)
write(key, filename)
class anduril.arrayio.ArrayReader(commandfile=None, port_name=None, folder=None)

Bases: object

get_folder()
next()

Returns the next value in the array

class anduril.arrayio.ArrayWriter(commandfile=None, port_name=None, folder=None)

Bases: object

Writes Anduril array files

close()
open()

Opens a new array file for writing.

writerow(row)

Write a row in the array file

writerows(rows)
anduril.arrayio.get_array(cf, array_name, relativeTo=None)

Return a list of tuples containing the key and filename of an Anduril array data type item, or None if the item is not defined. The value is always a string, if defined. cf is the CommandFile object created by Anduril component skeleton.

Tables

Module for reading and writing Anduril style CSV files.

An ambiguous definition of the CSV format used by Anduril components can be found from the datatypes.xml file of the builting component. This module implements that definition, and tries to fill in the ambiguous parts.

anduril.table.PandasReader(filename)

Returns a pandas data frame, from Anduril flavor TSV file

anduril.table.PandasWriter(dataframe, filename)

Writes a data frame as TSV file

class anduril.table.TableReader(filename, type='dict', column_types='guess')

Bases: object

Class for reading Anduril style CSV files. Parameters:

filename : Path to the CSV-file type : Return type for the rows, ‘dict’ or ‘list’ column_types : Data type for the columns, can be any type object,

‘guess’ or ‘strict’. Guessing ignores all the

quatations and tries to convert all the values to floats or booleans. Strict mode returns all quoted values as strings and tries to convert all unquoted values to floats returning NAN when failing.

get_column(col_name)

Returns the column as a list of values

get_dict(keyColumn=None, allowDuplicateKeys=False)

Returns the content of the table as a dictionary, where elements in keyColumn are used as keys.

Kwargs:

keyColumn (str): The name of the column which is used as the key for the row. If None, the first column is used. allowDuplicatedKeys (bool): If duplicate keys are not allowed and one is encountered an expetion is raised. If they

are allowed the latest row is returned in the dict.

Returns:

Dictionary object containing each row as an item where key is from the keyColumn and value contains the data in the rest of the columns. Note that the type of value depends on the type of the table instance.

get_fieldnames()

Returns the list of field names

get_numpy_array(types=None, numeric=False)

Reads the table to a Numpy Record Array object.

next()

Returns the next row in the table

open()

Open the file for reading. If file is already open, it is reset such that the iterators start from the begining of the file.

Note that this function is already called at the constructor!

read()

Returns the whole file contents as a list of row Dicts/lists depeding on the default type.

class anduril.table.TableWriter(filename, fieldnames=[])

Bases: object

Writes CSV files. Automatically quotes strings but leaves everything else unquoted. None, NA and nan objects are printed as NA strings without quoting as is standard in Anduril.

close()

Close the file.

open()

Opens a new file for writing.

set_fieldnames(fieldnames)

Set the field names for the table. Note that existing file will be erased

writerow(row)

Write a row in the array file. The row can be either dict or list type. Dictionary should have the keys as field names and values as data elements. List should have the data elements in the same order as fields in self.fieldnames.

writerows(rows)

Converters

anduril.converters.tojson.decorate(field)
anduril.converters.tojson.from_csv(csv, output='', **kwargs)

Converts a CSV file (or other iterable object) to a JSON format.

Args:

csv: The csv file, iterator to lines in the csv or a file name as a string. output: Defines how the output is produced, options are:

Empty string (default) - returns the JSON as a string. File name - opens the file, write the JSON to it and returns it. Open file - writes the JSON to the file, returns the file.

**kwargs: These are passsed to from_csv_iterator.

anduril.converters.tojson.from_csv_iterator(csv, format='plot', **kwargs)
anduril.converters.tojson.from_csv_iterator_plot(csv, columnsFieldName='columns', dataFieldName='data')
anduril.converters.tojson.from_csv_iterator_table(csv)
anduril.converters.tojson.isfloat(s)