Exemple #1
0
def test_multigroup2():
    """Check that implemented averaging gives the same results as SNOP"""
    base_path = os.path.dirname(__file__)
    op0 = OpgHdf5.open_file(os.path.join(base_path, 'data/Al_snp_10kgr.h5'))
    op1 = OpgHdf5.open_file(os.path.join(base_path, 'data/Al_snp_40gr.h5'))
    group_idx, groups_new =  project_on_grid(op1['groups'][:], op0['groups'][:])
    res = avg_mg_table(op0, group_idx, fields=['opp_mg', 'opr_mg', 'emp_mg'],
            weight_pars={'opp_mg': 'planck', 'opr_mg': 'rosseland', 'emp_mg': "planck"}) 
    for key, rtol in {'opp_mg':1e-3, 'opr_mg':1e-3, 'emp_mg':0.7}.items():
        yield assert_allclose, op1[key][:], res[key], rtol, 0, 'Not the same '+key
Exemple #2
0
def test_export_hdf5():
    He = OpgMulti.open_file(BASE_DIR, reference_name, verbose=False)
    tmp_path = os.path.join(BASE_DIR, tmp_name + '.h5')
    He.write2hdf(tmp_path, Znum=[2])

    test = OpgHdf5.open_file(tmp_path, explicit_load=True)

    test.f.close()

    if os.path.exists(tmp_path):
        os.remove(tmp_path)
Exemple #3
0
def test_export_hdf5():
    He = OpgMulti.open_file(BASE_DIR, reference_name, verbose=False)
    tmp_path = os.path.join(BASE_DIR, tmp_name+'.h5')
    He.write2hdf(tmp_path, Znum=[2])

    test = OpgHdf5.open_file(tmp_path, explicit_load=True)

    test.f.close()

    if os.path.exists(tmp_path):
        os.remove(tmp_path)
Exemple #4
0
def test_hdf5_write():
    fh = OpgHdf5.open_file(reference_file)
    tmp_file =  os.path.join(BASE_DIR, 'Al_snp_40gr_tmp.h5')

    try:
        fh.write2file(tmp_file)
    except:
        raise
    finally:
        fh.f.close()
        if os.path.exists(tmp_file):
            os.remove(tmp_file) 
Exemple #5
0
def test_hdf5_write():
    fh = OpgHdf5.open_file(reference_file)
    tmp_file = os.path.join(BASE_DIR, 'Al_snp_40gr_tmp.h5')

    try:
        fh.write2file(tmp_file)
    except:
        raise
    finally:
        fh.f.close()
        if os.path.exists(tmp_file):
            os.remove(tmp_file)
Exemple #6
0
def hdf_opacity(path, dens, tele, nu):
    op = OpgHdf5.open_file(path)
    dens_mg = op['dens'][:]
    temp_mg = op['temp'][:]
    groups =  op['groups'][:]
    group_center = 0.5*(groups[1:]  + groups[:-1])
    Ng = len(groups) - 1
    D, T, G = np.meshgrid(dens_mg, temp_mg, group_center)
    Di, Gi = np.meshgrid(dens, nu)
    Ti, _ = np.meshgrid(tele, nu)

    points = np.concatenate((D.flatten()[:,np.newaxis], T.flatten()[:,np.newaxis], G.flatten()[:,np.newaxis]), axis=1)
    xi = np.concatenate((Di.flatten()[:,np.newaxis], Ti.flatten()[:,np.newaxis], Gi.flatten()[:,np.newaxis]), axis=1)
    data = op['opp_mg'][:].flatten()
    res = griddata(points, data, xi, method='nearest')
    return res.reshape(nu.shape+dens.shape)
Exemple #7
0
def radiative_grid(r, opacity_file):
    """ 
    Parameters:
    -----------
      - r: ray orho ray
      - opacity file: patj to a hdf5 opacity file 
    """
    import numpy as np
    from opacplot2.opg_hdf5 import OpgHdf5
    op = OpgHdf5.open_file(opacity_file)
    groups = op['groups'][:]
    Ng = len(groups) - 1
    vars_list = ['r{0:3}'.format(idx) for idx in range(Ng + 1)]
    x = r['x']
    X, G = np.meshgrid(x, groups)
    R = np.zeros(X.shape)
    OP = np.zeros(X.shape)
    for idx in range(Ng):
        R[idx, :] = r['r{0:03}'.format(idx + 1)]

    return X, G, R, OP
Exemple #8
0
def radiative_grid(r, opacity_file):
    """ 
    Parameters:
    -----------
      - r: ray orho ray
      - opacity file: patj to a hdf5 opacity file 
    """
    import numpy as np
    from opacplot2.opg_hdf5 import OpgHdf5
    op = OpgHdf5.open_file(opacity_file)
    groups =  op['groups'][:]
    Ng = len(groups) - 1
    vars_list = ['r{0:3}'.format(idx) for idx in range(Ng+1)]
    x = r['x']
    X, G = np.meshgrid(x, groups)
    R = np.zeros(X.shape)
    OP = np.zeros(X.shape)
    for idx in range(Ng):
        R[idx,:] = r['r{0:03}'.format(idx+1)]

    return X, G, R, OP
Exemple #9
0
def hdf_opacity(path, dens, tele, nu):
    op = OpgHdf5.open_file(path)
    dens_mg = op['dens'][:]
    temp_mg = op['temp'][:]
    groups = op['groups'][:]
    group_center = 0.5 * (groups[1:] + groups[:-1])
    Ng = len(groups) - 1
    D, T, G = np.meshgrid(dens_mg, temp_mg, group_center)
    Di, Gi = np.meshgrid(dens, nu)
    Ti, _ = np.meshgrid(tele, nu)

    points = np.concatenate(
        (D.flatten()[:, np.newaxis], T.flatten()[:, np.newaxis],
         G.flatten()[:, np.newaxis]),
        axis=1)
    xi = np.concatenate(
        (Di.flatten()[:, np.newaxis], Ti.flatten()[:, np.newaxis],
         Gi.flatten()[:, np.newaxis]),
        axis=1)
    data = op['opp_mg'][:].flatten()
    res = griddata(points, data, xi, method='nearest')
    return res.reshape(nu.shape + dens.shape)
Exemple #10
0
def test_hdf5_read():
    fh = OpgHdf5.open_file(reference_file)
    fh.run_testsuite(mode='full')
    fh.f.close()
Exemple #11
0
def test_hdf5_read():
    fh = OpgHdf5.open_file(reference_file)
    fh.run_testsuite(mode='full')
    fh.f.close()