Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/openmc/tallies.py", line 2363, in get_slice
File "build/bdist.linux-x86_64/egg/openmc/tallies.py", line 1084, in get_values
File "build/bdist.linux-x86_64/egg/openmc/tallies.py", line 937, in get_filter_indices
File "build/bdist.linux-x86_64/egg/openmc/tallies.py", line 780, in get_filter_index
File "build/bdist.linux-x86_64/egg/openmc/filter.py", line 389, in get_bin_index
TypeError: 'int' object has no attribute '__getitem__'
Is it my mistake or is it a mistake in OpenMC ? (I use OpenMC v.0.7.1)
Thanks for bringing this up - the “Tally.get_slice(…)” routine should work for this use case, but the documentation is not quite correct. I will submit a patch to our code repository shortly to correct this.
I believe the only issue is that you must put the filter bins as a “tuple of tuples” which is not correctly documented. Each tuple corresponds to all of the bins to slice for the corresponding filter in the “filters” parameter list. I recognize that this can be confusing and appears a bit clunky, but it is intended to allow one to slice a tally across multiple filters with a single function call.
For example, if one could simultaneously slice off a tally for cell filter bins 1 and 2 and energy filter bins (0, 0.625e-6) and (1e-3, 20.) with the following code:
Yes there is a lot more overhead involved with the “slice” method than a direct access into the underlying NumPy array. Tally slicing is useful if you wish to encapsulate the sliced data within a Tally object so that you can easily index the data by filter and/or nuclide and/or score which is not as easy to do with a direct access. In addition, you can use any of Tally class’ method with a sliced tally (pandas dataframes, tally arithmetic, etc.). But if you are concerned with performance then I recommend using direct access. Also, we can likely can greatly improve the performance of the Tally class methods -including “slice” - with further development, but these are such new features that we’ve had little time to do performance optimizations.