def test_ROIEvents():

    trace = np.linspace(0, 2.0, 5)
    events = np.arange(5, dtype=int)
    roi_events = dc_types.ROIEvents()
    roi_events['trace'] = trace
    roi_events['events'] = events

    np_almost(roi_events['trace'], np.linspace(0, 2.0, 5), decimal=10)
    np_equal(roi_events['events'], np.arange(5, dtype=int))
Пример #2
0
def test_ROIDict():

    channel = dc_types.ROIChannels()
    channel['signal'] = np.array([9.2, 3.4, 6.7])
    channel['use_avg_mixing_matrix'] = False
    roi_dict = dc_types.ROIDict()
    roi_dict[9] = channel

    np_almost(roi_dict[9]['signal'], np.array([9.2, 3.4, 6.7]), decimal=9)

    assert not roi_dict[9]['use_avg_mixing_matrix']
def test_ROIEventSet():
    event_set = dc_types.ROIEventSet()
    rng = np.random.RandomState(888812)
    true_trace_s = []
    true_event_s = []
    true_trace_c = []
    true_event_c = []
    for ii in range(3):
        t = rng.random_sample(13)
        e = rng.randint(0, 111, size=13)
        signal = dc_types.ROIEvents()
        signal['trace'] = t
        signal['events'] = e
        true_trace_s.append(t)
        true_event_s.append(e)

        t = rng.random_sample(13)
        e = rng.randint(0, 111, size=13)
        crosstalk = dc_types.ROIEvents()
        crosstalk['trace'] = t
        crosstalk['events'] = e
        true_trace_c.append(t)
        true_event_c.append(e)

        channels = dc_types.ROIEventChannels()
        channels['signal'] = signal
        channels['crosstalk'] = crosstalk
        event_set[ii] = channels

    for ii in range(3):
        np_almost(event_set[ii]['signal']['trace'],
                  true_trace_s[ii], decimal=10)
        np_equal(event_set[ii]['signal']['events'],
                 true_event_s[ii])
        np_almost(event_set[ii]['crosstalk']['trace'],
                  true_trace_c[ii], decimal=10)
        np_equal(event_set[ii]['crosstalk']['events'],
                 true_event_c[ii])
    assert 0 in event_set
    assert 1 in event_set
    assert 2 in event_set
    assert 3 not in event_set
    keys = event_set.keys()
    keys.sort()
    assert keys == [0, 1, 2]
    channels = event_set.pop(1)
    np_almost(channels['signal']['trace'],
              true_trace_s[1], decimal=10)
    np_equal(channels['signal']['events'],
             true_event_s[1])
    np_almost(channels['crosstalk']['trace'],
              true_trace_c[1], decimal=10)
    np_equal(channels['crosstalk']['events'],
             true_event_c[1])
    assert 0 in event_set
    assert 2 in event_set
    assert 1 not in event_set
    keys = event_set.keys()
    keys.sort()
    assert keys == [0, 2]
def test_ROIEventChannels():
    rng = np.random.RandomState(1245)
    traces = list([rng.random_sample(10) for ii in range(2)])
    events = list([rng.randint(0, 20, size=10) for ii in range(2)])

    event_set = dc_types.ROIEventChannels()
    for ii, k in enumerate(('signal', 'crosstalk')):
        ee = dc_types.ROIEvents()
        ee['trace'] = traces[ii]
        ee['events'] = events[ii]
        event_set[k] = ee

    np_almost(event_set['signal']['trace'], traces[0], decimal=10)
    np_equal(event_set['signal']['events'], events[0])
    np_almost(event_set['crosstalk']['trace'], traces[1], decimal=10)
    np_equal(event_set['crosstalk']['events'], events[1])
