Skip to content

Commit 2a5b2be

Browse files
authored
Merge pull request #1114 from AllenInstitute/1101/session-analysis-nightly
1101 update 2p session analysis nightly tests for recent scipy
2 parents 6a9465f + 32f4873 commit 2a5b2be

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

allensdk/brain_observatory/stimulus_analysis.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ def get_speed_tuning(self, binsize):
465465
nc, start_max * binsize:(start_max + 1) * binsize]
466466
other_values = np.delete(celltraces_sorted_sp[nc, :], range(
467467
start_max * binsize, (start_max + 1) * binsize))
468-
(_, peak_run.ptest_sp[nc]) = st.ks_2samp(
468+
(_, peak_run.ptest_sp[nc]) = nonraising_ks_2samp(
469469
test_values, other_values)
470470
else:
471471
test_values = celltraces_sorted_sp[
472472
nc, start_min * binsize:(start_min + 1) * binsize]
473473
other_values = np.delete(celltraces_sorted_sp[nc, :], range(
474474
start_min * binsize, (start_min + 1) * binsize))
475-
(_, peak_run.ptest_sp[nc]) = st.ks_2samp(
475+
(_, peak_run.ptest_sp[nc]) = nonraising_ks_2samp(
476476
test_values, other_values)
477477
temp = binned_cells_vis[nc, :, 0]
478478
start_max = temp.argmax()
@@ -489,7 +489,7 @@ def get_speed_tuning(self, binsize):
489489
nc, start_min * binsize:(start_min + 1) * binsize]
490490
other_values = np.delete(celltraces_sorted_vis[nc, :], range(
491491
start_min * binsize, (start_min + 1) * binsize))
492-
(_, peak_run.ptest_vis[nc]) = st.ks_2samp(
492+
(_, peak_run.ptest_vis[nc]) = nonraising_ks_2samp(
493493
test_values, other_values)
494494

495495
return binned_dx_sp, binned_cells_sp, binned_dx_vis, binned_cells_vis, peak_run
@@ -581,3 +581,13 @@ def row_from_cell_id(self, csid=None, idx=None):
581581
else:
582582
raise Exception("Could not find row for csid(%s) idx(%s)" % (str(csid), str(idx)))
583583

584+
585+
def nonraising_ks_2samp(data1, data2, **kwargs):
586+
""" scipy.stats.ks_2samp now raises a ValueError if one of the input arrays
587+
is of length 0. Previously it signaled this case by returning nans. This
588+
function restores the prior behavior.
589+
"""
590+
591+
if min(len(data1), len(data2)) == 0:
592+
return (np.nan, np.nan)
593+
return st.ks_2samp(data1, data2, **kwargs)

allensdk/test/brain_observatory/test_session_analysis.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ def mock_stimulus_table(dset, name):
4747
t = _orig_get_stimulus_table(dset, name)
4848
t.set_value(0, 'end',
4949
t.loc[0,'start'] + 10)
50-
50+
5151
return t
5252

5353

5454
@pytest.fixture
5555
def session_a():
56-
filename = '/data/informatics/module_test_data/observatory/test_nwb/out_510390912.nwb'
56+
filename = os.path.abspath(os.path.join(
57+
"/", "allen", "aibs", "informatics", "module_test_data",
58+
"observatory", "test_nwb", "out_510390912.nwb"
59+
))
5760
save_path = 'xyza'
5861

5962
sa = SessionAnalysis(filename, save_path)
@@ -63,7 +66,10 @@ def session_a():
6366

6467
@pytest.fixture
6568
def session_b():
66-
filename = '/data/informatics/module_test_data/observatory/test_nwb/506278598.nwb'
69+
filename = os.path.abspath(os.path.join(
70+
"/", "allen", "aibs", "informatics", "module_test_data",
71+
"observatory", "test_nwb", "506278598.nwb"
72+
))
6773
save_path = 'xyzb'
6874

6975
sa = SessionAnalysis(filename, save_path)
@@ -73,7 +79,10 @@ def session_b():
7379

7480
@pytest.fixture
7581
def session_c():
76-
filename = '/data/informatics/module_test_data/observatory/test_nwb/out_510221121.nwb'
82+
filename = os.path.abspath(os.path.join(
83+
"/", "allen", "aibs", "informatics", "module_test_data",
84+
"observatory", "test_nwb", "out_510221121.nwb"
85+
))
7786
save_path = 'xyzc'
7887

7988
sa = SessionAnalysis(filename, save_path)

0 commit comments

Comments
 (0)