How to get tally results frin statepoint file

Hello,

I am a little confused about how create a python script to extract tally values from statepoint file to plot using matplotlib.plot.

I run a very simple case (see attached file: 14 MeV neutron isotropic point source at the centre of a water sphere 1 m diameter, to calculate neutron spectrum between 1 meV and 100 MeV using 54 log-spaced bins).
The results in tallies.out are ok and, as I can see using HDFView, seems to be also in statepoint.100.h5 (also attached: energy bins in /tallies/filters/filter 1/bins ; num of bins in /tallies/filters/filter 1/n_nbins ; and results in /tallies/tally 1/results) but:

How can I get energy bins and flux values in two arrays from the statepoint file (after having opened with sp = openmc.StatePoint(‘statepoint.100.h5’)?

Thank you!

test.py (1.2 KB)
statepoint.100.h5 (18.4 KB)

I have a few examples that are quite close to this question. The only difference is that my example makes use of the inbuilt energy structures. Perhaps we can add your group structure to the inbuilt options. Either way this is example gets the spectra flux values and energy bins from the statepoint and also does some nice plotting with matplotlib

Thank you very much. Following one of your examples, I think I can use something like:
results = openmc.StatePoint(‘statepoint.100.h5’)
cell_tally = results.get_tally(name=‘neutron spectrum’)
flux = cell_tally.mean.flatten()

to get an array of flux values but, is it possible to get the array of E binning energies also from the statefile to plot the spectrum as plt.plot(E,flux)?

Yes, I can’t run this to check but from memory it is something like this

e=cell_tally.find_filter(openmc.EnergyFilter).bins

Thank you very much!
One more (and last) question: can it be obtained separately the flux spectra en different cells (eg. cell1, cell2, cell3) from the statepoint file created with:
tallies_file = openmc.Tallies()
energy_filter = openmc.EnergyFilter(numpy.logspace(-3,8,num = 54))
cell_filter = openmc.CellFilter([cell1, cell2, cell3])
tally1 = openmc.Tally()
tally1.name = ‘neutron spectrum’
tally1.filters = [cell_filter, energy_filter]
tally1.scores = [‘flux’]
tallies_file.append(tally1)
tallies_file.export_to_xml()