# How to get tally results frin statepoint file

**URL:** <https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137>\
**Category:** User Support\
**Created:** [April 6, 2024, 10:55am UTC](https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137 "2024-04-06T10:55:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![josem](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/josem/32/4096_2.png) [@josem](https://openmc.discourse.group/u/josem)\
**Post date:** [April 6, 2024, 10:55am UTC](https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137/1 "2024-04-06T10:55:33Z")

</div>

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](https://openmc.discourse.group/uploads/short-url/xOnMVNzt0NwwgaBfYeIMIiga3lp.py) (1.2 KB)  
[statepoint.100.h5](https://openmc.discourse.group/uploads/short-url/3Rq0zIFZ5AvfWVtG8vrix9z7PBk.h5) (18.4 KB)

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [April 6, 2024, 11:18am UTC](https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137/2 "2024-04-06T11:18:09Z")

</div>

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

> **[neutronics-workshop/tasks/task\_07\_CSG\_cell\_tally\_spectra at main ·...](https://github.com/fusion-energy/neutronics-workshop/tree/main/tasks/task_07_CSG_cell_tally_spectra)**
>
> A workshop covering a range of fusion relevant analysis and simulations with OpenMC, DAGMC, Paramak and other open source fusion neutronics tools - fusion-energy/neutronics-workshop

---

<div class="post-metadata">

**Author:** ![josem](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/josem/32/4096_2.png) [@josem](https://openmc.discourse.group/u/josem)\
**Post date:** [April 7, 2024, 12:32pm UTC](https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137/3 "2024-04-07T12:32:11Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [April 7, 2024, 2:26pm UTC](https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137/4 "2024-04-07T14:26:26Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![josem](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/josem/32/4096_2.png) [@josem](https://openmc.discourse.group/u/josem)\
**Post date:** [April 7, 2024, 5:16pm UTC](https://openmc.discourse.group/t/how-to-get-tally-results-frin-statepoint-file/4137/5 "2024-04-07T17:16:03Z")

</div>

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()
