phase module

Phase history container. When you think of a phase value, think of that value at a specific point in time. This container holds the historic data of a phase; its species and quantities. This implementation treats access of time stamps within a tolerance. All searches for time stamped values are subjected to an approximation of the time stamp to avoid storing values too close to each other in time, and/or to return the closest value in time searched or no value if none can be found according to the tolerance.

Background

TODO: ATTENTION: The species (list of Specie) AND quantities (list of Quantity) data members have ARBITRARY density values either at an arbitrary point in the history or at no point in the history. This needs to be removed in the future to avoid confusion.

To obtain history values, associated to the phase, at a particular point in time, use the GetValue() method to access the history data frame (pandas) via columns and rows. ALERT: The corresponding values in species and quantities are OVERRIDEN and NOT to be used through the phase interface.

Author: Valmor F. de Almeida dealmeidav@ornl.gov; vfda Sat Sep 5 01:26:53 EDT 2015

Cortix: a program for system-level modules coupling, execution, and analysis.

class phase.Phase(time_stamp=None, time_unit=None, species=None, quantities=None)[source]

Bases: object

Phase history container. A Phase consists of Species and Quantities varying with time. This container is meant to reproduce the basic idea of a material phase.

AddQuantity(newQuant)[source]

Adds a new quantity object to the dataframe. See quantity.py for more details on the quantity class.

Parameters

newQuant (object) –

AddRow(try_time_stamp, row_values)[source]

Adds a row to the dataframe, with a timestamp of try_time_stamp and row values equal to row_values. Take care that the dimensions and order of the data matches up!

Parameters
  • try_time_stamp (float) –

  • row_values (list) –

AddSpecie(new_specie)[source]

Adds a new specie object to the phase history. See species.py for more details on the specie class.

Parameters

new_specie (obj) –

ClearHistory(value=0.0)[source]

Set species and quantities of history to a given value (default to zero value), all time stamps are preserved.

Parameters

value (float) –

GetActors()[source]

Returns a list of all the actors in the phase history.

Returns

list(self.__phase.colums)

Return type

list

GetColumn(actor)[source]

Returns an entire column of data. A column is the entire history of data associated with a specific actor.

Parameters

actor (str) –

Returns

list(self.__phase.loc[

Return type

, actor]): list

GetQuantities()[source]

Returns the list of Quantities. The values in each Quantity are synchronized with the Phase data frame.

Returns

quantities

Return type

list

GetQuantity(name)[source]

Returns the quantity evaluated at the last time step of the phase history. This also updates the value of the quantity object. If the quantity name does not exist the return is None.

Parameters

name (str) –

GetRow(try_time_stamp=None)[source]

Returns an entire row of the phase dataframe. A row is a series of values that are all at the same time stamp.

Parameters

try_time_stamp (float) –

Returns

list(self.__phase.loc[time_stamp,

Return type

]): list

GetSpecie(name)[source]

Returns the species specified by name if it exists, or none if it doesn’t.

Parameters

name (str) –

Returns

specie

Return type

str

GetSpecies()[source]

Returns every single species in the phase history.

Returns

species

Return type

list

GetTimeStamps()[source]

Returns a list of all the time stamps in the phase history.

Returns

timeStamps

Return type

list

GetValue(actor, try_time_stamp=None)[source]

Deprecated: use get_value()

ResetHistory(try_time_stamp=None, value=None)[source]

Set species and quantities of history to a given value (default to zero value) only one time stamp is preserved (default to last time stamp).

Parameters
ScaleRow(try_time_stamp, value)[source]

Multiplies all of the data in a row (except time stamp) by a scalar value.

Parameters
SetSpecieId(name, val)[source]

Sets the flag of a specie “name” equal to val.

Parameters
  • name (str) –

  • val (int) –

SetValue(actor, value, try_time_stamp=None)[source]

For the record: old def SetValue(self, time_stamp, actor, value):

Parameters
WriteHTML(fileName)[source]

Convert the Phase container into an HTML file.

Parameters

fileName (str) –

__init__(time_stamp=None, time_unit=None, species=None, quantities=None)[source]

Sometimes an empty Phase object is created by user code. This case needs adequate logic for None types. Note on usage: when passing quantities, do set the value argument explicitly to help define the type and avoid SetValue() errors with Pandas. This is to be investigated later. Also, the usage of a DataFrame needs to be re-evaluated. Maybe better to use a Quantity object and a Specie object with a Pandas Series history as a value to avoid the existance of a value in Quantity and a value in Phase that are not in sync.

get_quantity(name, try_time_stamp=None)[source]

New version. Get the quantity name at a point in time closest to try_time_stamp up to a tolerance. If no time stamp is passed, the whole history is returned.

Parameters
  • name (str) –

  • try_time_stamp (float, int or None) – Time stamp of desired quantity value. Default: None returns the whole quantity history.

Returns

quant.value

Return type

float or int or other

get_quantity_history(name)[source]

Create a Quantity name history. This will create a fully qualified Quantity object and return to the caller. The function is typically needed for data output to a file through pickle. Since the value attribute of a quantity can be any data structure, a time-series is built on the fly and stored in the value attribute. In addition the time unit is added to the final return value as a tuple.

Parameters

name (str) –

Returns

quant_history

Return type

tuple(Quantity,str)

get_value(actor, try_time_stamp=None)[source]

Returns the value associated with a specified actor at a specified time stamp.

Parameters
  • actor (str) –

  • try_time_stamp (float) –

Returns

self.__phase.loc[time_stamp, actor]

Return type

float

has_time_stamp(try_time_stamp)[source]

Checks to see if try_time_stamp exists in the phase history.

Parameters

try_time_stamp

quantities

Returns the list of Quantities. The values in each Quantity are synchronized with the Phase data frame.

Returns

quantities

Return type

list

set_value(actor, value, try_time_stamp=None)[source]

New version. Discontinue using SetValue()

species

Returns every single species in the phase history.

Returns

species

Return type

list

timeStamps

Returns a list of all the time stamps in the phase history.

Returns

timeStamps

Return type

list

time_stamps

Get all time stamps in the index of the data frame.

Returns

time_stamps

Return type

list

time_unit

Returns the time unit of the Phase.

Returns

time_unit

Return type

str