The PlainMesh class

class pylife.mesh.PlainMesh(pandas_obj)[source]

DataFrame accessor to access plain 2D and 3D mesh data, i.e. without connectivity

Raises:

AttributeError – if at least one of the columns x, y is missing

Notes

The PlainMesh describes meshes whose only geometrical information is the coordinates of the nodes or elements. Unlike Mesh they don’t know about connectivity, not even about elements and nodes.

See also

Mesh: accesses meshes with connectivity information pandas.api.extensions.register_dataframe_accessor(): concept of DataFrame accessors

broadcast(parameter, droplevel=None)

Broadcast the parameter to the object of self.

Parameters:

parameters (scalar, numpy array or pandas object) – The parameter to broadcast to

Returns:

parameter, object

Return type:

index aligned numerical objects

Examples

The behavior of the Broadcaster is best illustrated by examples:

  • Broadcasting pandas.Series to a scalar results in a scalar and a pandas.Series.

    obj = pd.Series([1.0, 2.0], index=pd.Index(['foo', 'bar'], name='idx'))
    obj
    
    idx
    foo    1.0
    bar    2.0
    dtype: float64
    
    parameter, obj = Broadcaster(obj).broadcast(5.0)
    
    parameter
    
    array(5.)
    
    obj
    
    idx
    foo    1.0
    bar    2.0
    dtype: float64
    
  • Broadcasting pandas.DataFrame to a scalar results in a pandas.DataFrame and a pandas.Series.

    obj = pd.DataFrame({
        'foo': [1.0, 2.0],
        'bar': [3.0, 4.0]
    }, index=pd.Index([1, 2], name='idx'))
    obj
    
    foo bar
    idx
    1 1.0 3.0
    2 2.0 4.0
    parameter, obj = Broadcaster(obj).broadcast(5.0)
    
    parameter
    
    idx
    1    5.0
    2    5.0
    dtype: float64
    
    obj
    
    foo bar
    idx
    1 1.0 3.0
    2 2.0 4.0
  • Broadcasting pandas.DataFrame to a a pandas.Series results in a pandas.DataFrame and a pandas.Series, if and only if the index name of the object is None.

    obj = pd.Series([1.0, 2.0], index=pd.Index(['tau', 'chi']))
    obj
    
    tau    1.0
    chi    2.0
    dtype: float64
    
    parameter = pd.Series([3.0, 4.0], index=pd.Index(['foo', 'bar'], name='idx'))
    parameter
    
    idx
    foo    3.0
    bar    4.0
    dtype: float64
    
    parameter, obj = Broadcaster(obj).broadcast(parameter)
    
    parameter
    
    idx
    foo    3.0
    bar    4.0
    dtype: float64
    
    obj
    
    tau chi
    idx
    foo 1.0 2.0
    bar 1.0 2.0
property coordinates

Returns the coordinate colums of the accessed DataFrame

Returns:

coordinates – The coordinates x, y and if 3D z of the accessed mesh

Return type:

pandas.DataFrame

property dimensions

The dimensions of the mesh (2 for 2D and 3 for 3D)

Note

If all the coordinates in z-direction are equal the mesh is considered 2D.

fail_if_key_missing(keys_to_check, msg=None)

Raise an exception if any key is missing in a self._obj object.

Parameters:
Raises:
  • AttributeError – if self._obj is neither a pandas.DataFrame nor a pandas.Series

  • AttributeError – if any of the keys is not found in the self._obj’s keys.

Notes

If self._obj is a pandas.DataFrame, all keys of keys_to_check meed to be found in the self._obj.columns.

If self._obj is a pandas.Series, all keys of keys_to_check meed to be found in the self._obj.index.

See also

get_missing_keys(), stresssignal.StressTensorVoigt

classmethod from_parameters(**kwargs)

Make a signal instance from a parameter set.

This is a convenience function to instantiate a signal from individual parameters rather than pandas objects.

A signal class like

@pd.api.extensions.register_dataframe_accessor('foo_signal')
class FooSignal(PylifeSignal):
    pass

The following two blocks are equivalent:

pd.Series({'foo': 1.0, 'bar': 2.0}).foo_signal
FooSignal.from_parameters(foo=1.0, bar=1.0)
get_missing_keys(keys_to_check)

Get a list of missing keys that are needed for a self._obj object.

Parameters:

keys_to_check (list) – A list of keys that need to be available in self._obj

Returns:

missing_keys – a list of missing keys

Return type:

list

Raises:

AttributeError – if self._obj is neither a pandas.DataFrame nor a pandas.Series

Notes

If self._obj is a pandas.DataFrame, all keys of keys_to_check not found in the self._obj.columns are returned.

If self._obj is a pandas.Series, all keys of keys_to_check not found in the self._obj.index are returned.

keys()

Get a list of missing keys that are needed for a signal object.

Returns:

keys – a pandas index of keys

Return type:

pd.Index

Raises:

AttributeError – if self._obj is neither a pandas.DataFrame nor a pandas.Series

Notes

If self._obj is a pandas.DataFrame, the self._obj.columns are returned.

If self._obj is a pandas.Series, the self._obj.index are returned.

to_pandas()

Expose the pandas object of the signal.

Returns:

pandas_object – The pandas object representing the signal

Return type:

pd.DataFrame or pd.Series

Notes

The default implementation just returns the object given when instantiating the signal class. Derived classes may return a modified object or augmented, if they store some extra information.

By default the object is not copied. So make a copy yourself, if you intent to modify it.