Exemplo n.º 1
0
def test_read_raw_on_test_data():
    import glob
    from pyrerp.test import test_data_path
    tested = 0
    for rawp in glob.glob(test_data_path("erpss/*.raw")):
        crwp = rawp[:-3] + "crw"
        print rawp, crwp
        assert_files_match(rawp, crwp)
        tested += 1
    # Cross-check, to make sure is actually finding the files... (bump up this
    # number if you add more test files):
    assert tested == 5
Exemplo n.º 2
0
def test_read_raw_on_test_data():
    import glob
    from pyrerp.test import test_data_path
    tested = 0
    for rawp in glob.glob(test_data_path("erpss/*.raw")):
        crwp = rawp[:-3] + "crw"
        print rawp, crwp
        assert_files_match(rawp, crwp)
        tested += 1
    # Cross-check, to make sure is actually finding the files... (bump up this
    # number if you add more test files):
    assert tested == 5
Exemplo n.º 3
0
def test_64bit_channel_names():
    from pyrerp.test import test_data_path
    stream = open(test_data_path("erpss/two-chunks-64chan.raw"))
    (hz, channel_names, codes, data, info) = read_raw(stream, int)
    # "Correct" channel names as listed by headinfo(1):
    assert (channel_names == [
        "LOPf", "ROPf", "LMPf", "RMPf", "LTPf", "RTPf", "LLPf", "RLPf", "LPrA",
        "RPrA", "LTFr", "RTFr", "LLFr", "RLFr", "LDPf", "RDPf", "LTOc", "RTOc",
        "LTCe", "RTCe", "LLCe", "RLCe", "LDFr", "RDFr", "LMFr", "RMFr", "MiFo",
        "MiPf", "MiFr", "A2", "LHEy", "RHEy", "LIOc", "RIOc", "LLOc", "RLOc",
        "LLPP", "RLPP", "LLPa", "RLPa", "LDCe", "RDCe", "LMCe", "RMCe", "LDOc",
        "RDOc", "LDPP", "RDPP", "LDPa", "RDPa", "LCer", "RCer", "LMOc", "RMOc",
        "LMPP", "RMPP", "LMPa", "RMPa", "MiCe", "MiPa", "MiPP", "MiOc", "LLEy",
        "RLEy"
    ]).all()
Exemplo n.º 4
0
def test_64bit_channel_names():
    from pyrerp.test import test_data_path
    stream = open(test_data_path("erpss/two-chunks-64chan.raw"))
    (hz, channel_names, codes, data, info) = read_raw(stream, int)
    # "Correct" channel names as listed by headinfo(1):
    assert (channel_names ==
            ["LOPf", "ROPf", "LMPf", "RMPf", "LTPf", "RTPf", "LLPf", "RLPf",
             "LPrA",  "RPrA", "LTFr", "RTFr", "LLFr", "RLFr", "LDPf", "RDPf",
             "LTOc", "RTOc", "LTCe", "RTCe", "LLCe", "RLCe", "LDFr", "RDFr",
             "LMFr", "RMFr", "MiFo", "MiPf", "MiFr", "A2",   "LHEy", "RHEy",
             "LIOc", "RIOc", "LLOc", "RLOc", "LLPP", "RLPP", "LLPa", "RLPa",
             "LDCe", "RDCe", "LMCe", "RMCe", "LDOc", "RDOc", "LDPP", "RDPP",
             "LDPa", "RDPa", "LCer", "RCer", "LMOc", "RMOc", "LMPP", "RMPP",
             "LMPa", "RMPa", "MiCe", "MiPa", "MiPP", "MiOc", "LLEy", "RLEy"]
            ).all()
