'dict' object has no attribute 'mean'

dear,
all

Does anyone know what happened with this and what should I do?

Thx,
auliyah

I quite like the pandas options for getting OpenMC tallies

results = openmc.StatePoint(openmc_output_filename)
cell_tally = results.get_tally(name=value.name)
cell_tally_df = cell_tally.get_pandas_dataframe()
cell_tally_values = cell_tally_df[“mean”]

For filename that what filename?
And for name?

I get the filename returned from the model run like this, it is normally called some thing like “statepoint.batches.h5” where batches is replaced by the number of batches run in the simulation. Looks like your filename is “statepoint.50.h5”

filename = model.run()

And for name is same with filename or different?

Hi Auliyah,

Sorry I don’t quite understand, if you are able to post your python script I can get it working if that helps.

@Auliyah11 In your original code, the error you are seeing is because sp1.tallies is a dictionary that maps tally IDs (integers) to tally objects. The .mean attribute exists on a tally object, so you need to select a specific tally from sp1.tallies. If you only have one tally defined, you’ll probably need to change you code to:

tally = sp1.tallies[1]
flux = tally.mean.ravel()
print(flux)

The suggestion by @Shimwell is that if you want to look at tally information, there is a method for getting a Pandas dataframe, which presents the tally results in a very readable form. If you wanted to do this, it would look like:

tally = sp1.tallies[1]
dataframe = tally.get_pandas_dataframe()
print(dataframe)