openmc.Filter

class openmc.Filter(type=None, bins=None)[source]

A filter used to constrain a tally to a specific criterion, e.g. only tally events when the particle is in a certain cell and energy range.

Parameters:
  • type (str) – The type of the tally filter. Acceptable values are “universe”, “material”, “cell”, “cellborn”, “surface”, “mesh”, “energy”, “energyout”, “distribcell”, “mu”, “polar”, “azimuthal”, and “delayedgroup”.
  • bins (Integral or Iterable of Integral or Iterable of Real) – The bins for the filter. This takes on different meaning for different filters. See the OpenMC online documentation for more details.
Variables:
  • type (str) – The type of the tally filter
  • bins (Integral or Iterable of Real) – The bins for the filter
  • num_bins (Integral) – The number of filter bins
  • mesh (openmc.Mesh or None) – A Mesh object for ‘mesh’ type filters.
  • stride (Integral) – The number of filter, nuclide and score bins within each of this filter’s bins.
  • distribcell_paths (list of str) – The paths traversed through the CSG tree to reach each distribcell instance (for ‘distribcell’ filters only)
can_merge(other)[source]

Determine if filter can be merged with another.

Parameters:other (openmc.Filter) – Filter to compare with
Returns:Whether the filter can be merged
Return type:bool
get_bin(bin_index)[source]

Returns the filter bin for some filter bin index.

Parameters:bin_index (Integral) – The zero-based index into the filter’s array of bins. The bin index for ‘material’, ‘surface’, ‘cell’, ‘cellborn’, and ‘universe’ filters corresponds to the ID in the filter’s list of bins. For ‘distribcell’ tallies the bin index necessarily can only be zero since only one cell can be tracked per tally. The bin index for ‘energy’ and ‘energyout’ filters corresponds to the energy range of interest in the filter bins of energies. The bin index for ‘mesh’ filters is the index into the flattened array of (x,y) or (x,y,z) mesh cell bins.
Returns:bin – The bin in the Tally data array. The bin for ‘material’, surface’, ‘cell’, ‘cellborn’, ‘universe’ and ‘distribcell’ filters is a 1-tuple of the ID corresponding to the appropriate filter bin. The bin for ‘energy’ and ‘energyout’ filters is a 2-tuple of the lower and upper energies bounding the energy interval for the filter bin. The bin for ‘mesh’ tallies is a 2-tuple or 3-tuple of the x,y or x,y,z mesh cell indices corresponding to the bin in a 2D/3D mesh.
Return type:1-, 2-, or 3-tuple of Real
get_bin_index(filter_bin)[source]

Returns the index in the Filter for some bin.

Parameters:filter_bin (Integral or tuple) – The bin is the integer ID for ‘material’, ‘surface’, ‘cell’, ‘cellborn’, and ‘universe’ Filters. The bin is an integer for the cell instance ID for ‘distribcell’ Filters. The bin is a 2-tuple of floats for ‘energy’ and ‘energyout’ filters corresponding to the energy boundaries of the bin of interest. The bin is an (x,y,z) 3-tuple for ‘mesh’ filters corresponding to the mesh cell interest.
Returns:filter_index – The index in the Tally data array for this filter bin.
Return type:Integral

See also

Filter.get_bin()

get_pandas_dataframe(data_size, distribcell_paths=True)[source]

Builds a Pandas DataFrame for the Filter’s bins.

This method constructs a Pandas DataFrame object for the filter with columns annotated by filter bin information. This is a helper method for Tally.get_pandas_dataframe().

This capability has been tested for Pandas >=0.13.1. However, it is recommended to use v0.16 or newer versions of Pandas since this method uses Pandas’ Multi-index functionality.

Parameters:
  • data_size (Integral) – The total number of bins in the tally corresponding to this filter
  • distribcell_paths (bool, optional) – Construct columns for distribcell tally filters (default is True). The geometric information in the Summary object is embedded into a Multi-index column with a geometric “path” to each distribcell instance. NOTE: This option assumes that all distribcell paths are of the same length and do not have the same universes and cells but different lattice cell indices.
Returns:

A Pandas DataFrame with columns of strings that characterize the filter’s bins. The number of rows in the DataFrame is the same as the total number of bins in the corresponding tally, with the filter bin appropriately tiled to map to the corresponding tally bins.

For ‘cell’, ‘cellborn’, ‘surface’, ‘material’, and ‘universe’ filters, the DataFrame includes a single column with the cell, surface, material or universe ID corresponding to each filter bin.

For ‘distribcell’ filters, the DataFrame either includes:

  1. a single column with the cell instance IDs (without summary info)
  2. separate columns for the cell IDs, universe IDs, and lattice IDs and x,y,z cell indices corresponding to each (distribcell paths).

For ‘energy’ and ‘energyout’ filters, the DataFrame includes one column for the lower energy bound and one column for the upper energy bound for each filter bin.

For ‘mesh’ filters, the DataFrame includes three columns for the x,y,z mesh cell indices corresponding to each filter bin.

Return type:

pandas.DataFrame

Raises:

ImportError – When Pandas is not installed

See also

Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()

is_subset(other)[source]

Determine if another filter is a subset of this filter.

If all of the bins in the other filter are included as bins in this filter, then it is a subset of this filter.

Parameters:other (openmc.Filter) – The filter to query as a subset of this filter
Returns:Whether or not the other filter is a subset of this filter
Return type:bool
merge(other)[source]

Merge this filter with another.

Parameters:other (openmc.Filter) – Filter to merge with
Returns:merged_filter – Filter resulting from the merge
Return type:openmc.Filter