def testRepr(self):
        """
        Test the 'repr' method for writing scripts is working.
        """

        # Load the files
        self.copyfiles()
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertTrue(data)

        # Get script text
        output, imports = data.repr()

        # Append testing content
        output += ["print(data['y'][6])"]

        # Write the test script
        script = '{}_repr.py'.format(self.__class__.__name__)
        with open(script, 'w') as fid:
            fid.write('\n'.join(imports))
            fid.write('\n'.join(output))

        # Run script
        self.assertTrue(os.path.exists(script))
        out = mooseutils.check_output(['python', script])

        # Test for output
        self.assertIn('4096', out)

        # Remove the script
        os.remove(script)
    def testTimeAccess(self):
        """
        Test that time based data access is working.
        """
        self.copyfiles()
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertTrue(data)

        # Test that newest data is returned
        y = data('y')
        self.assertEqual(y[4], 16)

        # Test that older data can be loaded
        y = data('y', time=3)
        self.assertEqual(y[4], 8)

        # Test that bisect returns value even if time is exactly correct
        y = data('y', time=3.3)
        self.assertEqual(y[4], 8)

        # Test that beyond end returns newest
        y = data('y', time=9999)
        self.assertEqual(y[4], 16)

        # Test time less than beginning returns first
        y = data('y', time=0.5)
        self.assertEqual(y[4], 4)

        # Test that disabling bisect returns empty
        y = data('y', time=3.3, exact=True)
        self.assertTrue(y.empty)
    def testEmptyUpdateRemove(self):
        """
        Test that non-exist file can be supplied, loaded, and removed.
        """

        # Create object w/o data
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertEqual(data._pattern, os.path.basename(self._pattern))
        self.assertEqual(data.filename, None)
        self.assertFalse(data._timedata)
        self.assertFalse(data)

        # Update data
        self.copyfiles()
        data.update()
        self.assertTrue(data._timedata)
        self.assertTrue(data)

        # Check axis organized correctly
        self.assertEqual(data.data.data.shape, (7, 3))
        self.assertEqual(list(data.times()), [1, 3, 7, 13])
        y = data['y']
        self.assertEqual(y[6], 4096)

        # Remove data
        self.tearDown()
        data.update()
        self.assertFalse(data._timedata)
        self.assertFalse(data)
    def testOldData(self):
        """
        Test that old data is not loaded
        """

        # Load the files
        self.copyfiles()
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertTrue(data)
        self.assertEqual(data.data.shape, (3, 6, 3))

        # Make the last file old
        time.sleep(2)  # wait so new files have newer modified times
        mooseutils.touch('vpp_000.csv')
        mooseutils.touch('vpp_001.csv')

        # Update and make certain data structure is smaller
        data.update()
        self.assertTrue(data)
        self.assertEqual(data.data.shape, (2, 6, 3))
        self.assertEqual(list(data.data.keys().values), [1, 3])

        # Test data
        y = data['y']
        self.assertEqual(y[3][4], 8)

        # Touch 3 so that, it should show up then
        time.sleep(1)
        mooseutils.touch('vpp_002.csv')
        data.update()
        self.assertTrue(data)
        self.assertEqual(data.data.shape, (3, 6, 3))
 def testVariables(self):
     """
     Check variable names.
     """
     self.copyfiles()
     data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
     self.assertTrue(data)
     self.assertEqual(data.variables(), ['index (Peacock)', 'x', 'y'])
 def testVariables(self):
     """
     Check variable names.
     """
     self.copyfiles()
     data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
     self.assertTrue(data)
     self.assertIn('x', data.variables())
     self.assertIn('y', data.variables())
