示例#1
0
def test__get_dblock_paths__required_group_not_present():

    with TMPDir() as tmpdir:

        TEST_FILE = tmpdir + "file.h5"
        TEST_GROUP = "group"

        # create empty file, no groups
        h5py.File(TEST_FILE, "w").close()

        with pytest.raises(ValueError) as group_does_not_exist_err:
            h5tools.get_dblock_paths(TEST_FILE, TEST_GROUP)

        assert "does not exist" in str(group_does_not_exist_err.value)
示例#2
0
def test__get_dblock_paths__no_dblocks():

    with TMPDir() as tmpdir:

        TEST_FILE = tmpdir + "file.h5"
        TEST_GROUP = "group"

        # create required data group, but no dblocks
        with h5py.File(TEST_FILE, "w") as tf:
            tf.create_group(TEST_GROUP)

        with pytest.raises(ValueError) as no_dblocks_err:
            h5tools.get_dblock_paths(TEST_FILE, TEST_GROUP)

        assert "No dblocks found" in str(no_dblocks_err.value)
示例#3
0
def test__get_dblock_paths__disordered_dblocks():

    with TMPDir() as tmpdir:

        TEST_FILE = tmpdir + "file.h5"
        TEST_GROUP = "group"

        with h5py.File(TEST_FILE, "w") as tf:
            grp = tf.create_group(TEST_GROUP)
            for i in range(3):
                grp.create_dataset(f"dblock_{i}", data=())
            grp.create_dataset("dblock_4", data=())

        # now have dblock_0, dblock_1, dblock_2, dblock_4
        # dblock_3 missing
        with pytest.raises(ValueError) as disordered_dblocks_err:
            h5tools.get_dblock_paths(TEST_FILE, TEST_GROUP)

        assert "Disordered dblocks" in str(disordered_dblocks_err.value)
示例#4
0
def test__get_dblock_paths__as_expected():

    with TMPDir() as tmpdir:

        TEST_FILE = tmpdir + "file.h5"
        TEST_GROUP = "group"

        with h5py.File(TEST_FILE, "w") as tf:
            grp = tf.create_group(TEST_GROUP)
            grp.create_dataset(f"dblock_1", data=())
            grp.create_dataset(f"dblock_0", data=())
            grp.create_dataset(f"dblock_2", data=())

        expected = ["group/dblock_0", "group/dblock_1", "group/dblock_2"]
        actual = h5tools.get_dblock_paths(TEST_FILE, TEST_GROUP)

        assert expected == actual
示例#5
0
def test_irb_calibrate_logpoked_cals():
    """test that calibration ignores logpoked cals"""

    pfx = "arquant2"
    h5f = IRB_DIR / "mkh5" / "logpoked_cals_test.h5"
    mydat = mkh5.mkh5(h5f)
    mydat.reset_all()  # a = read/write, create if needed
    mydat.create_mkdata(pfx, *GET_IRB_MKDIG(pfx))
    mydat.calibrate_mkdata(
        pfx,
        n_points=3,  # pts to average, either side of cursor
        cal_size=10,  # uV
        polarity=1,  # of calibration pulse
        lo_cursor=-50,  # ms
        hi_cursor=50,
        cal_ccode=0,
        use_cals=None,
    )

    hio = mydat.HeaderIO()
    dblock_paths = h5tools.get_dblock_paths(h5f, pfx)
    lo_gain_chans = ["lle", "lhz", "rle", "rhz", "MiPf", "LLPf", "RLPf"]

    with h5py.File(h5f, "r+") as h5:
        for dbp in dblock_paths:
            dblock = h5[dbp]
            hio.get(dblock)
            streams = hio.header["streams"]
            for k, stream in streams.items():
                if "dig_chan_" in stream["source"]:
                    scale_by = None
                    scale_by = abs(stream["cals"]["scale_by"])
                    if stream["name"] in lo_gain_chans:
                        assert 17.0 < scale_by and scale_by < 22.0
                    else:
                        assert 34.0 < scale_by and scale_by < 44.0