import numpy as np import scipy.stats import matplotlib.pyplot as plt from statepoint import StatePoint # Get filename filename = argv[1] # Determine axial level axial_level = int(argv[2]) if len(argv) > 2 else 1 score = int(argv[3]) if len(argv) > 3 else 1 # Create StatePoint object sp = StatePoint(filename) # Read number of realizations for global tallies sp.n_realizations = sp._get_int()[0] # Read global tallies n_global_tallies = sp._get_int()[0] sp.global_tallies = np.array(sp._get_double(2 * n_global_tallies)) sp.global_tallies.shape = (n_global_tallies, 2) # Flag indicating if tallies are present tallies_present = sp._get_int()[0] # Check if tallies are present if not tallies_present: raise Exception("No tally data in state point!")
def main(file_, o): """Main program""" sp = StatePoint(file_) sp.read_results() validate_options(sp, o) if o.list: print_available(sp) return if o.vtk: if not o.output[-4:] == ".vtm": o.output += ".vtm" else: if not o.output[-5:] == ".silo": o.output += ".silo" if o.vtk: try: import vtk except: print('The vtk python bindings do not appear to be installed properly.\n' 'On Ubuntu: sudo apt-get install python-vtk\n' 'See: http://www.vtk.org/') return else: try: import silomesh except: print('The silomesh package does not appear to be installed properly.\n' 'See: https://github.com/nhorelik/silomesh/') return if o.vtk: blocks = vtk.vtkMultiBlockDataSet() blocks.SetNumberOfBlocks(5) block_idx = 0 else: silomesh.init_silo(o.output) # Tally loop ################################################################# for tally in sp.tallies: # skip non-mesh tallies or non-user-specified tallies if o.tallies and not tally.id in o.tallies: continue if not 'mesh' in tally.filters: continue print("Processing Tally {}...".format(tally.id)) # extract filter options and mesh parameters for this tally filtercombos = get_filter_combos(tally) meshparms = get_mesh_parms(sp, tally) nx,ny,nz = meshparms[:3] ll = meshparms[3:6] ur = meshparms[6:9] if o.vtk: ww = [(u-l)/n for u,l,n in zip(ur,ll,(nx,ny,nz))] grid = grid = vtk.vtkImageData() grid.SetDimensions(nx+1,ny+1,nz+1) grid.SetOrigin(*ll) grid.SetSpacing(*ww) else: silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms) # Score loop ############################################################### for sid,score in enumerate(tally.scores): # skip non-user-specified scrores for this tally if o.scores and tally.id in o.scores and not sid in o.scores[tally.id]: continue # Filter loop ############################################################ for filterspec in filtercombos: # skip non-user-specified filter bins skip = False if o.filters and tally.id in o.filters: for filter_,bin in filterspec[1:]: if filter_ in o.filters[tally.id] and \ not bin in o.filters[tally.id][filter_]: skip = True break if skip: continue # find and sanitize the variable name for this score varname = get_sanitized_filterspec_name(tally, score, filterspec) if o.vtk: vtkdata = vtk.vtkDoubleArray() vtkdata.SetName(varname) dataforvtk = {} else: silomesh.init_var(varname) lbl = "\t Score {}.{} {}:\t\t{}".format(tally.id, sid+1, score, varname) # Mesh fill loop ####################################################### for x in range(1,nx+1): sys.stdout.write(lbl+" {0}%\r".format(int(x/nx*100))) sys.stdout.flush() for y in range(1,ny+1): for z in range(1,nz+1): filterspec[0][1] = (x,y,z) val = sp.get_value(tally.id-1, filterspec, sid)[o.valerr] if o.vtk: # vtk cells go z, y, x, so we store it now and enter it later i = (z-1)*nx*ny + (y-1)*nx + x-1 dataforvtk[i] = float(val) else: silomesh.set_value(float(val), x, y, z) # end mesh fill loop print() if o.vtk: for i in range(nx*ny*nz): vtkdata.InsertNextValue(dataforvtk[i]) grid.GetCellData().AddArray(vtkdata) del vtkdata else: silomesh.finalize_var() # end filter loop # end score loop if o.vtk: blocks.SetBlock(block_idx, grid) block_idx += 1 else: silomesh.finalize_mesh() # end tally loop if o.vtk: writer = vtk.vtkXMLMultiBlockDataWriter() writer.SetFileName(o.output) writer.SetInput(blocks) writer.Write() else: silomesh.finalize_silo()
def main(file_, o): """Main program""" sp = StatePoint(file_) sp.read_results() validate_options(sp, o) if o.list: print_available(sp) return silomesh.init_silo(o.output) # Tally loop ################################################################# for tally in sp.tallies: # skip non-mesh tallies or non-user-specified tallies if o.tallies and not tally.id in o.tallies: continue if not 'mesh' in tally.filters: continue print "Processing Tally {}...".format(tally.id) # extract filter options and mesh parameters for this tally filtercombos = get_filter_combos(tally) meshparms = get_mesh_parms(sp, tally) nx, ny, nz = meshparms[0], meshparms[1], meshparms[2] silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms) # Score loop ############################################################### for sid, score in enumerate(tally.scores): # skip non-user-specified scrores for this tally if o.scores and tally.id in o.scores and not sid in o.scores[ tally.id]: continue # Filter loop ############################################################ for filterspec in filtercombos: # skip non-user-specified filter bins skip = False if o.filters and tally.id in o.filters: for filter_, bin in filterspec[1:]: if filter_ in o.filters[tally.id] and \ not bin in o.filters[tally.id][filter_]: skip = True break if skip: continue # find and sanitize the variable name for this score varname = get_sanitized_filterspec_name( tally, score, filterspec) silomesh.init_var(varname) print "\t Score {}.{} {}:\t\t{}".format( tally.id, sid + 1, score, varname) # Mesh fill loop ####################################################### for x in range(1, nx + 1): for y in range(1, ny + 1): for z in range(1, nz + 1): filterspec[0][1] = (x, y, z) val = sp.get_value(tally.id - 1, filterspec, sid)[o.valerr] silomesh.set_value(float(val), x, y, z) # end mesh fill loop silomesh.finalize_var() # end filter loop # end score loop silomesh.finalize_mesh() # end tally loop silomesh.finalize_silo()
#!/usr/bin/env python from sys import argv from math import sqrt import numpy as np import scipy.stats import matplotlib import matplotlib.pyplot as plt from statepoint import StatePoint # Create StatePoint object sp1 = StatePoint('without-ufs.state') sp2 = StatePoint('with-ufs.state') sp1._get_int() sp2._get_int() # Calculate t-value for 95% two-sided CI n = sp1.current_batch - sp1.n_inactive t_value = scipy.stats.t.ppf(0.975, n - 1) ################################ WITHOUT UFS ################################### for t in sp1.tallies: n_bins = t.n_score_bins * t.n_filter_bins i_mesh = [f.type for f in t.filters].index('mesh') # Get Mesh object m = sp1.meshes[t.filters[i_mesh].bins[0] - 1] nx, ny, nz = m.dimension
#!/usr/bin/env python import sys from numpy.testing import assert_allclose, assert_equal from statepoint import StatePoint if len(sys.argv) > 2: path1 = sys.argv[1] path2 = sys.argv[2] else: raise # Create StatePoint objects sp1 = StatePoint(path1) sp2 = StatePoint(path2) # Read tally results sp1.read_results() sp2.read_results() # Compare header information assert sp1.revision == sp2.revision assert sp1.version == sp2.version assert sp1.seed == sp2.seed assert sp1.run_mode == sp2.run_mode assert sp1.n_particles == sp2.n_particles assert sp1.n_batches == sp2.n_batches if sp1.run_mode == 2:
for i in range(len(fileNums)): files.append("./statepoint." + str(fileNums[i]) + ".binary") # Initialize arrays as needed mean = [None for x in range(len(files))] uncert = [None for x in range(len(files))] scoreType = [None for x in range(len(files))] active_batches = [None for x in range(len(files))] for i_batch in range(len(files)): # Get filename batch_filename = files[i_batch] # Create StatePoint object sp = StatePoint(batch_filename) # Read number of realizations for global tallies sp.n_realizations = sp._get_int()[0] # Read global tallies n_global_tallies = sp._get_int()[0] sp.global_tallies = np.array(sp._get_double(2*n_global_tallies)) sp.global_tallies.shape = (n_global_tallies, 2) # Flag indicating if tallies are present tallies_present = sp._get_int()[0] # Check if tallies are present if not tallies_present: raise Exception("No tally data in state point!")