utils Package

This is the pyNastran.utils.rst file.

dev Module

pyNastran.utils.dev.get_files_of_type(dirname, extension='.txt', max_size=100.0, limit_file='no_dig.txt')[source]

Gets the list of all the files with a given extension in the specified directory

Parameters:
dirname : str

the directory name

extension : str; default=’.txt’

list of filetypes to get

max_size : float; default=100.0

size in MB for max file size

limit_file : str; default=no_dig.txt

the presence of this file indicates no folder digging should be done on this folder

Returns:
files : List[str]

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 or numpy array in an abbreviated format. Supported element types: None, string, numbers. Useful for debugging.

Parameters:
lst : list / numpy array

the value to print

Returns:
msg : str

the clean string representation of the object

docopt_types Module

pyNastran.utils.docopt_types.docopt_types(doc, argv=None, help=True, version=None, options_first=False, type_defaults=None)[source]

docopt creates your command-line interface based on its description that you pass as doc. Such description can contain –options, <positional-argument>, commands, which could be [optional], (required), (mutually | exclusive) or repeated…

Parameters:
doc : str

Description of your command-line interface.

argv : list of str, optional

Argument vector to be parsed. sys.argv[1:] is used if not provided.

help : bool (default: True)

Set to False to disable automatic help on -h or –help options.

version : any object

If passed, the object will be printed if –version is in argv.

options_first : bool (default: False)

Set to True to require options preceed positional arguments, i.e. to forbid options and positional arguments intermix.

type_defaults : dict (default:None)

key : name of argument value : type, default

Returns:
args : dict

A dictionary, where keys are names of command-line elements such as e.g. “–verbose” and “<path>”, and values are the parsed values of those elements.

Notes

Examples

