phase_new 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 Species) 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_new.PhaseNew(name=None, 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.

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) –
GetQuantities()[source]

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

Returns:quantities
Return type:list
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:
__init__(name=None, 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 set_value() 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 Species 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.

actors

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

Returns:list(self.__df.colums)
Return type:list
add_quantity(new_quant)[source]

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

Parameters:new_quant (object) –
add_row(try_time_stamp, row_values)[source]

Adds a row to the DataFrame, with a timestamp equal to try_time_stamp and row values equal to row_values. The length of row_values must match the number of columns in the data frame.

Parameters:
  • try_time_stamp (float) –
  • row_values (list) –
add_single_species(new_species)[source]

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

Parameters:new_species (obj) –
df

Die hard access.

get_column(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.__df.loc[
Return type:, actor]): list
get_quantity(name, try_time_stamp=None)[source]

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 value at the last time stamp is returned.

Parameters:
  • name (str) –
  • try_time_stamp (float, int or None) – Time stamp of desired quantity value. Default: None, returns the value at the last time stamp.
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_row(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.__df.loc[time_stamp,
Return type:]): list
get_species(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
get_species_concentration(name, try_time_stamp=None)[source]

Returns the species concentration at try_time_stamp.

Parameters:
  • name (str) –
  • try_time_time_stamp (float) –
Returns:

concentration

Return type:

float

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) – Default is None which returns the last time stamp.
Returns:

self.__df.loc[time_stamp, actor]

Return type:

any

has_time_stamp(try_time_stamp)[source]

Checks to see if try_time_stamp exists in the phase history.

Parameters:try_time_stamp
plot(name='phase-plot-name', time_unit='s', legend=None, nrows=2, ncols=2, dpi=200)[source]
plot_species(name, scaling=[1.0, 1.0], title=None, xlabel='Time [s]', ylabel='y', legend='no-legend', filename_tag=None, figsize=[6, 5], dpi=100)[source]
quantities

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

Returns:quantities
Return type:list
scale_row(try_time_stamp, value)[source]

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

Parameters:
set_species_id(name, val)[source]

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

Parameters:
  • name (str) –
  • val (int) –
set_value(actor, value, try_time_stamp=None)[source]
species

Returns every single species in the phase history.

Returns:species
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
write_html(fileName)[source]

Convert the Phase container into an HTML file.

Parameters:fileName (str) –