Problem with reading current tallies

Hi there,

I’m new to OpenMC and have been struggling with tallying currents.

The filter i build seems to be working fine, but trying to read the results from the tally seems to be impossible with pandas.

This is even true for the example notebook on https://docs.openmc.org/en/stable/examples/mdgxs-part-ii.html
When trying it, the line “current_tally.get_pandas_dataframe()” will throw an error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-19-81578235da85> in <module>
----> 1 current_tally.get_pandas_dataframe()

~/anaconda3/envs/openmc/lib/python3.7/site-packages/openmc/tallies.py in get_pandas_dataframe(self, filters, nuclides, scores, derivative, paths, float_format)
   1530             for f, stride in zip(self.filters, self.filter_strides):
   1531                 filter_df = f.get_pandas_dataframe(
-> 1532                     data_size, stride, paths=paths)
   1533                 df = pd.concat([df, filter_df], axis=1)
   1534 

~/anaconda3/envs/openmc/lib/python3.7/site-packages/openmc/filter.py in get_pandas_dataframe(self, data_size, stride, **kwargs)
    841 
    842         # Initialize a Pandas DataFrame from the mesh dictionary
--> 843         df = pd.concat([df, pd.DataFrame(filter_dict)])
    844 
    845         return df

~/anaconda3/envs/openmc/lib/python3.7/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    390                                  dtype=dtype, copy=copy)
    391         elif isinstance(data, dict):
--> 392             mgr = init_dict(data, index, columns, dtype=dtype)
    393         elif isinstance(data, ma.MaskedArray):
    394             import numpy.ma.mrecords as mrecords

~/anaconda3/envs/openmc/lib/python3.7/site-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype)
    210         arrays = [data[k] for k in keys]
    211 
--> 212     return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    213 
    214 

~/anaconda3/envs/openmc/lib/python3.7/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype)
     49     # figure out the index, if necessary
     50     if index is None:
---> 51         index = extract_index(arrays)
     52     else:
     53         index = ensure_index(index)

~/anaconda3/envs/openmc/lib/python3.7/site-packages/pandas/core/internals/construction.py in extract_index(data)
    315             lengths = list(set(raw_lengths))
    316             if len(lengths) > 1:
--> 317                 raise ValueError('arrays must all be same length')
    318 
    319             if have_dicts:

ValueError: arrays must all be same length

So far, I have not figured out another way to get the data I need from the tally.

Thanks for any help!

Hi Simon,

I tried running that notebook using the ‘develop’ branch of OpenMC and did run into a problem. However, it seems to be unrelated to what you are seeing. The only fix I needed to make was to change MeshFilter to MeshSurfaceFilter. After that, the remainder of the notebook worked successfully, including getting data out of the pandas dataframe. Depending on what version of OpenMC you are using, you might want to look at the latest documentation rather than the stable version. Let us know if you’re still unable to figure things out.

Best regards,
Paul

Hi Paul,

I am using the stable version from the conda-forge repository. I have looked at the development branch, but it seems I’d have to adapt my script and generate new cross section files (3.0 is expected, best I could find ready for download was 2.0), which I haven’t had the time for so far.

At the moment, I am reading the tally data without the inbuilt pandas function. The data is a bit weird, as it is padded with a lot of extra zeros (always eight times the number of values I am expecting). Still, I can just collect that data via tally.get_reshaped_data and sort it myself.
(tally.get_pandas_dataframe() works for a [1,1,1] mesh, so looking at that result I was able to figure out which current is which).

Thanks for the help,
Simon

Hi Simon,

Glad to hear you more or less got things figured out. I’ve actually just updated the pre-built cross section libraries on https://openmc.org/ to version 3.0, so they should now be usable with the develop branch.

Best,
Paul

Hi Simon,
I’m looking for help.
I have run the example, (https://nbviewer.org/github/openmc-dev/openmc-notebooks/tree/main/tally-arithmetic.ipynb), but no dataframe were generated.
I have not figured out another way to get the data I need from the tally.
Thanks for any help!

Hello @wzrone
my problem report was from a long time ago. I think the function works as expected now, but I cannot verify because that script is too old now and would need many updates.

The example you posted works as expected in my current setup (OpenMC 0.13.3 from conda-forge). Maybe you are missing dependencies? In any case, you should get some error message.

Thanks for your answer, I have solved the problem.