Exemplo n.º 5
0
def test_load_erpss():
    from pyrerp.test import test_data_path
    # This crw/log file is constructed to have a few features:
    # - it only has 3 records, so it's tiny
    # - the first two records are in one recspan, the last is in a second, so
    #   we test the recspan splitting code
    # - the first recspan ends in a PAUSE event, the second ends in a DELETE
    #   event, so we test the deleted event handling.
    # There are some weird things about it too:
    # - several events in the first recspan have condition 0, to test
    #   calibration pulse stuff. In a normal ERPSS file all events within a
    #   single recspan would have the same condition number.
    # - most of the event codes are >32767. In a normal ERPSS file such events
    #   are supposed to be reserved for special stuff and deleted events, but
    #   it happens the file I was using as a basis violated this rule. Oh
    #   well.
    dataset = load_erpss(test_data_path("erpss/tiny-complete.crw"),
                         test_data_path("erpss/tiny-complete.log"))
    assert len(dataset) == 2
    assert dataset[0].shape == (512, 32)
    assert dataset[1].shape == (256, 32)

    assert dataset.data_format.exact_sample_rate_hz == 250
    assert dataset.data_format.units == "RAW"
    assert list(dataset.data_format.channel_names) == [
        "lle",
        "lhz",
        "MiPf",
        "LLPf",
        "RLPf",
        "LMPf",
        "RMPf",
        "LDFr",
        "RDFr",
        "LLFr",
        "RLFr",
        "LMFr",
        "RMFr",
        "LMCe",
        "RMCe",
        "MiCe",
        "MiPa",
        "LDCe",
        "RDCe",
        "LDPa",
        "RDPa",
        "LMOc",
        "RMOc",
        "LLTe",
        "RLTe",
        "LLOc",
        "RLOc",
        "MiOc",
        "A2",
        "HEOG",
        "rle",
        "rhz",
    ]

    for recspan_info in dataset.recspan_infos:
        assert recspan_info["raw_file"].endswith("tiny-complete.crw")
        assert recspan_info["log_file"].endswith("tiny-complete.log")
        assert recspan_info["experiment"] == "brown-1"
        assert recspan_info["subject"] == "Subject p3 2008-08-20"
        assert recspan_info["odelay"] == 8
        assert len(recspan_info["erpss_raw_header"]) == 512

    assert dataset.recspan_infos[0].ticks == 512
    assert dataset.recspan_infos[1].ticks == 256
    assert dataset.recspan_infos[1]["deleted"]

    assert len(dataset.events()) == 14
    # 2 are calibration events
    assert len(dataset.events("has code")) == 12
    for ev in dataset.events("has code"):
        assert ev["condition"] in (64, 65)
        assert ev["flag"] == 0
        assert not ev["flag_data_error"]
        assert not ev["flag_polinv"]
        assert not ev["flag_rejected"]
    for ev in dataset.events("calibration_pulse"):
        assert dict(ev) == {"calibration_pulse": True}

    def check_ticks(query, recspan_ids, start_ticks):
        events = dataset.events(query)
        assert len(events) == len(recspan_ids) == len(start_ticks)
        for ev, recspan_id, start_tick in zip(events, recspan_ids,
                                              start_ticks):
            assert ev.recspan_id == recspan_id
            assert ev.start_tick == start_tick
            assert ev.stop_tick == start_tick + 1

    check_ticks("condition == 64", [0] * 8,
                [21, 221, 304, 329, 379, 458, 483, 511])
    check_ticks("condition == 65", [1] * 4,
                [533 - 512, 733 - 512, 762 - 512, 767 - 512])
    check_ticks("calibration_pulse", [0, 0], [250, 408])

    # check calibration_events option
    dataset2 = load_erpss(test_data_path("erpss/tiny-complete.crw"),
                          test_data_path("erpss/tiny-complete.log"),
                          calibration_events="condition == 65")
    assert len(dataset2.events("condition == 65")) == 0
    assert len(dataset2.events("condition == 0")) == 2
    assert len(dataset2.events("calibration_pulse")) == 4

    # check that we can load from file handles (not sure if anyone cares but
    # hey you never know...)
    assert len(
        load_erpss(open(test_data_path("erpss/tiny-complete.crw")),
                   open(test_data_path("erpss/tiny-complete.log")))) == 2

    # check that code/raw mismatch is detected
    from nose.tools import assert_raises
    for bad in ["bad-code", "bad-tick", "bad-tick2"]:
        assert_raises(ValueError, load_erpss,
                      test_data_path("erpss/tiny-complete.crw"),
                      test_data_path("erpss/tiny-complete.%s.log" % (bad, )))

    # test .transform and .copy
    from pyrerp.test_data import check_transforms
    check_transforms(
        load_erpss(test_data_path("erpss/tiny-complete.crw"),
                   test_data_path("erpss/tiny-complete.log")))
