ReporterReader
mooseutils.ReporterReader
mooseutils.ReporterReader(file)
A Reader for MOOSE Reporter data.
Args:
file[str]: JSON file containing reporter data, can be blob pattern if there is one file per timestep.
MOOSE outputs Reporter data in two different ways: Every timestep in a single file or separate files for each timestep, using the timestep as a prefix. For example: file_000.json, file_001.json, etc.
Therefore, a pattern acceptable for use with the python glob package may be supplied. For the above files, "file_*.json" should be supplied.
This object manages the loading and unloading of data and should always be in a valid state, regardless of the existence of a file. It will also append new data and remove old/deleted data on subsequent calls to "update()".
ReporterReader uses tuples as keys for indexing values. Here is an example usage:
data = mooseutils.ReporterReader('file.json')
if ('object_name', 'value_name') in data:
print('value_name in object object_name was found!')
value = data[('object_name', 'value_name')]
else:
print('value_name in object object_name was NOT found!')
clear()
Remove all data.
data
Get the raw data from reading the JSON file(s)
filename
The file name inputted when constructing the object
info(key=None)
Return a information within json file.
Args:
key[None|str|tuple(str, str)]: The information to return. Can be:
None for system information
object name for reporter object information
(object name, value name) for reporter value information
data = ReporterReader('file.json')
print('Data created at ' + data.info()['executable_time'])
print(obj_name + ' is a ' + data.info(obj_name)['type'] + ' object.')
print(val_name + ' from ' + obj_name + ' is of C++ type ' + data.info((obj_name, val_name))['type'])
numParts()
Returns the number of parts available
partFilename(part)
Gets the filename assocated with the given part
Args:
part[int]: The part
repr()
Return components for building script.
Returns:
(output, imports) The necessary script and include statements to re-create data load.
times()
Returns the list of available time indices contained in the data.
update(time=None, part=0)
Update data by reading/re-reading files.
Args:
time[float]: The time at which the data should be returned.
part[int]: The part of which the data should be returned.
data = ReporterReader('file.json')
df = dict(time=[], object_name=[], value_name=[], value=[])
for time in data.times():
data.update(time)
for var in data.variables():
df['time'].append(time)
df['object_name'].append(var[0])
df['value_name'].append(var[1])
df['value'].append(data[var])
variables()
Return a list of reporter names as tuples listed in the reader.
data = ReporterReader('file.json')
for var in data.variables():
print('Found value with object name "{}" and value name "{}"'.format(var[0], var[1]))