>>> from docopt import docopt
>>> doc = '''
Usage:
    my_program tcp <host> <port> [--timeout=<seconds>]
    my_program serial <port> [--baud=<n>] [--timeout=<seconds>]
    my_program (-h | --help | --version)
Options:
-h, --help Show this screen and exit.
--baud=<n> Baudrate [default: 9600]

‘’’ >>> argv = [‘tcp’, ‘127.0.0.1’, ‘80’, ‘–timeout’, ‘30’] >>> docopt(doc, argv) {‘–baud’: ‘9600’,

‘–help’: False, ‘–timeout’: ‘30’, ‘–version’: False, ‘<host>’: ‘127.0.0.1’, ‘<port>’: ‘80’, ‘serial’: False, ‘tcp’: True}

#:mod:gui_io Module #——————– # #.. inheritance-diagram:: pyNastran.utils.gui_io # #.. automodule:: pyNastran.utils.gui_io # :members: # :undoc-members: # :show-inheritance:

mathematics Module

Various mathematical functions are defined in this file. This includes:
  • gauss(n)
  • get_abs_index(data, axis=1)
  • get_abs_max(min_values, max_values)
  • get_max_index(data, axis=1)
  • get_min_index(data, axis=1)
  • integrate_positive_unit_line(x, y, min_value=0.)
  • integrate_unit_line(x, y)
  • is_float_ranged(a, x, b)
  • is_list_ranged(a, List, b)
  • list_print(list_a, tol=1e-8, float_fmt=’%-3.2g’, zero_fmt=’ 0’)
  • print_annotated_matrix(A, row_names=None, col_names=None, tol=1e-8)
  • print_matrix(A, tol=1e-8)
  • reduce_matrix(matrix_a, nids)
  • roundup(value, round_increment=100)
  • solve_tridag(A, D)
  • unique2d(a)

All beams are LineProperty objects. Multi-segment beams are IntegratedLineProperty objects.

pyNastran.utils.mathematics.Area(a, b)
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.get_abs_index(data, axis=1)[source]

Gets the maximum absolute value of a 2D matrix along an axis

Examples

>>> data = [
        [4.0, 2.2, 3.0, 5.0, 2.2]  # subcase 1
        [4.1, 2.1, 3.1, 5.1, 2.1], # subcase 2
    ]
>>> max_values, index = get_min_index(data, axis=1)
>>> out
[4.1, 2.2, 3.1, 5.1, 2.2]
>>> index
[1, 0, 1, 1, 0]
pyNastran.utils.mathematics.get_abs_max(min_values, max_values, dtype='float32')[source]

Get return the value with the greatest magnitude, preserving sign.

pyNastran.utils.mathematics.get_max_index(data, axis=1)[source]

Gets the maximum values of a 2D matrix along an axis

Examples

>>> data = [
        [4.0, 2.2, 3.0, 5.0, 2.2]  # subcase 1
        [4.1, 2.1, 3.1, 5.1, 2.1], # subcase 2
    ]
>>> max_values, index = get_max_index(data, axis=1)
>>> out
[4.1, 2.2, 3.1, 5.1, 2.2]
>>> index
[1, 0, 1, 1, 0]
pyNastran.utils.mathematics.get_min_index(data, axis=1)[source]

Gets the minimum values of a 2D matrix along an axis

Examples

>>> data = [
        [4.0, 2.2, 3.0, 5.0, 2.2]  # subcase 1
        [4.1, 2.1, 3.1, 5.1, 2.1], # subcase 2
    ]
>>> min_values, index = get_min_index(data, axis=1)
>>> out
[4.0, 2.1, 3.0, 5.0, 2.1]
>>> index
[0, 1, 0, 0, 1]
pyNastran.utils.mathematics.integrate_positive_unit_line(x, y, min_value=0.0)[source]

Integrates a line of length 1.0 by linear interpolation

Parameters:
x : List[float]

the independent variable

y : List[float]

the dependent variable

min_value : float; default=0.0

???

Returns:
integrated_value : float

the area under the curve

pyNastran.utils.mathematics.integrate_unit_line(x, y)[source]

Integrates a line of length 1.0 by linear interpolation

Parameters:
x : List[float]

the independent variable

y : List[float]

the dependent variable

Returns:
integrated_value : float

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 : float

the lower bound value (inclusive)

x : List[float, …]

the search values

b: float

the upper bound value (inclusive)

Returns:
is_ranged : bool

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 : float

the lower bound value (inclusive)

x : List[float, …]

the search values

b: float

the upper bound value (inclusive)

Returns:
is_ranged : bool

True/False

pyNastran.utils.mathematics.list_print(list_a, tol=1e-08, float_fmt='%-3.2g', zero_fmt=' 0')[source]

prints a list / numpy array in a readable format

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

pyNastran.utils.mathematics.print_matrix(A, tol=1e-08)[source]

prints a 2d matrix in a readable format

pyNastran.utils.mathematics.reduce_matrix(matrix_a, nids)[source]

takes a list of ids and removes those rows and cols

pyNastran.utils.mathematics.roundup(value, round_increment=100)[source]

Rounds up to the next N.

Parameters:
value : int

the value to round up

round_increment : int

the increment to round by

.. python
>>> 100 = roundup(10)
>>> 200 = roundup(105)
>>> 300 = roundup(200)
>>> 1000 = roundup(200, 1000)
>>> 2000 = roundup(1000, 1000)
>>> 2000 = roundup(1001, 1000)
.. note :: this function is used to ensure that renumbering is more

obvious when testing

nastran_utils Module

pyNastran.utils.nastran_utils.run_nastran(bdf_filename, nastran_cmd='nastran', keywords=None, run=True, run_in_bdf_dir=True)[source]

Call a nastran subprocess with the given filename

Parameters:
bdf_filename : string

Filename of the Nastran .bdf file

keywords : str/dict/list of strings, optional

Default keywords are ‘scr=yes’, ‘bat=no’, ‘old=no’, and ‘news=no’

run : bool; default=True

let’s you disable actually running Nastran to test out code/get the call arguments

run_in_local_dir : bool; default=True

True : output (e.g., *.f06) will go to the current working directory (default) False : outputs (e.g., *.f06) will go to the input BDF directory

Returns:
return_code : int

the nastran flag

cmd_args : List[str]

the nastran commands that go into subprocess

numpy_utils Module

Interface to various numpy utilities

__init__ Module

defines:
  • print_bad_path(path)
  • object_attributes(obj, mode=’public’, keys_to_skip=None)
  • object_methods(obj, mode=’public’, keys_to_skip=None)
pyNastran.utils.__init__.b(string)[source]

reimplementation of six.b(…) to work in Python 2

pyNastran.utils.__init__.check_path(filename, name='file')[source]
pyNastran.utils.__init__.int_version(name, version)[source]

splits the version into a tuple of integers

pyNastran.utils.__init__.ipython_info()[source]

determines if iPython/Jupyter notebook is running

pyNastran.utils.__init__.is_binary_file(filename)[source]

Return true if the given filename is binary.

Parameters:
filename : str

the filename to test

Returns:
binary_flag : bool

True if filename is a binary file (contains null byte) and False otherwise.

raises:IOError if the file cannot be opened. ..
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__.is_file_obj(filename)[source]

does this object behave like a file object?

pyNastran.utils.__init__.object_attributes(obj, mode='public', keys_to_skip=None, filter_properties=False)[source]

List the names of attributes of a class as strings. Returns public attributes as default.

Parameters:
obj : instance

the object for checking

mode : str

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

keys_to_skip : List[str]; default=None -> []

names to not consider to avoid deprecation warnings

filter_properties: bool: default=False

filters the @property objects

Returns:
attribute_names : List[str]

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', keys_to_skip=None)[source]

List the names of methods of a class as strings. Returns public methods as default.

Parameters:
obj : instance

the object for checking

mode : str

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

keys_to_skip : List[str]; default=None -> []

names to not consider to avoid deprecation warnings

Returns:
method : List[str]

sorted list of the names of methods of a given type or None if the mode is wrong

pyNastran.utils.__init__.object_stats(obj, mode='public', keys_to_skip=None, filter_properties=False)[source]

Prints out an easy to read summary of the object

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 : str

path to check

Returns:
msg : str

string with informations whether access to parts of the path is possible

pyNastran.utils.__init__.remove_files(filenames)[source]

remvoes a series of files; quietly continues if the file can’t be removed

pyNastran.utils.__init__.str_version(version)[source]

converts a tuple of intergers to a version number