Example #7
0
    def create(self):
        """
        Creates the widgets for testing.

        This is done here rather than in setUp to allow for testing of delayed loading.
        """

        self._reader = mooseutils.VectorPostprocessorReader(self._pattern)
        self._data = PostprocessorDataWidget(self._reader)

        # Build the widgets
        self._control, self._widget, self._window = main(self._data)
        self._widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(625, 625))
 def testUpdateCall(self):
     """
     Test that MooseDataFrame is cached
     """
     self.copyfiles()
     data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
     ids0 = [id(f) for f in data._frames.values()]
     data.update()
     ids1 = [id(f) for f in data._frames.values()]
     self.assertEqual(ids0, ids1)
     data.update()
     ids2 = [id(f) for f in data._frames.values()]
     self.assertEqual(ids0, ids2)
    def testBasic(self):
        """
        Test that if a file exists it is loaded w/o error.
        """
        self.copyfiles()

        # Load the data
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertEqual(data._pattern, os.path.basename(self._pattern))
        self.assertEqual(data.filename, 'vpp_005.csv')
        self.assertTrue(data._timedata)
        self.assertTrue(data)

        # Check axis organized correctly
        self.assertEqual(data.data.data.shape, (7, 3))
        self.assertEqual(data.times(), [1, 3, 7, 13])

        # Check data
        y = data['y']
        self.assertEqual(y[6], 4096)
    def testBasicNoTime(self):
        """
        Test that if a file is loaded w/o error (when no time).
        """
        self.copyfiles(copytime=False)

        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertEqual(data._pattern, os.path.basename(self._pattern))
        self.assertEqual(data.filename, 'vpp_005.csv')
        self.assertFalse(data._timedata)
        self.assertTrue(data)

        # Check axis organized correctly
        self.assertEqual(data.data.data.shape, (7, 3))

        # Check that times are loaded
        self.assertEqual(data.times(), [0, 1, 2, 5])

        # Check data
        y = data['y']
        self.assertEqual(y[6], 4096)
    def testRemoveData(self):
        """
        Test that removing a file is handled correctly.
        """

        # Load the files
        self.copyfiles()
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertTrue(data)
        self.assertEqual(data.filename, 'vpp_005.csv')
        self.assertEqual(data.data.data.shape, (7, 3))
        self.assertEqual(data.times(), [1, 3, 7, 13])

        # Remove the middle file
        os.remove('vpp_001.csv')

        # Update and check results
        data.update()
        self.assertTrue(data)
        self.assertEqual(data.filename, 'vpp_005.csv')
        self.assertEqual(data.data.data.shape, (7, 3))
        self.assertEqual(data.times(), [1, 7, 13])
    def testBasic(self):
        """
        Test that if a file exists it is loaded w/o error.
        """
        self.copyfiles()

        # Load the data
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertEqual(data.filename, os.path.basename(self._pattern))
        self.assertTrue(data._timedata)
        self.assertTrue(data)

        # Check axis organized correctly
        self.assertEqual(data.data.shape, (3, 6, 3))

        # Check that times are loaded
        self.assertEqual(list(data.data.keys().values), [1, 3, 7])

        # Check data
        y = data['y']
        self.assertEqual(y[3][4], 8)
        self.assertEqual(y[7][4], 16)
    def testTimeAccess(self):
        """
        Test that time based data access is working.
        """
        self.copyfiles()
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertEqual(data.times(), [1, 3, 7, 13])
        self.assertTrue(data)

        # Test that newest data is returned
        self.assertEqual(data.filename, 'vpp_005.csv')
        y = data['y']
        self.assertEqual(y[6], 4096)

        # Test that older data can be loaded
        data.update(time=3)
        self.assertEqual(data.filename, 'vpp_001.csv')
        y = data['y']
        self.assertEqual(y[5], 10)

        # Test that bisect returns value even if time is exactly correct
        data.update(time=7.3)
        self.assertEqual(data.filename, 'vpp_002.csv')
        y = data['y']
        self.assertEqual(y[5], 25)

        # Test that beyond end returns newest
        data.update(time=9999)
        self.assertEqual(data.filename, 'vpp_005.csv')
        y = data['y']
        self.assertEqual(y[6], 4096)

        # Test time less than beginning returns first
        data.update(time=0.5)
        self.assertEqual(data.filename, 'vpp_000.csv')
        y = data['y']
        self.assertEqual(y[5], 5)
    def testRemoveData(self):
        """
        Test that removing a file is handled correctly.
        """

        # Load the files
        self.copyfiles()
        data = mooseutils.VectorPostprocessorReader('vpp_*.csv')
        self.assertTrue(data)
        self.assertEqual(data.data.shape, (3, 6, 3))

        # Remove the middle file
        os.remove('vpp_001.csv')

        # Update and check results
        data.update()
        self.assertTrue(data)
        self.assertEqual(data.data.shape, (2, 6, 3))
        self.assertEqual(list(data.data.keys().values), [1, 7])

        # Test data
        y = data['y']
        self.assertEqual(y[1][4], 4)
        self.assertEqual(y[7][4], 16)
Example #15
0
    parser.add_argument('--bins', default=None, type=int, help="Number of bins to consider.")
    parser.add_argument('--alpha', default=0.5, type=float, help="Set the bar chart opacity alpha setting.")
    parser.add_argument('--xlabel', default='Value', type=str, help="The X-axis label.")
    parser.add_argument('--ylabel', default='Probability', type=str, help="The X-axis label.")
    parser.add_argument('--uniform', default=None, type=float, nargs=2, help="Show a uniform distribution between a and b (e.g., --uniform 8 10).")
    parser.add_argument('--weibull', default=None, type=float, nargs=2, help="Show a Weibull distribution with given shape and scale parameters (e.g., --uniform 1 5).")
    return parser.parse_args()

