Table — Raw tabular data base.

This module defines the Table class for TABLE entries in BDPs.

class admit.util.Table.Table(**keyval)[source]

Defines the basic table structure used in ADMIT.

The Table class is a container for holding data in tabular format. The table can hold data in column-row format and also in plane-column-row format. Data can be added in instantiation, by columns, by rows, or by entire planes.

Parameters:

keyval : dict

Any valid attributes can be specified to the constructor.

Attributes

columns (List containing the column headers, optional) (defaults to an empty list)
units (List containing the units of each column, optional) (defaults to an empty list)
planes (List containing labels for each plane, optional) (defaults to an empty list)
data (A numpy array containing the data, can be 1D, 2D, or 3D, optional) (defaults to an empty array)
description (A string for a description/caption of the table, optional) (defaults to an empty string)

Methods

addColumn(data[, col]) Add a column to the table
addPlane(data[, plane]) Add a plane to the table
addRow(row) Add a row to the table
clear([full]) Method to clear out the data from the table
deserialize(serial) Create a Table from serialized data created by serialize().
exportTable(fileName[, plane, cols, fixcols]) Method to export a table to ascii text
getColumn(col[, plane, typ]) Get a single column by its index
getColumnByName(name[, plane, typ]) Get a column by its name
getFullColumnByName(name[, typ]) Method to get a full column (single column from all planes) by name
getHeader() Get the header information
getPlane(pln) Method to get a single plane from the table
getRow(row) Get data from a specific row
getRowAsDict(row) Get data from a specific row in dictionary format with the column headings as keys.
getUnits() Get the units information
getkey(key) Method to get a data member by name
html([css]) Create an HTML representation of the table
next() Method to get the next row from a table
rewind() Reset the “next” counter to the beginning
serialize() Create a string representation of the table that can be converted to native Python structures with ast.literal_eval or back to a Table with deserialize().
setData(data) Set the data of the table all at once
setkey([name, value]) set keys, two styles are possible:
shape()
addColumn(data, col='')[source]

Add a column to the table

Adds the given column to the table and recomputes the minimum and maximum. The column must have the same length as the other columns or numpy will throw an exception.

Parameters:

data : list or numpy array

The data of the column to be added

col : str, optional

The name of the column

Returns:

None

addPlane(data, plane='')[source]

Add a plane to the table

Adds the given plane to the table and recomputes the minimum and maximum. The plane must have the same dimensions as the other planes or numpy will throw an exception.

Parameters:

data : list or numpy array

The data of the plane to be added

plane : str, optional

The name of the plane. See getPlane() how to access a plane

Returns:

None

addRow(row)[source]

Add a row to the table

Adds the given row to the table and recomputes the minimum and maximum.

Parameters:

row : list or numpy array

The data of the row to be added

Returns:

None

clear(full=False)[source]

Method to clear out the data from the table

Parameters:

full : bool

If True then clear header and other meta data also Default: False

Returns:

None

deserialize(serial)[source]

Create a Table from serialized data created by serialize().

Parameters:

serial : The string representation of a Table in the format from

deserialize().

Returns:

None

exportTable(fileName, plane=0, cols=[], fixcols=[])[source]

Method to export a table to ascii text

Note only one plane at the time can be written. Alternatively one could allow multiple planes, and use another keyword for the fixcols=[], i.e. the columns that do not change per plane. This has not been implemented.

Parameters:

fileName : str

The name of the file to write the table to

plane : int or list, optional

What plane to export, defaults to the first plane (0). A list can be given if multiple planes need to be written.

cols : if given, a subset of these named columns will be written

Columns are written in the order they were listed originally, not the order in this given list. For multi-plane tables, these should be the columns that vary.

fixcols : if given, these are the named columns that are common for

all planes.

Returns:

None

getColumn(col, plane=0, typ=None)[source]

Get a single column by its index

Parameters:

col : int

The index of the column to retrieve

plane : int

The plane to retrieve it from if the table is 3D

typ : various

The data type to convert the data to. Default: None

Returns:

The data from the column as a numpy array, or None if the column index

does not exist.

getColumnByName(name, plane=0, typ=None)[source]

Get a column by its name

Parameters:

name : str

The name of the column to retrieve

plane : int

The plane to retrieve it from if the table is 3D

typ : various

The data type to convert the returning data to. Default: None (no conversion)

Returns:

The data from the column as a numpy array, or None if the column name

does not exist.

getFullColumnByName(name, typ=None)[source]

Method to get a full column (single column from all planes) by name

Parameters:

name : str

The name of the column to get

typ : various

The data type to convert the returning data to. Default: None (no conversion)

Returns:

Numpy array containing the data of the full column.

getHeader()[source]

Get the header information

Parameters:None
Returns:list of the column headers
getPlane(pln)[source]

Method to get a single plane from the table

Parameters:

pln : int

The plane number to get (0 based) No Default.

Returns:

Numpy array containing the requested plane

getRow(row)[source]

Get data from a specific row

Parameters:

row : int

The row to get

Returns:

a numpy array of the data of the specified row, or None if the

row does not exist

getRowAsDict(row)[source]

Get data from a specific row in dictionary format with the column headings as keys. If there are no column headings or two column headings are identical or column header has an empty string an exception is thrown. Note: this is not terribly useful for multi-plane Tables.

Parameters:

row : int

The row to get

Returns:

A dictionary of the data of the specified row, or None if the

row does not exist

getUnits()[source]

Get the units information

Parameters:None
Returns:list of the units headers
html(css=None)[source]

Create an HTML representation of the table

Parameters:

css : str

A string that may refer to a CSS or style parameter. This can be used for special formatting of the table, e.g. striping. Default: No extra formatting.

Returns:

string

HTML <table> representation.

next()[source]

Method to get the next row from a table

Parameters:None
Returns:List of the next row, None if there are no more.
rewind()[source]

Reset the “next” counter to the beginning

Parameters:None
Returns:None
serialize()[source]

Create a string representation of the table that can be converted to native Python structures with ast.literal_eval or back to a Table with deserialize(). Intended for the summary but can be used wherever.

Parameters:

None

Returns:

A string representation of the Table that can be converted back

to a Table with deserialize().

setData(data)[source]

Set the data of the table all at once

Parameters:

data : list or numpy array

The actual data to insert into the table

Returns:

None

shape()[source]