Пример #1
0
def test_jeff33_fy(tmpdir):
    iargs = [
        os.path.join(FY.__path__[0], r"FY.jeff33"), "--outdir",
        str(tmpdir), "--mat", "9228", "--processes",
        str(os.cpu_count()), "--samples", "10", "--fission-yields"
    ]
    sampling(iargs)
Пример #2
0
def test_U238_lpc(tmpdir):
    iargs = [
        os.path.join(U8.__path__[0], r"u238.endf"), "--cov",
        os.path.join(U8.__path__[0], r"u238.endf"), "--outdir",
        str(tmpdir), "--verbose", "--processes",
        str(os.cpu_count()), "--eig", "15", "--samples", "10", "--mf", "34"
    ]
    sampling(iargs)
Пример #3
0
def test_Fe56_lpc(tmpdir):
    iargs = [
        os.path.join(Fe56.__path__[0], r"fe56.endf"), "--cov",
        os.path.join(Fe56.__path__[0], r"fe56.endf"), "--outdir",
        str(tmpdir), "--processes",
        str(os.cpu_count()), "--samples", "10", "--mf", "34"
    ]
    sampling(iargs)
Пример #4
0
def test_U5_chi(tmpdir):
    iargs = [
        os.path.join(U5.__path__[0], r"u235.endf"), "--cov",
        os.path.join(U5.__path__[0], r"u235.endf"), "--outdir",
        str(tmpdir), "--processes",
        str(os.cpu_count()), "--samples", "10", "--mf", "35"
    ]
    sampling(iargs)
Пример #5
0
def test_H1(tmpdir):
    iargs = [
        os.path.join(H1.__path__[0], r"h1.pendf"),
        "--cov",
        os.path.join(H1.__path__[0], r"h1.errorr"),
        "--outdir",
        str(tmpdir),
        "--processes",
        str(os.cpu_count()),
        "--eig",
        "10",
        "--samples",
        "10",
    ]
    sampling(iargs)
Пример #6
0
def test_U5_errorr(tmpdir):
    iargs = [
        os.path.join(U5.__path__[0], r"u235.pendf"),
        "--cov",
        os.path.join(U5.__path__[0], r"u235.errorr"),
        "--outdir",
        str(tmpdir),
        "--processes",
        str(os.cpu_count()) if os.cpu_count() < 10 else str(10),
        "--eig",
        "10",
        "--samples",
        "10",
    ]
    sampling(iargs)
Пример #7
0
def test_Cm242(tmpdir):
    iargs = [
        os.path.join(Cm242.__path__[0], r"cm242.endf"),
        "--cov",
        os.path.join(Cm242.__path__[0], r"cm242.endf"),
        "--outdir",
        str(tmpdir),
        "--processes",
        str(os.cpu_count()),
        "--eig",
        "10",
        "--samples",
        "10",
    ]
    sampling(iargs)
Пример #8
0
def test_Fe56_pendf_cov_errorr_only_mt3(tmpdir):
    """Sampling test to check the following:
    
    - sampling runs correctly with keywords:
        
        * `outdir`
        * `debug`
        * `cov`
        * `samples`
        * `mt`
        * `mf`
        * `mat`
    
    - sandy `mt` option works as expected
    - sandy `mf` option works as expected
    - sandy `mat` option works as expected
    - ratio between perturbed files and original pendf are equal to perturbations
    - daughter reactions are perturbed according to parent reaction perturbations
    - redundant cross sections are correclty summed up
    """
    name = "26056.pendf"
    file = os.path.join(os.path.dirname(__file__), "data", name)
    endftape = sandy.read_formatted_file(file)
    covname = "26056.errorr"
    filecov = os.path.join(os.path.dirname(__file__), "data", covname)
    iargs = [
        file,
        "--cov",
        filecov,
        "--outdir",
        str(tmpdir),
        "--debug",
        "--samples",
        "1",
        "--mt",
        "3",
        "--mf",
        "33",
        "--mat",
        "2631",
    ]
    ftape, covtape, outs = sampling(iargs)
    # Check that ratio between perturbed files and original pendf are equal to perturbations
    xs = ftape.get_xs()
    perts = pd.read_csv(os.path.join(str(tmpdir), 'perts_mf33.csv'))
    for i in range(1):
        tape = sandy.read_formatted_file(
            os.path.join(str(tmpdir), "{}-{}".format(name, i + 1)))
        xs1 = tape.get_xs()
        mts = xs1.columns.get_level_values("MT").unique()
        for mt in mts[mts > 3]:
            perts.MT = mt
            check_xs(xs, xs1, perts, 2631, mt, i + 1)
        assert np.allclose(
            xs1[2631][[2, 4, 5, 16, 22, 28, 102, 103, 104, 105, 106,
                       107]].sum(axis=1), xs1[2631, 1])
