anypytools.tools#

Created on Sun Sep 7 13:25:38 2014.

@author: Morten

Module Contents#

Classes#

AnyPyProcessOutput

Subclassed OrderedDict which supports partial key access.

AnyPyProcessOutputList

List like class to wrap the output of model simulations.

AMSVersion

Functions#

array2anyscript

Format a numpy array as an anyscript variable.

case_preserving_replace

Replace string while preserving the case

define2str

get_ammr_version

Return the AMMR version if possible.

get_anybodycon_path

Return the path to default AnyBody console application. If AnyBodyCon.exe is on path it will take precedence over the registry lookup.

winepath

Wrapper for the winepath commandline tool

anybodycon_version

Return the AnyBodyCon version.

parse_anybodycon_output

Parse the output log file from AnyBodyConsole to for data, errors and warnings. If fatal_warnins is True, then warnings are also added to the error list.

wraptext

Wraps text to fit the terminal window.

API#

class anypytools.tools.AnyPyProcessOutput(*args, **kwargs)#

Bases: collections.OrderedDict

Subclassed OrderedDict which supports partial key access.

Initialization

Initialize self. See help(type(self)) for accurate signature.

__getitem__(key)#
_repr_gen(prefix)#
__repr__(_repr_running={}, prefix='')#
_get_index_length(index_var='auto')#

Find the length of the index_var variable or look for a time dimension in the data set if index_var=”auto”

to_dataframe(index_var: str | None = 'auto', interp_var=None, interp_val=None, interp_method='cubic')#

Convert the output to a pandas dataframe.

Parameters:
  • index_var (str) – Name of the variable to use as axis 0 in the dataframe. If “auto” is given the system will look for variables ending with “Ouput.Abcsissa.t”. If ‘None’ no index variable is used an only a single row is returned in the dataframe.

  • interp_var (str) – Name of the variable on which the data is interpolating/resampled.

  • interp_val (np.ndarray) – Values to use when re-interpolating/resampling the data.

  • interp_method (str) – Method to use when re-interpolating/resampling the data. Defaults to ‘cubic’.

Returns:

df – Dataframe with the output data.

Return type:

pandas.DataFrame

class anypytools.tools.AnyPyProcessOutputList(*args)#

Bases: collections.abc.MutableSequence

List like class to wrap the output of model simulations.

The class behaves as a normal list but provide extra function to easily access data.

Initialization

check(v)#
__len__()#
__getitem__(item)#
__delitem__(item)#
__setitem__(item, v)#
insert(item, v)#
__str__()#
__repr__()#
filter(function)#

Filter elements for whichfunction returns true.

shelve(filename, key='results')#
classmethod from_shelve(filename, key='results')#
tolist()#

Return as native python types (list of dicts).

to_dataframe(index_var='auto', include_task_info=False, **kwargs)#

Return output of all simuations as a concatenated pandas dataframe.

Parameters:
  • index_var (str) – Name of the variable to use as axis 0 in the dataframe. If not given system will look for variables ending with “Ouput.Abcsissa.t”

  • interp_var (str) – Name of the variable on which the data is interpolating/resampled.

  • interp_val (np.ndarray) – Values to use when re-interpolating/resampling the data.

  • interp_method (str) – Method to use when re-interpolating/resampling the data. Defaults to ‘cubic’.

  • include_task_info (bool) – If True variables starting with task_* are included in the dataframe.

Return type:

pandas.DataFrame

anypytools.tools.array2anyscript(arr)#

Format a numpy array as an anyscript variable.

anypytools.tools.case_preserving_replace(string, old, new)#

Replace string while preserving the case

anypytools.tools.define2str(key, value=None)#
anypytools.tools.get_ammr_version(folder=None)#

Return the AMMR version if possible.

The function will walk up a directory tree looking for a ammr_verion.any file to parse.

anypytools.tools.get_anybodycon_path() str | None#

Return the path to default AnyBody console application. If AnyBodyCon.exe is on path it will take precedence over the registry lookup.

anypytools.tools.winepath(path, opts=None)#

Wrapper for the winepath commandline tool

anypytools.tools.anybodycon_version(anybodyconpath=None)#

Return the AnyBodyCon version.

class anypytools.tools.AMSVersion#
major: int = None#
minor: int = None#
patch: int = None#
build: int = None#
classmethod from_string(version_string)#
_as_tuple()#
__eq__(other)#
__lt__(other)#
__ne__(other)#
__le__(other)#
__ge__(other)#
__gt__(other)#
anypytools.tools.parse_anybodycon_output(raw, errors_to_ignore=None, warnings_to_include=None, fatal_warnings=False)#

Parse the output log file from AnyBodyConsole to for data, errors and warnings. If fatal_warnins is True, then warnings are also added to the error list.

anypytools.tools.wraptext(elem, initial_indent='', subsequent_indent=None)#

Wraps text to fit the terminal window.