pyNastran/utils¶
This is the pyNastran.utils.rst file.
gui_choices
Module¶
gui_io
Module¶
-
pyNastran.utils.gui_io.
load_file_dialog
(Title, wx_wildcard, qt_wildcard, dirname='')[source]¶ creates a load file dialog in wx or PyQt4/PySide
log
Module¶
-
class
pyNastran.utils.log.
SimpleLogger
(level='debug', log_func=<function stderr_logging>)[source]¶ Bases:
object
Simple logger object. In future might be changed to use Python logging module. Two levels are supported: ‘debug’ and ‘info’. Info level discards debug messages, ‘debug’ level displays all messages.
Note
Logging module is currently not supported because I don’t know how to repoint the log file if the program is called a second time. Poor logging can result in:
- double logging to a single file
- all longging going to one file
This is really only an issue when calling logging multiple times, such as in an optimization loop or testing.
Methods
Parameters: - level – level of logging: ‘info’ or ‘debug’
- log_func – funtion that will be used to print log. It should take one argument: string that is produces by a logger. Default: print messages to stderr using @see stderr_logging function.
Methods
-
msg_typ
(typ, msg)[source]¶ Log message of a given type :param typ: type of a message (e.g. INFO) :param msg: message to be logged
-
pyNastran.utils.log.
get_logger
(log=None, level='debug')[source]¶ This function is useful as it will instantiate a simpleLogger object if log=None. :param log: a logger object or None :param level: level of logging: ‘info’ or ‘debug’
-
pyNastran.utils.log.
get_logger2
(log=None, debug=True)[source]¶ This function is useful as it will instantiate a SimpleLogger object if log=None. :param log: a python logging module object;
if log is set, debug is ignored and uses the settings the logging object hasParameters: debug – used to set the logger if no logger is passed in True: logs debug/info/error messages False: logs info/error messages None: logs error messages Returns log: log or a SimpleLogger
mathematics
Module¶
-
pyNastran.utils.mathematics.
Area
(a, b)¶
-
pyNastran.utils.mathematics.
augmented_identity
(A)[source]¶ Creates an Identity Matrix augmented with zeros. The location of the extra zeros depends on A.
[ 1, 0, 0, 0 ] [ 0, 1, 0, 0 ] [ 0, 0, 1, 0 ]
-
pyNastran.utils.mathematics.
build_spline
(x, y)[source]¶ Builds a cubic spline or 1st order spline if there are less than 3 terms :param x: the independent variable :param y: the dependent variable
Returns splrep: a splrep object (linear or cubic spline depending on the length of x) Note
a 1st order spline is the same as linear interpolation
-
pyNastran.utils.mathematics.
centroid_triangle
(n1, n2, n3)[source]¶ Calculates the centroid of a triangle
Parameters: - n1 – NDARRAY of node 1
- n2 – NDARRAY of node 2
- n3 – NDARRAY of node 3
-
pyNastran.utils.mathematics.
gauss
(n)[source]¶ A quadrature rule: an approximation of the definite integral of a function. Currently implementation supports up to 5 quadrature points.
Function returns following values depending on n (number of points):
- n = 1:
- f$ 0 f$ –> f$ 2 f$
- n = 2:
- f$ pm 1/sqrt{3} f$ –> f$ 1 f$
- n = 3
- f$ 0 f$ –> f$ 8/9 f$
- f$ pmsqrt{3/5} f$ –> f$ 5/9 f$
- n = 4:
- f$ pmsqrt{left( 3 - 2sqrt{6/5} right)/7} f$ –> f$ (18+sqrt{30})/36 f$
- f$ pmsqrt{left( 3 + 2sqrt{6/5} right)/7} f$ –> f$ (18-sqrt{30})/36 f$
- n = 5:
- f$ 0 f$ –> f$ 128/225 f$
- f$ pmfrac{1}{3}sqrt{5-2sqrt{10/7}} f$ –> f$ (322+13sqrt{70})/900 f$
- f$ pmfrac{1}{3}sqrt{5+2sqrt{10/7}} f$ –> f$ (322-13sqrt{70})/900 f$
Parameters: n – Number of quadrature points Returns lists: points and corresponding weights, sorted by points value
-
pyNastran.utils.mathematics.
integrate_line
(x, y)[source]¶ Integrates a line of length 1.0
Parameters: - x – the independent variable
- y – the dependent variable
Returns integrated_value: the area under the curve
-
pyNastran.utils.mathematics.
integrate_positive_line
(x, y, minValue=0.0)[source]¶ Integrates a line of length 1.0
Parameters: - x – the independent variable
- y – the dependent variable
Returns integrated_value: the area under the curve
-
pyNastran.utils.mathematics.
is_float_ranged
(a, x, b)[source]¶ Returns true if a<= x <= b or a-x < 0 < b-x.
Parameters: - a – the lower bound value (inclusive)
- x – the search value
- b – the upper bound value (inclusive)
Returns is_ranged: True/False
-
pyNastran.utils.mathematics.
is_list_ranged
(a, List, b)[source]¶ Returns true if a<= x <= b or a-x < 0 < b-x
Parameters: - a – the lower bound value (inclusive)
- x – the search values
- b – the upper bound value (inclusive)
Returns is_ranged: True/False
-
pyNastran.utils.mathematics.
list_print
(listA, tol=1e-08, float_fmt='%-3.2g', zero_fmt=' 0')[source]¶
-
pyNastran.utils.mathematics.
print_annotated_matrix
(A, row_names=None, col_names=None, tol=1e-08)[source]¶ Takes a list/dictionary and annotates the row number with that value indicies go from 0 to N
dev
Module¶
-
pyNastran.utils.dev.
get_files_of_type
(dirname, extension='.txt', maxSize=100.0)[source]¶ Gets the list of all the files with a given extension in the specified directory
Parameters: - dirname – the directory name
- extension – list of filetypes to get (default=’.txt’)
- maxSize – size in MB for max file size
Returns: list of all the files with a given extension in the specified directory
-
pyNastran.utils.dev.
list_print
(lst, float_fmt='%-4.2f')[source]¶ Prints a list, numpy array, or numpy matrix in an abbreviated format. Supported element types: None, string, numbers. Useful for debugging.
Parameters: lst – list, numpy array or numpy matrix Returns: the clean string representation of the object
__init__
Module¶
-
pyNastran.utils.__init__.
is_binary_file
(filename)[source]¶ Return true if the given filename is binary.
Raises: IOError if the file cannot be opened. Returns: True if filename is a binary file (contains null byte) and False otherwise. Based on the idea (.. seealso:: http://bytes.com/topic/python/answers/21222-determine-file-type-binary-text) that file is binary if it contains null.
Warning
this may not work for unicode.
-
pyNastran.utils.__init__.
object_attributes
(obj, mode='public')[source]¶ List the names of attributes of a class as strings. Returns public attributes as default.
Parameters: - obj – the object for checking
- mode – defines what kind of attributes will be listed * “public” - names that do not begin with underscore * “private” - names that begin with single underscore * “both” - private and public * “all” - all attributes that are defined for the object
Returns: sorted list of the names of attributes of a given type or None if the mode is wrong
-
pyNastran.utils.__init__.
object_methods
(obj, mode='public')[source]¶ List the names of methods of a class as strings. Returns public methods as default.
Parameters: - obj – the object for checking
- mode – defines what kind of methods will be listed * “public” - names that do not begin with underscore * “private” - names that begin with single underscore * “both” - private and public * “all” - all methods that are defined for the object
Returns: sorted list of the names of methods of a given type or None if the mode is wrong
-
pyNastran.utils.__init__.
print_bad_path
(path)[source]¶ Prints information about the existence (access possibility) of the parts of the given path. Useful for debugging when the path to a given file is wrong.
Parameters: path – path to check Returns: string with informations whether access to parts of the path is possible