Utility Functions – pyne.utils

This module holds some basic utility functions that are used throughout PyNE. You may find them useful as well!

All functionality may be found in the utils module:

from pyne import utils

Utils API

exception pyne.utils.QAWarning[source]
pyne.utils.block_in_blocks(block1, blocks2, rel_tol=1e-09)[source]

Test whether a block of content in another file (represented as blocks2).

pyne.utils.check_iterable(obj)[source]

Check whether the object is Iterable.

pyne.utils.failure(s)[source]

Formats a fail message for printing. If on a posix system the message will be in color.

pyne.utils.file_almost_same(f1, f2, rel_tol=1e-09)[source]

For some reasones, it’s useful to compare two files that are almost the same. Two files, f1 and f2, the text contents are exactly the same, but there is a small difference in numbers. Such as the difference between ‘some text 9.5’ and ‘some text 9.500000000001’. For example, in PyNE test files, there are some expected file generated by python2, however, the the file generated by python3 may have difference in decimals.

pyne.utils.file_block_almost_same(f1, f2, rel_tol=1e-09)[source]

Some files are seperated into different blocks without specific sequence. Such as the materials definition file: ‘alara_matlib’, the sequence of the materils doesn’t matter. It is useful to compare whether their blocks are almost the same.

pyne.utils.from_barns(xs, units)[source]

Converts a cross section from barns to units.

Parameters
xs :

Cross section value in [barns].

unitsstr

Units flag, eg ‘b’, ‘microbarn’.

Returns
unit_xs :

Cross section value in [units].

pyne.utils.is_float(s)[source]

This function checks whether a string can be converted as a float number.

pyne.utils.line_almost_same(l1, l2, rel_tol=1e-09)[source]

This function is used to compare two lines (read from files). If they are the same, or almost the same (with only slight difference on float numbers), return True. Ohterwise, return False.

pyne.utils.message(s)[source]

Formats a message for printing. If on a posix system the message will be in color.

pyne.utils.remove(path)[source]

Removes a path, or recursively a directory, or does nothing if path is neither a file nor a directory.

pyne.utils.str_almost_same(s1, s2, rel_tol=1e-09)[source]

This function is used to compare two string to check whether they are almost the same. Return True if two strings are exactly the same. Return True if two strings are almost the same with only slight difference of float decimals. Return False if two strings are different.

pyne.utils.str_to_unicode(s)[source]

This function convert a str from binary or unicode to str (unicode). If it is a list of string, convert every element of the list.

pyne.utils.to_barns(xs, units)[source]

Converts a cross section with units to barns.

Parameters
xs :

Cross section value in [units].

unitsstr

Units flag, eg ‘b’, ‘microbarn’.

Returns
barn_xs :

Cross section value in [barns].

pyne.utils.to_sec(input_time, units)[source]

Converts a time with units to seconds.

Parameters
input_timenumber

Time value in [units].

unitsstr

Units flag, eg ‘min’, ‘ms’, ‘days’

Returns
sec_timefloat

Time value in [sec].

pyne.utils.warning(s)[source]

Formats a warning message for printing. If on a posix system the message will be in color.