psctb.utils.misc package¶
Submodules¶
psctb.utils.misc._misc module¶
-
psctb.utils.misc._misc.cc_list(mod)[source]¶ Retuns a list of control coefficients of a model.
The list contains both flux and species control coefficients and control coefficients follow the syntax of ‘cc_controlled_controller’.
Parameters: - mod : PysMod
The Pysces model contains the reactions and species which is used to construct the control coefficient list.
Returns: - list of str
The cc_list is sorted alphabetically.
-
psctb.utils.misc._misc.ec_list(mod)[source]¶ Retuns a list of elasticity coefficients of a model.
The list contains both species and parameter elasticity coefficients and elasticity coefficients follow the syntax of ‘ec_reaction_sp-or-param’.
Parameters: - mod : PysMod
The Pysces model contains the reactions, species and parameters which is used to construct the elasticity coefficient list.
Returns: - list of str
The ec_list is sorted alphabetically.
-
psctb.utils.misc._misc.prod_ec_list(mod)[source]¶ Returns a list of product elasticity coefficients of a model.
Returns: - list of str
The prod_ec_list is sorted alphabetically.
-
psctb.utils.misc._misc.mod_ec_list(mod)[source]¶ Returns a list of modifier elasticity coefficients of a model.
Returns: - list of str
The mod_ec_list is sorted alphabetically.
-
psctb.utils.misc._misc.rc_list(mod)[source]¶ Retuns a list of response coefficients of a model.
The list contains both species and flux response coefficients and response coefficients follow the syntax of ‘rc_responder_parameter’.
Parameters: - mod : PysMod
The Pysces model contains the reactions, species and parameters which is used to construct the response coefficient list.
Returns: - list of str
The rc_list is sorted alphabetically.
-
psctb.utils.misc._misc.prc_list(mod)[source]¶ Retuns a list of partial response coefficients of a model.
The list contains both species and flux partial response coefficients and partial response coefficients follow the syntax of ‘prc_responder_parameter_route’.
Parameters: - mod : PysMod
The Pysces model contains the reactions, species and parameters which is used to construct the partial response coefficient list.
Returns: - list of str
The prc_list is sorted alphabetically.
-
psctb.utils.misc._misc.silence_print(func)[source]¶ A function wrapper that silences the stdout output of a function.
This function is very useful for silencing pysces functions that print a lot of unneeded output.
Parameters: - func : function
A function that talks too much.
Returns: - function
A very quiet function
-
class
psctb.utils.misc._misc.DotDict(*args, **kwargs)[source]¶ Bases:
dictA class that inherits from
dict.The DotDict class has the same functionality as
dictbut with the added feature that dictionary elements may be accessed via dot notation.See also
dictPseudoDotDict
Methods
clear()copy()fromkeys(iterable[, value])Create a new dictionary with keys from iterable and values set to value. get(key[, default])Return the value for key if key is in the dictionary, else default. items()keys()pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised popitem()2-tuple; but raise KeyError if D is empty. setdefault(key[, default])Insert key with a value of default if key is not in the dictionary. update([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] values()
-
class
psctb.utils.misc._misc.PseudoDotDict(*args, **kwargs)[source]¶ Bases:
objectA class that acts like a dictionary with dot accessible elements.
This class is not subsclassed from
dictlike DotDict, but rather wraps dictionary functionality.This object has trouble being pickled :’(
See also
dictDotDict
Methods
update
-
psctb.utils.misc._misc.is_number(suspected_number)[source]¶ Test if an object is a number
Parameters: - suspected_number: object
This can be any object which might be a number.
Returns: - boolean
True if object is a number, else false
-
psctb.utils.misc._misc.formatter_factory(min_val=None, max_val=None, default_fmt=None, outlier_fmt=None)[source]¶ Returns a custom html_table object cell content formatter function.
Parameters: - min_val : int or float, optional (Default
The minimum value for float display cutoff.
- max_val : int of float, optional (Default
The maximum value for float display cutoff.
- default_fmt : str, options (Default
The default format for any number within the range of min_val to max_val.
- outlier_fmt : str, optional (Default
The format for any number not in the range of min_val to max_val
Returns: - formatter : function
A function which formats input for html_table using the values set up by this function.
Examples
>>> f = formatter_factory(min_val=1, max_val=10, default_fmt='%.2f', outlier_fmt='%.2e') >>> f(1) '1.00' >>> f(5.235) '5.24' >>> f(10) '10.00' >>> f(0.99842) '9.98e-01' >>> f('abc') 'abc'
-
psctb.utils.misc._misc.html_table(matrix_or_array_like, float_fmt=None, raw=False, first_row_headers=False, caption=None, style=None, formatter=None)[source]¶ Constructs an html compatible table from 2D list, numpy array or sympy matrix.
Parameters: - matrix_or_array_like : list of lists or array or matrix
A compatible object to be converted to an html table
- float_fmt : str, optional (Default
The formatter string for numbers. This formatter will be applied to all numbers. This optional argument is only used when the argument formatter is None. Useful for simple tables where different types of formatting is not needed.
- raw : boolean, optional (Default
If True a raw html string will be returned, otherwise an IPython HTML object will be returned.
- first_row_headers : boolean, optional (Default
If True elements in the fist row in matrix_or_array_like will be considered as part of a header and will get the <th></th> tag, otherwise there will be no header.
- caption : str, optional (Default
An optional caption for the table.
- style : str, optional (Default
An optional html table style
- formatter: function, optional (Default : None)
An optional formatter function. If none float_fmt will be used to format numbers.
Returns: - str
A string containing an html table.
- OR
- HTML
An IPython notebook HTML object.
See also
-
psctb.utils.misc._misc.print_f(message, status)[source]¶ Prints a message if status is True Parameters ———- message : object
Any object with a __str__ method.status : bool
-
psctb.utils.misc._misc.stringify(symbol_or_list)[source]¶ Returns a list of strings from a list of sympy.Symbol objects or a string from a sympy.Symbol.
Parameters: - symbol_or_list : sympy.Symbol or list of sympy.Symbol.
Returns: - str or list of str
A str or list of str representation of the sympy.Symbol or list of sympy.Symbol.
Examples
>>> import sympy >>> symbol_list = sympy.sympify(['a','c','d']) >>> a = stringify(symbol_list[0]) >>> a 'a' >>> type(a) <type 'str>' >>> str_list = stringify(symbol_list) >>> str_list ['a', 'b', 'c'] >>> type(str_list[0]) <type 'str>'
-
psctb.utils.misc._misc.is_iterable(obj)[source]¶ Returns True if an object is iterable and False if it is not.
This function makes the assumtion that any iterable object can be cast as an iterator using the build-in function iter. This might not be the case, but works within the context of PySCeSToolbox.
Parameters: - obj : object
Any object that might or might not be iterable.
Returns: - bool
A boolean indicating if ob is iterable.
-
psctb.utils.misc._misc.scanner_range_setup(scan_range)[source]¶ From a range of numbers, returns its start point, end point, number of points and if it is a log range.
The assumption is made that only log or linear ranges are valid inputs, thus lists of random numbers would likely be classified as logarithmic.
Parameters: - scan_range : iterable
Any iterable object containing a range of numbers. Most probably numpy.ndarray.
Returns: - start : number
A number indicating the start point of the scan range.
- end: number
A number indicating the end point of the scan range.
- scan_points: number
A number indicating the number of scan point in the scan range
- is_log_range: bool
A boolean indicating whether the scan range has a logarithmic scale or not.
-
psctb.utils.misc._misc.is_linear(scan_range)[source]¶ For any 1-demensional data structure containing numbers return True if the numbers follows a linear sequence.
Within the context of PySCeSToolbox this function will be called on either a linear range or a log range. Thus, while not indicative of log ranges, this is what a False return value indicates in this software.
Parameters: - scan_range : iterable
Any iterable object containing a range of numbers.
Returns: - bool
A boolean indicating if scan_range is a linear sequence of numbers.
-
psctb.utils.misc._misc.column_multiply(arr)[source]¶ For any 2d array returns a column vector with the product of the columns of each row.
Parameters: - arr : numpy.ndarray
Returns: - numpy.ndarray
A ndarray (column vector) with the products of columns of each row of arr as values
Examples
>>> arr = np.arrange(10).reshape(5,2) >>> arr array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) >>> column_multiply(arr) array([[ 0.], [ 6.], [ 20.], [ 42.], [ 72.]])
-
psctb.utils.misc._misc.unix_to_windows_path(path_to_convert, drive_letter='C')[source]¶ For a string representing a POSIX compatible path (usually starting with either ‘~’ or ‘/’), returns a string representing an equivalent Windows compatible path together with a drive letter.
Parameters: - path_to_convert : string
A string representing a POSIX path
- drive_letter : string (Default
A single character string representing the desired drive letter
Returns: - string
A string representing a Windows compatible path.