Пример #9
0
def test_h1_run_errorr(tmpdir):
    """Sampling test to check the following:
    
    - sampling runs correctly with keywords:
        
        * `outdir`
        * errorr
        * `debug`
        * `seed33`
        * `samples`
    
    - `outdir` directory was created
    - only 2 sample were produced for MAT 125
    - pertubed files exist and are named correctly
    - NJOY ran RECONR and ERRORR
    - perturbations are dump to file (debug option)
    - ratio between perturbed files and original pendf are equal to perturbations
    - redundant cross sections are correclty summed up
    """
    name = "1-H-1g.jeff33"
    file = os.path.join(os.path.dirname(__file__), "data", name)
    iargs = [
        file,
        "--outdir",
        str(tmpdir),
        "--error",
        "--debug",
        "--seed33",
        "555",
        "--samples",
        "2",
    ]
    ftape, covtape, outs = sampling(iargs)
    # Check that covariance file is  errorr
    assert covtape.get_file_format() == "errorr"
    # Check that PENDF flag was changed
    tape = sandy.read_formatted_file(
        os.path.join(str(tmpdir), "{}-1".format(name)))
    infosec = tape.read_section(125, 1, 451)
    assert infosec["TEMP"] == 0
    assert tape.get_file_format() == "pendf"
    # Check that ratio between perturbed files and original pendf are equal to perturbations
    xs = ftape.get_xs()
    perts = pd.read_csv(os.path.join(str(tmpdir), 'perts_mf33.csv'))
    for i in range(2):
        tape = sandy.read_formatted_file(
            os.path.join(str(tmpdir), "{}-{}".format(name, i + 1)))
        xs1 = tape.get_xs()
        for mt in (2, 102):
            check_xs(xs, xs1, perts, 125, mt, i + 1)
        assert np.allclose(xs1[(125, 2)] + xs1[(125, 102)],
                           xs1[(125, 1)],
                           rtol=1e-6)
Пример #10
0
def test_h1_cov_errorr(tmpdir):
    """Sampling test to check the following:
    
    - sampling runs correctly with keywords:
        
        * `outdir`
        * `cov`
        * `debug`
        * `seed33`
        * `samples`
    
    - SANDY reads covariances in ERRORR format
    - NJOY ran RECONR
    - perturbations are dump to file (debug option)
    - ratio between perturbed files and original pendf are equal to perturbations
    - redundant cross sections are correclty summed up
    """
    name = "1-H-1g.jeff33"
    file = os.path.join(os.path.dirname(__file__), "data", name)
    covname = "1-H-1g.jeff33.errorr"
    filecov = os.path.join(os.path.dirname(__file__), "data", covname)
    iargs = [
        file,
        "--outdir",
        str(tmpdir),
        "--cov",
        filecov,
        "--debug",
        "--seed33",
        "555",
        "--samples",
        "2",
    ]
    ftape, covtape, outs = sampling(iargs)
    # Check that covariance file is  errorr
    assert covtape.get_file_format() == "errorr"
    # Check that NJOY ran RECONR
    assert ftape.get_file_format() == "pendf"
    # Check that ratio between perturbed files and original pendf are equal to perturbations
    xs = ftape.get_xs()
    perts = pd.read_csv(os.path.join(str(tmpdir), 'perts_mf33.csv'))
    for i in range(2):
        tape = sandy.read_formatted_file(
            os.path.join(str(tmpdir), "{}-{}".format(name, i + 1)))
        xs1 = tape.get_xs()
        for mt in (2, 102):
            check_xs(xs, xs1, perts, 125, mt, i + 1)
        assert np.allclose(xs1[(125, 2)] + xs1[(125, 102)],
                           xs1[(125, 1)],
                           rtol=1e-6)
