Exemple #1
0
def test_repr():

    detector = src.detector("Name", 2, 4)

    assert (
        detector.__repr__() ==
        "<File Name, Period: 2, n_Cycles: 4, num_procs: 1, filter_detectable: False, filter_zero: False>"
    )
def test_filter_zero():
    cwd = os.getcwd()
    cwd = cwd.split("RPx")[0]

    detector = src.detector(cwd + "RPx/datasets/young_values.txt",
                            1,
                            2,
                            filter_zero=True)

    df = detector.read_file(delim="tab")

    df = detector.filter_zero(df)

    assert df["zero"].mean() == 1
Exemple #3
0
def test_calculate_p_value_5_processes():
    cwd = os.getcwd()
    cwd = cwd.split("RPx")[0]

    detector = src.detector(
        cwd + "RPx/datasets/young_values.txt",
        1,
        2,
        filter_detectable=True,
        filter_zero=True,
        num_permutations=10,
        num_procs=5,
    )

    df = detector.read_file(delim="tab")

    df["RPx"] = df.iloc[:, 1 : (detector.config["LEN_SIGNALS"] + 1)].apply(
        detector.compute_rpx, axis=1
    )

    indexes = list(range(1, detector.config["LEN_SIGNALS"] + 1)) + [
        len(df.columns.tolist()) - 1
    ]

    start = time.time()
    df["p_values"] = df.iloc[:, indexes].apply(detector.compute_p_value, axis=1)
    end = time.time()

    print(end - start)

    p_values = df.head(10)["p_values"].tolist()

    for i in range(len(p_values)):
        if isinstance(p_values[i], float):
            p_values[i] = 0.0
    assert np.array_equal(
        p_values,
        [
            "NOTEST",
            "NOTEST",
            "NOTEST",
            "NOTEST",
            0.0,
            "NOTEST",
            "NOTEST",
            0.0,
            "NOTEST",
            0.0,
        ],
    )
def test_detect():
    cwd = os.getcwd()
    cwd = cwd.split("RPx")[0]

    detector = src.detector(
        cwd + "RPx/datasets/young_values.txt",
        1,
        2,
        filter_detectable=True,
        filter_zero=True,
        num_permutations=10,
    )

    df = detector.read_file(delim="tab")

    df = detector.detect(df)
def test_read_csv():
    cwd = os.getcwd()
    cwd = cwd.split("RPx")[0]
    detector = src.detector(cwd + "RPx/datasets/young_values.txt", 1, 2)

    df = detector.read_file(delim="tab")

    assert df.columns.tolist() == [
        "symbol",
        "ZT0_R1",
        "ZT4_R1",
        "ZT8_R1",
        "ZT12_R1",
        "ZT16_R1",
        "ZT20_R1",
        "ZT0_R2",
        "ZT4_R2",
        "ZT8_R2",
        "ZT12_R2",
        "ZT16_R2",
        "ZT20_R2",
        "detectable",
        "zero",
    ]
    assert np.array_equal(
        df.iloc[1, :].values.tolist(),
        [
            "CG2678",
            2.2014400000000003,
            2.30626,
            2.6552700000000002,
            2.65123,
            1.6633099999999998,
            1.96986,
            2.2431,
            1.67356,
            3.18127,
            2.0783,
            2.9474299999999998,
            2.12705,
            1,
            1,
        ],
    )
def test_calculate_rpx():
    cwd = os.getcwd()
    cwd = cwd.split("RPx")[0]

    detector = src.detector(cwd + "RPx/datasets/young_values.txt",
                            1,
                            2,
                            filter_detectable=True)

    df = detector.read_file(delim="tab")

    df = detector.filter_detectable(df)
    df = detector.filter_zero(df)

    df["RPx"] = df.iloc[:, 1:(detector.config["LEN_SIGNALS"] + 1)].apply(
        detector.compute_rpx, axis=1)

    RPxs = [round(x, 4) for x in df.head(5)["RPx"].tolist()]
    assert np.array_equal(RPxs, [-1.9083, -2.4264, -1.9803, -1.3145, 0.7344])
def test_calculate_mean():
    cwd = os.getcwd()
    cwd = cwd.split("RPx")[0]

    detector = src.detector(
        cwd + "RPx/datasets/young_values.txt",
        1,
        2,
        filter_detectable=True,
        filter_zero=True,
    )

    df = detector.read_file(delim="tab")

    df["mean"] = df.iloc[:, 1 : (detector.config["LEN_SIGNALS"] + 1)].apply(
        np.mean, axis=1
    )

    means = [round(x, 4) for x in df.head(5)["mean"].tolist()]

    assert np.array_equal(means, [2.3082, 16.4625, 12.9011, 261.8394, 121.8818])
Exemple #8
0
def test_init():
    assert src.detector

    detector = src.detector("Name", 2, 4)

    assert detector.config["FILE_NAME"] == "Name"
    assert detector.config["PERIOD"] == 2
    assert detector.config["N_CYCLES"] == 4

    default_config = {
        "EPS": 1e-5,
        "STAGGER": False,
        "USE_Z_SCORE": False,
        "NUM_PERMUTATIONS": 5000,
        "NUM_PROCS": 1,
        "SHUFFLE_WITH_REPLACEMENT": False,
        "MIN_RP24": 0.0,
        "FILTER_DETECTABLE": False,
        "FILTER_ZERO": False,
        "LEN_SIGNALS": None,
    }

    for param in default_config:
        assert detector.config[param] == default_config[param]
Exemple #9
0
            cfg.getint('Detector', 'cfg_size_height'))
classes_file = cfg.get('Detector', 'classes_file')
iou_thresh = cfg.getfloat('Detector', 'iou_thresh')
conf_thresh = cfg.getfloat('Detector', 'conf_thresh')
nms_thresh = cfg.getfloat('Detector', 'nms_thresh')
use_gpu = cfg.getboolean('Detector', 'use_gpu')

# tracker configs
draw_tracks = cfg.getboolean('Tracker', 'draw_tracks')
export_data = cfg.getboolean('Tracker', 'export_data')

# Initializing the Detector
detectNet = detector(weights,
                     config,
                     conf_thresh=conf_thresh,
                     netsize=cfg_size,
                     nms_thresh=nms_thresh,
                     gpu=use_gpu,
                     classes_file=classes_file)
print('Network initialized!')

###################################################################
fps, duration = 0, 0
frame_num = 0
classes = None
vid_out = None
video = None
frameA = None
Tracking = None
num_det = 0
"""