Пример #5
0
def test_ROIDict_pop_and_keys():
    rng = np.random.RandomState(1123)
    s1 = rng.random_sample(10)
    c1 = rng.random_sample(10)
    s2 = rng.random_sample(14)
    c2 = rng.random_sample(14)

    channel1 = dc_types.ROIChannels()
    channel1['signal'] = s1
    channel1['crosstalk'] = c1

    channel2 = dc_types.ROIChannels()
    channel2['signal'] = s2
    channel2['crosstalk'] = c2

    roi_dict = dc_types.ROIDict()
    roi_dict[88] = channel1
    roi_dict[77] = channel2

    keys = roi_dict.keys()
    keys.sort()
    assert keys == [77, 88]

    assert 77 in roi_dict
    assert 88 in roi_dict
    assert 55 not in roi_dict

    test = roi_dict.pop(88)
    assert 77 in roi_dict
    assert 88 not in roi_dict
    assert roi_dict.keys() == [77]

    np_almost(test['signal'], s1, decimal=10)
    np_almost(test['crosstalk'], c1, decimal=10)

    np_almost(roi_dict[77]['signal'], s2, decimal=10)
    np_almost(roi_dict[77]['crosstalk'], c2, decimal=10)
Пример #6
0
def test_ROIChannels():

    signal = np.arange(9, dtype=float)
    crosstalk = np.arange(8, 17, dtype=float)
    mm = np.array([[1.2, 3.4], [5.6, 7.9]])
    p_signal = signal+0.01
    p_crosstalk = crosstalk+0.7
    p_mm = mm+0.9
    channels = dc_types.ROIChannels()
    channels['signal'] = signal
    channels['crosstalk'] = crosstalk
    channels['mixing_matrix'] = mm
    channels['poorly_converged_signal'] = p_signal
    channels['poorly_converged_crosstalk'] = p_crosstalk
    channels['poorly_converged_mixing_matrix'] = p_mm
    channels['use_avg_mixing_matrix'] = False

    np_almost(channels['signal'], signal, decimal=10)
    np_almost(channels['crosstalk'], crosstalk, decimal=10)
    np_almost(channels['mixing_matrix'], mm, decimal=10)
    np_almost(p_signal,
              channels['poorly_converged_signal'], decimal=10)
    np_almost(p_crosstalk,
              channels['poorly_converged_crosstalk'], decimal=10)
    np_almost(p_mm,
              channels['poorly_converged_mixing_matrix'], decimal=10)
    assert not channels['use_avg_mixing_matrix']
Пример #7
0
def test_ROISetDict():

    rng = np.random.RandomState(53124)
    signals = list([rng.random_sample(10) for ii in range(4)])
    crosstalks = list([rng.random_sample(10) for ii in range(4)])

    roi_set_dict = dc_types.ROISetDict()

    for ii in range(2):
        c = dc_types.ROIChannels()
        c['signal'] = signals[ii]
        c['crosstalk'] = crosstalks[ii]
        roi_set_dict['roi'][ii] = c

    for ii in range(2, 4):
        c = dc_types.ROIChannels()
        c['signal'] = signals[ii]
        c['crosstalk'] = crosstalks[ii]
        roi_set_dict['neuropil'][ii-2] = c

    np_almost(roi_set_dict['roi'][0]['signal'],
              signals[0], decimal=10)

    np_almost(roi_set_dict['roi'][1]['signal'],
              signals[1], decimal=10)

    np_almost(roi_set_dict['roi'][0]['crosstalk'],
              crosstalks[0], decimal=10)

    np_almost(roi_set_dict['roi'][1]['crosstalk'],
              crosstalks[1], decimal=10)

    np_almost(roi_set_dict['neuropil'][0]['signal'],
              signals[2], decimal=10)

    np_almost(roi_set_dict['neuropil'][1]['signal'],
              signals[3], decimal=10)

    np_almost(roi_set_dict['neuropil'][0]['crosstalk'],
              crosstalks[2], decimal=10)

    np_almost(roi_set_dict['neuropil'][1]['crosstalk'],
              crosstalks[3], decimal=10)