if __name__ == '__main__':

    # Command-line options
    opt = command_line_options()
    opt.filename = os.path.abspath(opt.filename)

    # Read data and set the default vector names
    data = mooseutils.VectorPostprocessorReader(opt.filename)
    if not opt.vectors:
        opt.vectors = data.variables()[1:] # 1: ignores peacock index

    # Plot the results
    times = data.times()
    for t in [times[idx] for idx in opt.timesteps]:
        for vec in opt.vectors:
            plt.hist(data[vec][t], bins=opt.bins, normed=True, alpha=opt.alpha,
                     label="{} (t={})".format(vec, t), ec='black')

    # Add distributions
    if opt.uniform:
        loc = opt.uniform[0]
        scale = opt.uniform[1] - loc
        x = np.linspace(loc, loc + scale, 100)
Example #16
0
#!/usr/bin/env python

import pandas
import mooseutils
import matplotlib.pyplot as plt

f1 = plt.figure(1, figsize=(6, 4.5))
ax = plt.gca()
data = mooseutils.VectorPostprocessorReader('csv/out_profiles_*.csv')

t_times = [19.5, 30.5, 41.8, 61.3, 125.0, 194.6]
rh_times = [33.4, 58.4, 66.7, 77.9, 152.8, 194.5]

#T = data('T', time = 0)
#print(T)
#print(data.data.keys().values)

#Plot a line for every output time:
#for time in data.data.data.keys().values:
#  data.data.data[time].plot(ax=ax,x='x',y='T')

#Plot lines for selected interpolated output times:
for t_hr in t_times:
    t = t_hr * 3600
    data.update(time=t)
    data.data.data.plot(ax=ax, x='id', y='T', label=str(t_hr) + ' hr')

plt.xlabel('Radial Position (m)')
plt.ylabel('Temperature ($\degree$C)')

plt.savefig('temp_plot.pdf')
Example #17
0
#!/usr/bin/env python3
#* This file is part of the MOOSE framework
#* https://www.mooseframework.org
#*
#* All rights reserved, see COPYRIGHT for full restrictions
#* https://github.com/idaholab/moose/blob/master/COPYRIGHT
#*
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html

# Plotting the results of line.i, strip.i, rectangle_w_line.i, rectangle_w_strip.i, block_w_bar.i, and block_w_line.i

import mooseutils
import matplotlib.pyplot as plt

data_line = mooseutils.VectorPostprocessorReader('csv/line_center_*.csv')
data_strip = mooseutils.VectorPostprocessorReader('csv/strip_center_*.csv')

data_rectangle_w_line_x_025 = mooseutils.VectorPostprocessorReader(
    'csv/rectangle_w_line_x_0_25_*.csv')
data_rectangle_w_line_x_n025 = mooseutils.VectorPostprocessorReader(
    'csv/rectangle_w_line_x_n0_25_*.csv')

data_rectangle_w_strip_x_025 = mooseutils.VectorPostprocessorReader(
    'csv/rectangle_w_strip_x_0_25_*.csv')
data_rectangle_w_strip_x_n025 = mooseutils.VectorPostprocessorReader(
    'csv/rectangle_w_strip_x_n0_25_*.csv')

data_block_w_line_x_0_25 = mooseutils.VectorPostprocessorReader(
    'csv/block_w_line_x_0_25_*.csv')