Exemplo n.º 6
0
def test_load_erpss():
    from pyrerp.test import test_data_path
    # This crw/log file is constructed to have a few features:
    # - it only has 3 records, so it's tiny
    # - the first two records are in one recspan, the last is in a second, so
    #   we test the recspan splitting code
    # - the first recspan ends in a PAUSE event, the second ends in a DELETE
    #   event, so we test the deleted event handling.
    # There are some weird things about it too:
    # - several events in the first recspan have condition 0, to test
    #   calibration pulse stuff. In a normal ERPSS file all events within a
    #   single recspan would have the same condition number.
    # - most of the event codes are >32767. In a normal ERPSS file such events
    #   are supposed to be reserved for special stuff and deleted events, but
    #   it happens the file I was using as a basis violated this rule. Oh
    #   well.
    dataset = load_erpss(test_data_path("erpss/tiny-complete.crw"),
                          test_data_path("erpss/tiny-complete.log"))
    assert len(dataset) == 2
    assert dataset[0].shape == (512, 32)
    assert dataset[1].shape == (256, 32)

    assert dataset.data_format.exact_sample_rate_hz == 250
    assert dataset.data_format.units == "RAW"
    assert list(dataset.data_format.channel_names) == [
        "lle", "lhz", "MiPf", "LLPf", "RLPf", "LMPf", "RMPf", "LDFr", "RDFr",
        "LLFr", "RLFr", "LMFr", "RMFr", "LMCe", "RMCe", "MiCe", "MiPa", "LDCe",
        "RDCe", "LDPa", "RDPa", "LMOc", "RMOc", "LLTe", "RLTe", "LLOc", "RLOc",
        "MiOc", "A2", "HEOG", "rle", "rhz",
        ]

    for recspan_info in dataset.recspan_infos:
        assert recspan_info["raw_file"].endswith("tiny-complete.crw")
        assert recspan_info["log_file"].endswith("tiny-complete.log")
        assert recspan_info["experiment"] == "brown-1"
        assert recspan_info["subject"] == "Subject p3 2008-08-20"
        assert recspan_info["odelay"] == 8
        assert len(recspan_info["erpss_raw_header"]) == 512

    assert dataset.recspan_infos[0].ticks == 512
    assert dataset.recspan_infos[1].ticks == 256
    assert dataset.recspan_infos[1]["deleted"]

    assert len(dataset.events()) == 14
    # 2 are calibration events
    assert len(dataset.events("has code")) == 12
    for ev in dataset.events("has code"):
        assert ev["condition"] in (64, 65)
        assert ev["flag"] == 0
        assert not ev["flag_data_error"]
        assert not ev["flag_polinv"]
        assert not ev["flag_rejected"]
    for ev in dataset.events("calibration_pulse"):
        assert dict(ev) == {"calibration_pulse": True}
    def check_ticks(query, recspan_ids, start_ticks):
        events = dataset.events(query)
        assert len(events) == len(recspan_ids) == len(start_ticks)
        for ev, recspan_id, start_tick in zip(events, recspan_ids, start_ticks):
            assert ev.recspan_id == recspan_id
            assert ev.start_tick == start_tick
            assert ev.stop_tick == start_tick + 1

    check_ticks("condition == 64",
                [0] * 8, [21, 221, 304, 329, 379, 458, 483, 511])
    check_ticks("condition == 65",
                [1] * 4,
                [533 - 512, 733 - 512, 762 - 512, 767 - 512])
    check_ticks("calibration_pulse", [0, 0], [250, 408])

    # check calibration_events option
    dataset2 = load_erpss(test_data_path("erpss/tiny-complete.crw"),
                          test_data_path("erpss/tiny-complete.log"),
                          calibration_events="condition == 65")
    assert len(dataset2.events("condition == 65")) == 0
    assert len(dataset2.events("condition == 0")) == 2
    assert len(dataset2.events("calibration_pulse")) == 4

    # check that we can load from file handles (not sure if anyone cares but
    # hey you never know...)
    assert len(load_erpss(open(test_data_path("erpss/tiny-complete.crw")),
                          open(test_data_path("erpss/tiny-complete.log")))) == 2

    # check that code/raw mismatch is detected
    from nose.tools import assert_raises
    for bad in ["bad-code", "bad-tick", "bad-tick2"]:
        assert_raises(ValueError,
                      load_erpss,
                      test_data_path("erpss/tiny-complete.crw"),
                      test_data_path("erpss/tiny-complete.%s.log" % (bad,)))

    # test .transform and .copy
    from pyrerp.test_data import check_transforms
    check_transforms(load_erpss(test_data_path("erpss/tiny-complete.crw"),
                                test_data_path("erpss/tiny-complete.log")))