Package documentation

Subpackages

Submodules

t4_geom_convert.Debug module

Useful tools for debugging.

t4_geom_convert.Debug.debug(wrapped)

Prints input and output values of any function it decorates.

t4_geom_convert.conftest module

pytest configuration file.

class t4_geom_convert.conftest.MCNPRunner(path, work_path)

Bases: object

A helper class to run MCNP on a given input file.

run(input_file)

Run MCNP on the given input file.

Parameters:

input_file (str) – absolute path to the input file

Returns:

the paths to the generated output and PTRAC files

Return type:

(pathlib.Path, pathlib.Path)

class t4_geom_convert.conftest.OracleRunner(path, work_path)

Bases: object

A helper class to run the test oracle.

run(t4_o, mcnp_i, mcnp_ptrac, oracle_opts=None)

Run the test oracle on the given files.

Parameters:
  • t4_o (str) – absolute path to the TRIPOLI-4 file to test

  • mcnp_i (str) – absolute path to the MCNP input file

  • mcnp_ptrac (str) – absolute path to the MCNP PTRAC file

Returns:

the number of failed points in the comparison

t4_geom_convert.conftest.check_failed_points(failed_path)

Read the failed_path file and return the number of failed points and the maximum distance for them.

t4_geom_convert.conftest.datadir(tmp_path, request)

Fixture responsible for searching a folder called ‘data’ in the same directory as the test module and, if available, moving all contents to a temporary directory so tests can use them freely.

t4_geom_convert.conftest.foreach_data(*args, **kwargs)

Decorator that parametrizes a test function over files in the data directory for the current tests.

Assume that the following snippet resides in tests/submod/test_submod.py:

@foreach_data('datafile')
def test_something(datafile):
    pass

When pytest imports test_submod.py, it will parametrize the datafile argument to test_something() over all the files present in tests/submod/data/.

If you wish to filter away some of the files, you can use the alternative syntax:

@foreach_data(datafile=lambda path: str(path).endswith('.txt'))
def test_something(datafile):
    pass

Here the argument to the datafile keyword argument is a predicate that must return True if path is to be parametrized over, and False otherwise. Note that the path argument to the lambda is a pathlib.Path object. In this example, pytest will parametrize test_something() only over files whose name ends in '.txt'.

t4_geom_convert.conftest.mcnp(mcnp_path, tmp_path)

Return an instance of the MCNPRunner class.

t4_geom_convert.conftest.mcnp_path(request)

Fixture yielding the path to the MCNP executable specified on the command line.

t4_geom_convert.conftest.oracle(oracle_path, tmp_path)

Return an instance of the OracleRunner class.

t4_geom_convert.conftest.oracle_path(request)

Fixture yielding the path to the oracle executable specified on the command line.

t4_geom_convert.conftest.parse_outside_points(stdout_path)

Parse the file at stdout_path and return the number of points that fall outside the geometry.

t4_geom_convert.main module

t4_geom_convert.main.conversion(args)

Orchestrate the conversion.

t4_geom_convert.main.main()

Main entry point for the CLI tool.

t4_geom_convert.main.parse_args(argv)

Parse the command-line arguments.

Returns:

a namespace containing the parsed arguments.

t4_geom_convert.main.parse_lattice(lattice_list)

Check the arguments to the –lattice option and parse them into a usable form.

The arguments to –lattice (the option may be given multiple times) have the form cell,i_min:i_max[,j_min:j_max[,k_min:k_max]]

>>> opt_lattice = ['200,2:5,0:4', '5902,0:5,0:5,0:5', '10,-4:4']

This function parses the opt_lattice list into a dictionary associating cell numbers to a list of ranges, as tuples:

>>> dic = parse_lattice(opt_lattice)
>>> dic == {200: [(2, 5), (0, 4)],
...         5902: [(0, 5), (0, 5), (0, 5)],
...         10: [(-4, 4)]}
True

The function does some error checking, too:

>>> parse_lattice(['malformed'])
Traceback (most recent call last):
    ...
ValueError: no ranges specified in option 'malformed'
>>> parse_lattice(['three,-1:5'])
Traceback (most recent call last):
    ...
ValueError: cell number 'three' is not an integer in option 'three,-1:5'
>>> parse_lattice(['100,'])
Traceback (most recent call last):
    ...
ValueError: needs exactly 2 colon-separated range bounds in argument '' in option '100,'
>>> parse_lattice(['100,0:4,0:4,0:4,0:4'])
Traceback (most recent call last):
    ...
ValueError: too many ranges specified in option '100,0:4,0:4,0:4,0:4'
>>> parse_lattice(['100,0:6.022e23'])
Traceback (most recent call last):
    ...
ValueError: range bound '6.022e23' is not an integer in option '100,0:6.022e23'
>>> parse_lattice(['100,-6.022e23:0'])
Traceback (most recent call last):
    ...
ValueError: range bound '-6.022e23' is not an integer in option '100,-6.022e23:0'
t4_geom_convert.main.writeHeader(ofile)

Write a short header for the TRIPOLI-4 output file.

Module contents