Shortcuts

tomopt package

Subpackages

Submodules

tomopt.core module

tomopt.utils module

tomopt.utils.class_to_x0preds(array, id2x0)[source]

Converts array of classes to X0 predictions using the map defined in id2x0

Parameters:
  • array (ndarray) – array of integer class IDs

  • id2x0 (Dict[int, float]) – map of class IDs to X0 float values

Return type:

ndarray

Returns:

New array of X0 values

tomopt.utils.jacobian(y, x, create_graph=False, allow_unused=True)[source]

Computes the Jacobian (dy/dx) of y with respect to variables x. x and y can have multiple elements. If y has multiple elements then computation is vectorised via vmap.

Parameters:
  • y (Tensor) – tensor to be differentiated

  • x (Tensor) – dependent variables

  • create_graph (bool) – If True, graph of the derivative will be constructed, allowing to compute higher order derivative products. Default: False.

  • allow_unused (bool) – If False, specifying inputs that were not used when computing outputs (and therefore their grad is always

Return type:

Tensor

Returns:

dy/dx tensor of shape y.shape+x.shape

tomopt.utils.x0_from_mixture(x0s, densities, weight_fracs=None, volume_fracs=None)[source]

Computes the X0 of a mixture of (non-chemically bonded) materials, Based on https://cds.cern.ch/record/1279627/files/PH-EP-Tech-Note-2010-013.pdf

Parameters:
  • x0s (Union[ndarray, List[float]]) – X0 values of the materials in the mixture in metres

  • densities (Union[ndarray, List[float]]) – densities of the materials in the mixture kg/m^3

  • weight_fracs (Union[ndarray, List[float], None]) – the relative amounts of each material by weight

  • volume_fracs (Union[ndarray, List[float], None]) – the relative amounts of each material by volume

Returns:

The X0 of the defined mixture in metres, “density”: The density in kg/m^3 of the defined mixture}

Return type:

{“X0”

tomopt.utils.x0targs_to_classtargs(array, x02id)[source]

Converts array of float X0 targets to integer class IDs using the map defined in x02id.

Warning

To account for floating point precision, X0 values are mapped to the integer class IDs which are closest to X0 keys defined in the map. This means that the method cannot detect missing X0 values from x02id; X0s will always be mapped to a class ID, even if the material isn’t defined in the map

Warning

The input array is modified in-place

Parameters:
  • array (ndarray) – array of X0 values

  • x02id (Dict[float, int]) – map of X0 float values to class IDs

Return type:

ndarray

Returns:

Array of integer class IDs

tomopt.version module

Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.

Docs

Access comprehensive developer and user documentation for TomOpt

View Docs

Tutorials

Get tutorials for beginner and advanced researchers demonstrating many of the features of TomOpt

View Tutorials