Пример #11
0
def test_h1_pendf_cov_errorr_only_mt102(tmpdir):
    """Sampling test to check the following:
    
    - sampling runs correctly with keywords:
        
        * `outdir`
        * `cov`
        * `samples`
    
    - SANDY reads covariances in ERRORR format
    - SANDY reads input file in PENDF format
    - NJOY does not run
    - perturbations are dump to file (debug option)
    - ratio between perturbed files and original pendf are equal to perturbations
    - redundant cross sections are correclty summed up
    """
    name = "1-H-1g.jeff33.pendf"
    file = os.path.join(os.path.dirname(__file__), "data", name)
    covname = "1-H-1g.jeff33.errorr"
    filecov = os.path.join(os.path.dirname(__file__), "data", covname)
    iargs = [
        file,
        "--outdir",
        str(tmpdir),
        "--debug",
        "--cov",
        filecov,
        "--mt",
        "102",
        "--samples",
        "2",
    ]
    ftape, covtape, outs = sampling(iargs)
    # Check that ratio between perturbed files and original pendf are equal to perturbations
    xs = ftape.get_xs()
    perts = pd.read_csv(os.path.join(str(tmpdir), 'perts_mf33.csv'))
    for i in range(2):
        tape = sandy.read_formatted_file(
            os.path.join(str(tmpdir), "{}-{}".format(name, i + 1)))
        xs1 = tape.get_xs()
        # MT102 is perturbed
        check_xs(xs, xs1, perts, 125, 102, i + 1)
        # MT2 is not perturbed
        assert ((xs1 / xs)[125, 2] == 1).all()
        # MT1 is perturbed and it is the sum
        assert np.allclose(xs1[(125, 2)] + xs1[(125, 102)],
                           xs1[(125, 1)],
                           rtol=1e-6)
Пример #12
0
def test_Fe56_pendf_cov_errorr_no_mt(tmpdir):
    """Sampling test to check the following:
       
    - sandy `mt` option works as expected
    """
    name = "26056.pendf"
    file = os.path.join(os.path.dirname(__file__), "data", name)
    endftape = sandy.read_formatted_file(file)
    covname = "26056.endf"
    filecov = os.path.join(os.path.dirname(__file__), "data", covname)
    iargs = [
        file,
        "--mt",
        "511",
    ]
    ftape, covtape, outs = sampling(iargs)
    assert not outs
