Exemplo n.º 1
0
def test_rbmultchk2():
    # write to a string:
    with StringIO() as f:
        cb.rbmultchk(f,
                     np.zeros((15, 6)),
                     "DRM",
                     np.eye(6),
                     drm2=np.random.randn(15, 6))
        s = f.getvalue()
    assert s.find(" -- no coordinates detected --") > -1
    assert s.find("All rows in DRM are NULL") > -1
    assert s.find("There are no NULL rows in DRM2.") > -1

    with StringIO() as f:
        cb.rbmultchk(f,
                     np.zeros((15, 6)),
                     "DRM",
                     np.eye(6),
                     drm2=np.random.randn(14, 6))
        s = f.getvalue()
    assert s.find("Error: incorrectly sized DRM2") > -1

    drm = np.random.randn(14, 6)
    drm2 = np.random.randn(14, 6)
    drm[::3] = 0.0
    drm2[1::3] = 0.0
    with StringIO() as f:
        cb.rbmultchk(f, drm, "DRM", np.eye(6), drm2=drm2)
        s = f.getvalue()
    assert s.find("different set of NULL rows") > -1

    drm = np.random.randn(14, 6)
    drm2 = np.random.randn(14, 6)
    drm[::3] = 0.0
    drm2[2::3] = 0.0
    with StringIO() as f:
        cb.rbmultchk(f, drm, "DRM", np.eye(6), drm2=drm2)
        s = f.getvalue()
    assert s.find("different set of NULL rows") > -1

    with StringIO() as f:
        assert_raises(ValueError, cb.rbmultchk, f, drm, "drm", 1)
    with StringIO() as f:
        assert_raises(ValueError, cb.rbmultchk, f, drm, "drm", np.zeros(
            (6, 6)))
Exemplo n.º 2
0
def test_rbmultchk():
    nas = op2.rdnas2cam("tests/nas2cam_csuper/nas2cam")
    se = 101
    maa = nas["maa"][se]
    kaa = nas["kaa"][se]
    pv = np.any(maa, axis=0)
    pv = np.ix_(pv, pv)
    maa = maa[pv]
    kaa = kaa[pv]

    uset = nas["uset"][se]
    bset = n2p.mksetpv(uset, "p", "b")
    usetb = nas["uset"][se].iloc[bset]
    b = n2p.mksetpv(uset, "a", "b")
    q = ~b
    b = np.nonzero(b)[0]

    grids = [[11, 123456], [45, 123456], [60, 123456]]
    drm101, dof101 = n2p.formtran(nas, 101, grids)

    # write and read a file:
    f = tempfile.NamedTemporaryFile(delete=False)
    name = f.name
    f.close()

    rb = n2p.rbgeom_uset(usetb)
    cb.rbmultchk(name, drm101, "DRM101", rb)
    with open(name) as f:
        sfile = f.read()
    os.remove(name)

    # test rbscale and unit scale:
    with StringIO() as f:
        cb.rbmultchk(f, 0.00259 * drm101, "DRM101", 100 * rb)
        s = f.getvalue()

    pos = s.find(" which is: ")
    pos2 = s[pos:].find("\n")
    assert math.isclose(float(s[pos + 10 : pos + pos2]), 100)
    s = s.splitlines()
    table, nj1 = gettable(s, 15, 0, "Absolute Maximums", 3)
    sbe = np.array(
        [
            [600, 300, 300, 0.00259],
            [600, 300, 300, 0.00259],
            [600, 300, 300, 0.00259],
            [150, -930, 150, 0.00259],
            [600, 300, 300, 0.00259],
            [150, -930, 150, 0.00259],
        ]
    )

    assert np.allclose(table[:, 1:5], sbe)

    # write to a string:
    with StringIO() as f:
        cb.rbmultchk(f, drm101, "DRM101", rb)
        s = f.getvalue()
    assert sfile == s

    # add q-set rows to rb:
    nq = np.count_nonzero(q)
    rb2 = np.vstack((rb, np.zeros((nq, 6))))
    with StringIO() as f:
        cb.rbmultchk(f, drm101, "DRM101", rb2)
        s2 = f.getvalue()
    assert s2 == s

    # check results when b-set are last:
    drm101_last = np.hstack((drm101[:, q], drm101[:, b]))
    with StringIO() as f:
        cb.rbmultchk(f, drm101_last, "DRM101", rb, bset="last")
        s2 = f.getvalue()
    assert s2 == s

    # check results when b-set are last ... using pv:
    with StringIO() as f:
        bsetpv = np.zeros((len(b) + nq), bool)
        bsetpv[-len(b) :] = True
        cb.rbmultchk(f, drm101_last, "DRM101", rb, bset=bsetpv)
        s2 = f.getvalue()
    assert s2 == s

    with StringIO() as f:
        assert_raises(
            ValueError, cb.rbmultchk, f, drm101, "asdf", rb, bset="bad string"
        )

    # trim q-set columns out of drm:
    labels = [str(i[0]) + "  " + str(i[1]) for i in dof101]
    with StringIO() as f:
        cb.rbmultchk(
            f,
            drm101[:, b],
            "DRM101",
            rb,
            drm2=drm101[:, b],
            prtnullrows=True,
            labels=labels,
        )
        s2 = f.getvalue()

    # row 16 is now all zeros ... not comparable
    drm2 = drm101.copy()
    drm2[15] = 0
    with StringIO() as f:
        cb.rbmultchk(f, drm2, "DRM101", rb, drm2=drm2, prtnullrows=True, labels=labels)
        s3 = f.getvalue()
    assert s2 == s3

    s = s.splitlines()
    with open("tests/nas2cam_csuper/yeti_outputs/rbmultchk_yeti_101.out") as f:
        sy = f.read().splitlines()

    j = [2]
    jy = [2]
    assert comptable(s, sy, j, jy, label="Extreme ", skip=3, col=11)
    assert comptable(s, sy, j, jy, label=" Row ", skip=2, col=68)
    assert comptable(s, sy, j, jy, label=" Row ", skip=2)
    assert comptable(s, sy, j, jy, label=" Row ", skip=2)