<commit_before>from tables import openFile
from numpy import mgrid, add, multiply, ones, flatnonzero, empty, float64

def read_flash_names(filename, names):
    """ read arrays of the given names in a flash file """
    f = openFile(filename, 'r')

    res = {}

    params = f.getNode(f.root, 'simulation parameters')
    res['time'] = params[0][1]

    for name in names:
        res[name] =  f.getNode(f.root, name).read()
    f.close()
    return res

def read_cell_centres(filename):
    """ get cell centres of flash file cells """
    names = ['block size', 'coordinates']
    res = read_flash_names(filename, names) 
  
    block_size =  res['block size']
    coords = res['coordinates']

    if coords.shape[1]==3:
        z,y,x = (mgrid[:8,:8,:8]-3.5) * (1.0/8.0)
 
        x = multiply.outer(block_size[:,0], x) + multiply.outer(coords[:,0], ones(x.shape, dtype=block_size.dtype))
        y = multiply.outer(block_size[:,1], y) + multiply.outer(coords[:,1], ones(y.shape, dtype=block_size.dtype))
        z = multiply.outer(block_size[:,2], z) + multiply.outer(coords[:,2], ones(z.shape, dtype=block_size.dtype))
  
        return x,y,z

    if coords.shape[1]==2:
        y,x = (mgrid[:8,:8]-3.5) * (1.0/8.0)
 
        x = multiply.outer(block_size[:,0], x) + multiply.outer(coords[:,0], ones(x.shape, dtype=block_size.dtype))
        y = multiply.outer(block_size[:,1], y) + multiply.outer(coords[:,1], ones(y.shape, dtype=block_size.dtype))

        return x,y
    x = (mgrid[:8]-3.5) * (1.0/8.0)
    x = multiply.outer(block_size[:,0], x) + multiply.outer(coords[:,0], ones(x.shape, dtype=block_size.dtype))
    
    return (x,)

def read_runtime_params(filename):
    """ read the cfl value """
    f = openFile(filename, 'r')
    params = f.getNode(f.root, 'real runtime parameters').read()

    f.close()

    params = dict((name.rstrip(), val) for name, val in params)

    return params

def get_data(filename, vars=('dens', 'pres', 'lamb', 'temp', 'eint')):
    """ 
    get_data(filename, vars=('dens', 'pres', 'lamb', 'temp', 'eint')):
    read flash data for a given filename
    """
    coords = read_cell_centres(filename)
    dim = len(coords)
    names = ['node type', 'block size'] + list(vars)
    data = read_flash_names(filename, names) 

    leaf_blocks = flatnonzero(data['node type']==1)

    result = {}
    for var in vars:
        result[var] = data[var][leaf_blocks].flatten()

    result['cell size'] = data['block size'][leaf_blocks, 0] / 8.0

    pos = empty((leaf_blocks.size*(8**dim), dim), dtype=float64)

    for i in range(dim):<commit_msg>each cell now has a size<commit_after>from tables import openFile
from numpy import mgrid, add, multiply, ones, flatnonzero, empty, float64, repeat

def read_flash_names(filename, names):
    """ read arrays of the given names in a flash file """
    f = openFile(filename, 'r')

    res = {}

    params = f.getNode(f.root, 'simulation parameters')
    res['time'] = params[0][1]

    for name in names:
        res[name] =  f.getNode(f.root, name).read()
    f.close()
    return res

def read_cell_centres(filename):
    """ get cell centres of flash file cells """
    names = ['block size', 'coordinates']
    res = read_flash_names(filename, names) 
  
    block_size =  res['block size']
    coords = res['coordinates']

    if coords.shape[1]==3:
        z,y,x = (mgrid[:8,:8,:8]-3.5) * (1.0/8.0)
 
        x = multiply.outer(block_size[:,0], x) + multiply.outer(coords[:,0], ones(x.shape, dtype=block_size.dtype))
        y = multiply.outer(block_size[:,1], y) + multiply.outer(coords[:,1], ones(y.shape, dtype=block_size.dtype))
        z = multiply.outer(block_size[:,2], z) + multiply.outer(coords[:,2], ones(z.shape, dtype=block_size.dtype))
  
        return x,y,z

    if coords.shape[1]==2:
        y,x = (mgrid[:8,:8]-3.5) * (1.0/8.0)
 
        x = multiply.outer(block_size[:,0], x) + multiply.outer(coords[:,0], ones(x.shape, dtype=block_size.dtype))
        y = multiply.outer(block_size[:,1], y) + multiply.outer(coords[:,1], ones(y.shape, dtype=block_size.dtype))

        return x,y
    x = (mgrid[:8]-3.5) * (1.0/8.0)
    x = multiply.outer(block_size[:,0], x) + multiply.outer(coords[:,0], ones(x.shape, dtype=block_size.dtype))
    
    return (x,)

def read_runtime_params(filename):
    """ read the cfl value """
    f = openFile(filename, 'r')
    params = f.getNode(f.root, 'real runtime parameters').read()

    f.close()

    params = dict((name.rstrip(), val) for name, val in params)

    return params

def get_data(filename, vars=('dens', 'pres', 'lamb', 'temp', 'eint')):
    """ 
    get_data(filename, vars=('dens', 'pres', 'lamb', 'temp', 'eint')):
    read flash data for a given filename
    """
    coords = read_cell_centres(filename)
    dim = len(coords)
    names = ['node type', 'block size'] + list(vars)
    data = read_flash_names(filename, names) 

    leaf_blocks = flatnonzero(data['node type']==1)

    result = {}
    for var in vars:
        result[var] = data[var][leaf_blocks].flatten()

    result['cell size'] = repeat(data['block size'][leaf_blocks, 0] / 8.0, 8**dim)

    pos = empty((leaf_blocks.size*(8**dim), dim), dtype=float64)

    for i in range(dim):
{'fraction_non_alphanumeric': 0.1800729506623152, 'fraction_numerical': 0.019773468995968515, 'mean_word_length': 3.3929173693086003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2067871', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1868, 'n_words': 416}