Пример #13
0
def test_h1(tmpdir):
    """Sampling test to check the following:
    
    - sampling runs correctly with keywords:
        
        * `outdir`
        * `cov`
        * `debug`
        * `seed33`
        * `samples`
    
    - `outdir` directory was created
    - only 1 sample was produced for MAT 125
    - pertubed files exist and are named correctly
    - perturbed files do not contain covariance MF sections
    - NJOY ran RECONR
    - NJOY did not run RECONR
    - perturbed files are actual PENDF 
    - perturbation do not change (seed33 option)
    - only cross sections were perturbed, other data remain unchanged
    - perturbations are dump to file (debug option)
    - ratio between perturbed files and original pendf are equal to perturbations
    - redundant cross sections are correclty summed up
    """
    name = "1-H-1g.jeff33"
    file = os.path.join(os.path.dirname(__file__), "data", name)
    endftape = sandy.read_formatted_file(file)
    covname = "h1cov.3x3"
    filecov = os.path.join(os.path.dirname(__file__), "data", covname)
    iargs = [
        file,
        "--cov",
        filecov,
        "--outdir",
        str(tmpdir),
        "--acer",
        "--temperatures",
        "900",
        "1200",
        "--debug",
        "--seed33",
        "555",
        "--samples",
        "1",
    ]
    ftape, covtape, outs = sampling(iargs)
    # check that only 1 sample was produced for MAT 125
    assert sorted(outs.keys()) == [125]
    assert sorted(outs[125].keys()) == [1]
    # Check that perturbed files exist
    assert "{}-1".format(name) in os.listdir(str(tmpdir))
    tape = sandy.read_formatted_file(
        os.path.join(str(tmpdir), "{}-1".format(name)))
    # Check that pendf file tape30 exist (debug option)
    assert "tape30" in os.listdir(str(tmpdir))
    # Check that covariances were removed
    assert tape.index.equals(
        pd.MultiIndex(levels=[[125], [1, 2, 3, 4, 6], [1, 2, 102, 151, 451]],
                      codes=[[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 2, 2, 3, 4],
                             [4, 3, 0, 1, 2, 1, 2]],
                      names=['MAT', 'MF', 'MT']))
    infosec = tape.read_section(125, 1, 451)
    # Check that PENDF flag was changed
    assert infosec["TEMP"] == 0
    assert tape.get_file_format() == "pendf"
    # Check that covariance file is not errorr
    assert covtape.get_file_format() != "errorr"
    # Check that non perturbed data did not change
    assert endftape.TEXT.loc[125, 2, 151] == tape.TEXT.loc[125, 2, 151]
    assert endftape.TEXT.loc[125, 4, 2] == tape.TEXT.loc[125, 4, 2]
    assert endftape.TEXT.loc[125, 6, 102] == tape.TEXT.loc[125, 6, 102]
    # Check that perts do not change (seed33 option)
    perts = pd.read_csv(os.path.join(str(tmpdir),
                                     'perts_mf33.csv'))["1"].values
    assert perts.tolist() == [
        1.0148227202065168, 1.0353486552229474, 0.8912750106863625
    ]
    # Check that ratio between perturbed files and original pendf are equal to perturbations
    xs1 = tape.get_xs()
    xs = ftape.get_xs()
    ratio = xs1[(125, 102)] / xs[(125, 102)]
    egrid = ratio.index.get_level_values("E")
    assert np.allclose(ratio[(egrid < 1e1) & (egrid >= 1e-5)],
                       perts[0],
                       rtol=1e-6)
    assert np.allclose(ratio[(egrid < 1e7) & (egrid >= 1e1)],
                       perts[1],
                       rtol=1e-6)
    assert np.allclose(ratio[(egrid >= 1e7)], perts[2], rtol=1e-6)
    # Check that ratio between perturbed files and original pendf are equal to perturbations
    # also for redundant cross sections, although with a lower tolerance
    assert np.allclose(xs1.reconstruct_sums(), xs1)
    assert xs1[(125, 2)].equals(xs[(125, 2)])
    ratio = (xs1[(125, 1)] - xs[(125, 2)]) / xs[(125, 102)]
    assert np.allclose(ratio[(egrid < 1e1) & (egrid >= 1e-5)],
                       perts[0],
                       rtol=1e-3)
    assert np.allclose(ratio[(egrid < 1e7) & (egrid >= 1e1)],
                       perts[1],
                       rtol=1e-3)
    assert np.allclose(ratio[(egrid >= 1e7)], perts[2], rtol=1e-3)
    assert '1001_1.09c' in os.listdir(str(tmpdir))
    assert '1001_1.12c' in os.listdir(str(tmpdir))
    assert '1001_1.09c.xsd' in os.listdir(str(tmpdir))
    assert '1001_1.12c.xsd' in os.listdir(str(tmpdir))