data_block_w_line_x_n0_25 = mooseutils.VectorPostprocessorReader(
Example #18
0
def frames():
    camera = vtk.vtkCamera()
    camera.SetViewUp(-0.0000000012, 0.9999999979, -0.0000646418)
    camera.SetPosition(0.1520029313, 0.0128604224, 0.1612327470)
    camera.SetFocalPoint(0.1520000000, 0.0128500000, 0.0000000000)

    reader = chigger.exodus.ExodusReader('step8_out.e')
    temp = chigger.exodus.ExodusResult(reader,
                                       camera=camera,
                                       variable='temperature',
                                       range=[300, 350],
                                       viewport=[0, 0.5, 1, 1],
                                       cmap='plasma')
    cbar = chigger.exodus.ExodusColorBar(temp,
                                         length=0.6,
                                         viewport=[0, 0, 1, 1],
                                         colorbar_origin=[0.1, 0.85],
                                         location='top')
    cbar.setOptions('primary',
                    title='Temperature (K)',
                    num_ticks=6,
                    font_size=48,
                    font_color=[0, 0, 0])

    time = chigger.annotations.TextAnnotation(position=[0.85, 0.85],
                                              font_size=48,
                                              text_color=[0, 0, 0],
                                              justification='center')

    pp_data = mooseutils.PostprocessorReader('step8_out.csv')
    x = pp_data['time']
    y0 = pp_data['average_temperature']
    y1 = pp_data['outlet_heat_flux']

    avg_temp = chigger.graphs.Line(color=[0.1, 0.1, 1], width=4, tracer=True)
    out_flux = chigger.graphs.Line(color=[1, 0.2, 0.2],
                                   width=4,
                                   tracer=True,
                                   corner='right-bottom')

    graph = chigger.graphs.Graph(avg_temp,
                                 out_flux,
                                 viewport=[0, 0, 0.5, 0.65])
    graph.setOptions('legend', visible=False)
    graph.setOptions('xaxis',
                     title='Time (s)',
                     lim=[0, 100],
                     font_color=[0, 0, 0],
                     font_size=28)
    graph.setOptions('yaxis',
                     title='Temperature (K)',
                     lim=[300, 350],
                     font_color=[0.1, 0.1, 1],
                     font_size=28,
                     num_ticks=6)
    graph.setOptions('y2axis',
                     title='Heat Flux (W/m^2)',
                     lim=[0, 2.5],
                     font_color=[1, 0.2, 0.2],
                     font_size=28,
                     num_ticks=6)

    vpp_data = mooseutils.VectorPostprocessorReader(
        'step8_out_temperature_sample_*.csv')

    line_temp = chigger.graphs.Line(color=[0.1, 0.1, 1], width=4, append=False)
    graph2 = chigger.graphs.Graph(line_temp, viewport=[0.5, 0, 1, 0.65])
    graph2.setOptions('legend', visible=False)
    graph2.setOptions('yaxis',
                      title='y (cm)',
                      lim=[0, 0.026],
                      font_color=[0, 0, 0],
                      font_size=28,
                      axis_scale=100,
                      num_ticks=5)
    graph2.setOptions('xaxis',
                      title='Temperature (K)',
                      lim=[300, 350],
                      font_color=[0, 0, 0],
                      font_size=28,
                      num_ticks=6)

    window = chigger.RenderWindow(temp,
                                  cbar,
                                  time,
                                  graph,
                                  graph2,
                                  size=[1920, 1080],
                                  motion_factor=0.1,
                                  background=[1, 1, 1])

    for i, t in enumerate(reader.getTimes()):
        reader.setOptions(timestep=i)
        reader.setOptions(timestep=i)
        reader.setOptions(timestep=i)
        avg_temp.setOptions(x=[x[i]], y=[y0[i]])
        out_flux.setOptions(x=[x[i]], y=[y1[i]])

        vpp = vpp_data(['y', 'temperature'], time=i)
        line_temp.setOptions(x=vpp['temperature'].tolist(),
                             y=vpp['y'].multiply(100).tolist())

        time.setOptions(text='Time = {:.2f} sec.'.format(t))
        filename = 'output/step08_{:05d}.png'.format(i)
        window.write(filename)

    window.start()
Example #19
0
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy
import chigger
import mooseutils

T_exact = mooseutils.VectorPostprocessorReader('1d_analytical_out_T_exact_*.csv')
T_sim = mooseutils.VectorPostprocessorReader('1d_analytical_out_T_simulation_*.csv')
x = T_exact['x']
n = len(T_exact.times())

# Exact alone
fig0 = plt.figure(dpi=300)
ax0 = fig0.add_subplot(111, xlabel='x [m]', ylabel='T [K]', ylim=[300,350])
ax0.grid(color=[0.8]*3)
l_exact0 = ax0.plot(x,[0]*len(x), '-k', label='exact', linewidth=1)[0]

# Exact and simulation
fig1 = plt.figure(dpi=300)
fig1.subplots_adjust(right=0.85)
ax1 = fig1.add_subplot(111, xlabel='x [m]', ylabel='T [K]', ylim=[300,350])
l_sim = ax1.plot(x,[0]*len(x), 'ob', label='simulation', markersize=3, markeredgewidth=0.5, markerfacecolor=[1]*3, markevery=5)[0]
l_exact = ax1.plot(x,[0]*len(x), '-k', label='exact', linewidth=1)[0]
plt.legend(loc='upper left')
ax1.grid(color=[0.8]*3)

ax2 = ax1.twinx()
ax2.set(ylabel="Absolute error [K]")
ax2.yaxis.set_major_locator(ticker.LinearLocator(numticks=6))
ax2.ticklabel_format(axis='y', style='scientific', scilimits=(0,0))