diff --git a/allensdk/brain_observatory/ecephys/optotagging.py b/allensdk/brain_observatory/ecephys/optotagging.py index dc7eb78d7..4e568ec5d 100644 --- a/allensdk/brain_observatory/ecephys/optotagging.py +++ b/allensdk/brain_observatory/ecephys/optotagging.py @@ -15,7 +15,7 @@ def __init__(self, table: pd.DataFrame): # pre-processed optotagging_table may use. table = \ table.rename(columns={"name": "stimulus_name"}) - + table.index = table.index.rename('id') super().__init__(name='optotaggging_table', value=table) @property diff --git a/allensdk/test/brain_observatory/ecephys/test_ecephys_project_lims_api.py b/allensdk/test/brain_observatory/ecephys/test_ecephys_project_lims_api.py index bb718ec57..05bb5b063 100644 --- a/allensdk/test/brain_observatory/ecephys/test_ecephys_project_lims_api.py +++ b/allensdk/test/brain_observatory/ecephys/test_ecephys_project_lims_api.py @@ -1,4 +1,3 @@ -import os import re from unittest import mock @@ -39,7 +38,7 @@ def __call__(self, query, *args, **kwargs): "no_pa_check": lambda st: "published_at" not in st }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], @@ -48,10 +47,11 @@ def __call__(self, query, *args, **kwargs): {"session_ids": [1, 2, 3]}, pd.DataFrame({"id": [5, 6], "something": [12, 14]}), { - "filters_sessions": lambda st: re.compile(r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None + "filters_sessions": lambda st: re.compile( + r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], @@ -60,10 +60,11 @@ def __call__(self, query, *args, **kwargs): {"unit_ids": [1, 2, 3]}, pd.DataFrame({"id": [5, 6], "something": [12, 14]}), { - "filters_units": lambda st: re.compile(r".+and eu.id in \(1,2,3\).*", re.DOTALL).match(st) is not None + "filters_units": lambda st: re.compile( + r".+and eu.id in \(1,2,3\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], @@ -72,11 +73,14 @@ def __call__(self, query, *args, **kwargs): {"channel_ids": [1, 2, 3], "probe_ids": [4, 5, 6]}, pd.DataFrame({"id": [5, 6], "something": [12, 14]}), { - "filters_channels": lambda st: re.compile(r".+and ec.id in \(1,2,3\).*", re.DOTALL).match(st) is not None, - "filters_probes": lambda st: re.compile(r".+and ep.id in \(4,5,6\).*", re.DOTALL).match(st) is not None + "filters_channels": lambda st: re.compile( + r".+and ec.id in \(1,2,3\).*", re.DOTALL).match( + st) is not None, + "filters_probes": lambda st: re.compile( + r".+and ep.id in \(4,5,6\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], @@ -85,11 +89,15 @@ def __call__(self, query, *args, **kwargs): {"published_at": "2019-10-22"}, pd.DataFrame({"id": [5, 6], "something": [12, 14]}), { - "checks_pa_not_null": lambda st: re.compile(r".+and es.published_at is not null.*", re.DOTALL).match(st) is not None, - "checks_pa": lambda st: re.compile(r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match(st) is not None + "checks_pa_not_null": lambda st: re.compile( + r".+and es.published_at is not null.*", re.DOTALL).match( + st) is not None, + "checks_pa": lambda st: re.compile( + r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match( + st) is not None }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], @@ -98,12 +106,17 @@ def __call__(self, query, *args, **kwargs): {"published_at": "2019-10-22", "session_ids": [1, 2, 3]}, pd.DataFrame({"id": [5, 6], "something": [12, 14]}), { - "checks_pa_not_null": lambda st: re.compile(r".+and es.published_at is not null.*", re.DOTALL).match(st) is not None, - "checks_pa": lambda st: re.compile(r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match(st) is not None, - "filters_sessions": lambda st: re.compile(r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None + "checks_pa_not_null": lambda st: re.compile( + r".+and es.published_at is not null.*", re.DOTALL).match( + st) is not None, + "checks_pa": lambda st: re.compile( + r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match( + st) is not None, + "filters_sessions": lambda st: re.compile( + r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], @@ -112,63 +125,81 @@ def __call__(self, query, *args, **kwargs): {"published_at": "2019-10-22", "session_ids": [1, 2, 3]}, pd.DataFrame({"id": [5, 6], "something": [12, 14]}), { - "checks_pa_not_null": lambda st: re.compile(r".+and es.published_at is not null.*", re.DOTALL).match(st) is not None, - "checks_pa": lambda st: re.compile(r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match(st) is not None, - "filters_sessions": lambda st: re.compile(r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None + "checks_pa_not_null": lambda st: re.compile( + r".+and es.published_at is not null.*", re.DOTALL).match( + st) is not None, + "checks_pa": lambda st: re.compile( + r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match( + st) is not None, + "filters_sessions": lambda st: re.compile( + r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"something": [12, 14]}, + {"something": [12, 14]}, index=pd.Index(name="id", data=[5, 6]) ) ], [ "get_sessions", {"published_at": "2019-10-22", "session_ids": [1, 2, 3]}, - pd.DataFrame({"id": [5, 6], "something": [12, 14], "genotype": ["foo", np.nan]}), + pd.DataFrame({"id": [5, 6], "something": [12, 14], + "genotype": ["foo", np.nan]}), { - "checks_pa_not_null": lambda st: re.compile(r".+and es.published_at is not null.*", re.DOTALL).match(st) is not None, - "checks_pa": lambda st: re.compile(r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match(st) is not None, - "filters_sessions": lambda st: re.compile(r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None + "checks_pa_not_null": lambda st: re.compile( + r".+and es.published_at is not null.*", re.DOTALL).match( + st) is not None, + "checks_pa": lambda st: re.compile( + r".+and es.published_at <= '2019-10-22'.*", re.DOTALL).match( + st) is not None, + "filters_sessions": lambda st: re.compile( + r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"something": [12, 14], "genotype": ["foo", "wt"]}, + {"something": [12, 14], "genotype": ["foo", "wt"]}, index=pd.Index(name="id", data=[5, 6]) ) ], [ "get_unit_analysis_metrics", {"ecephys_session_ids": [1, 2, 3]}, - pd.DataFrame({"id": [5, 6], "data": [{"a": 1, "b": 2}, {"a": 3, "b": 4}], "ecephys_unit_id": [10, 11]}), + pd.DataFrame( + {"id": [5, 6], "data": [{"a": 1, "b": 2}, {"a": 3, "b": 4}], + "ecephys_unit_id": [10, 11]}), { - "filters_sessions": lambda st: re.compile(r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None + "filters_sessions": lambda st: re.compile( + r".+and es.id in \(1,2,3\).*", re.DOTALL).match(st) is not None }, pd.DataFrame( - {"id": [5, 6], "a": [1, 3], "b": [2, 4]}, - index=pd.Index(name="iecephys_unit_id", data=[10, 11]) + {"id": [5, 6], "a": [1, 3], "b": [2, 4]}, + index=pd.Index(name="ecephys_unit_id", data=[10, 11]) ) ] ]) def test_pg_query(method_name, kwargs, response, checks, expected): - selector = MockSelector(checks, response) - with mock.patch("allensdk.internal.api.psycopg2_select", new=selector) as ptc: - api = epla.EcephysProjectLimsApi.default(lims_credentials=mock_lims_credentials) + with mock.patch("allensdk.internal.api.psycopg2_select", + new=selector) as ptc: + api = epla.EcephysProjectLimsApi.default( + lims_credentials=mock_lims_credentials) obtained = getattr(api, method_name)(**kwargs) - pd.testing.assert_frame_equal(expected, obtained, check_like=True, check_dtype=False) + pd.testing.assert_frame_equal(expected, obtained, check_like=True, + check_dtype=False) any_checks_failed = False for name, result in ptc.passed.items(): if not result: print(f"check {name} failed") any_checks_failed = True - + if any_checks_failed: print(ptc.query) assert not any_checks_failed WKF_ID = 12345 + + class MockPgEngine: def __init__(self, query_pattern): @@ -220,8 +251,8 @@ def stream(self, url): ] ]) def test_file_getter(method, kwargs, query_pattern, pg_engine_cls): - api = epla.EcephysProjectLimsApi( - postgres_engine=pg_engine_cls(query_pattern), app_engine=MockHttpEngine() + postgres_engine=pg_engine_cls(query_pattern), + app_engine=MockHttpEngine() ) - getattr(api, method)(**kwargs) \ No newline at end of file + getattr(api, method)(**kwargs) diff --git a/allensdk/test/brain_observatory/ecephys/test_ecephys_session.py b/allensdk/test/brain_observatory/ecephys/test_ecephys_session.py index 926865a6c..ac76a7b6b 100644 --- a/allensdk/test/brain_observatory/ecephys/test_ecephys_session.py +++ b/allensdk/test/brain_observatory/ecephys/test_ecephys_session.py @@ -300,7 +300,7 @@ def test_get_stimulus_presentations(valid_stimulus_table_api): "stimulus_name": ['invalid_presentation', 'invalid_presentation', 'a', 'a_movie'], "phase": [np.nan, np.nan, 120.0, 180.0] - }, index=pd.Index(name='stimulus_presentations_id', data=[0, 1, 2, 3])) + }, index=pd.Index(name='stimulus_presentation_id', data=[0, 1, 2, 3])) session = EcephysSession(api=valid_stimulus_table_api) obtained = session.stimulus_presentations[["start_time", @@ -323,7 +323,7 @@ def test_get_stimulus_presentations_no_invalid_times(just_stim_table_api): "stop_time": [1/2, 1, 3/2, 2], 'stimulus_name': ['a', 'a', 'a', 'a_movie'], - }, index=pd.Index(name='stimulus_presentations_id', data=[0, 1, 2, 3])) + }, index=pd.Index(name='stimulus_presentation_id', data=[0, 1, 2, 3])) session = EcephysSession(api=just_stim_table_api) @@ -468,8 +468,8 @@ def test_empty_presentationwise_spike_times(spike_times_api): session.stimulus_presentations.index.values, session.units.index.values) - assert(isinstance(obtained, pd.DataFrame)) - assert(obtained.empty) + assert isinstance(obtained, pd.DataFrame) + assert obtained.empty def test_conditionwise_spike_statistics(spike_times_api): @@ -503,11 +503,11 @@ def test_empty_conditionwise_spike_statistics(spike_times_api): stimulus_presentation_ids=session.stimulus_presentations.index.values, unit_ids=session.units.index.values ) - assert(len(obtained) == 12) - assert(not np.any(obtained['spike_count'])) # check all spike_counts are 0 - assert(not np.any(obtained['spike_mean'])) # spike_means are 0 - assert(np.all(np.isnan(obtained['spike_std']))) # std/sem is undefined - assert(np.all(np.isnan(obtained['spike_sem']))) + assert len(obtained) == 12 + assert not np.any(obtained['spike_count']) # check all spike_counts are 0 + assert not np.any(obtained['spike_mean']) # spike_means are 0 + assert np.all(np.isnan(obtained['spike_std'])) # std/sem is undefined + assert np.all(np.isnan(obtained['spike_sem'])) def test_get_stimulus_parameter_values(just_stim_table_api): diff --git a/allensdk/test/brain_observatory/ecephys/test_write_nwb.py b/allensdk/test/brain_observatory/ecephys/test_write_nwb.py index afd0f5906..00f66c443 100644 --- a/allensdk/test/brain_observatory/ecephys/test_write_nwb.py +++ b/allensdk/test/brain_observatory/ecephys/test_write_nwb.py @@ -215,7 +215,8 @@ def test_add_stimulus_presentations_color( "level": [10., 9., 8., 7.], "condition": ["a", "a", "b", "c"], "stimulus_name": ["w", "x", "y", "z"], - "duration": [0.5, 0.5, 0.5, 0.5]})), + "duration": [0.5, 0.5, 0.5, 0.5]}, + index=pd.Index(name="id", data=[0, 1, 2, 3]))), (pd.DataFrame({"start_time": [0., 1., 2., 3.], "stop_time": [0.5, 1.5, 2.5, 3.5], @@ -239,6 +240,7 @@ def test_add_optotagging_table_to_nwbfile( if expected is None: expected = opto_table.value + expected.index.name = 'id' pd.testing.assert_frame_equal(obtained, expected, check_like=True) @@ -1243,7 +1245,8 @@ def test_add_eye_tracking_rig_geometry_data_to_nwbfile(nwbfile, "eye_height": [6.] * 5, "eye_width": [6.] * 5, "eye_phi": [3.] * 5}, - index=[3., 4., 5., 6., 7.]), + index=pd.Index(name="Time (s)", + data=[3., 4., 5., 6., 7.])), # expected_gaze_data pd.DataFrame({"raw_eye_area": [3., 5., 7., 9., 11.], "raw_pupil_area": [2., 4., 6., 8., 10.], @@ -1281,7 +1284,8 @@ def test_add_eye_tracking_rig_geometry_data_to_nwbfile(nwbfile, np.nan, 8., 10.]}, - index=[3., 4., 5., 6., 7.]) + index=pd.Index(name="Time (s)", + data=[3., 4., 5., 6., 7.])) ), ]) def test_add_eye_tracking_data_to_nwbfile(nwbfile, diff --git a/allensdk/test/brain_observatory/receptive_field_analysis/test_chisquarerf.py b/allensdk/test/brain_observatory/receptive_field_analysis/test_chisquarerf.py index ffc597b34..57cae07df 100644 --- a/allensdk/test/brain_observatory/receptive_field_analysis/test_chisquarerf.py +++ b/allensdk/test/brain_observatory/receptive_field_analysis/test_chisquarerf.py @@ -38,42 +38,40 @@ import pytest -from scipy.ndimage.interpolation import zoom import scipy.stats as stats import numpy as np -from allensdk.brain_observatory.receptive_field_analysis import chisquarerf as chi +from allensdk.brain_observatory.receptive_field_analysis import \ + chisquarerf as chi @pytest.fixture def rf_events(): - np.random.seed(12) def make(receptive_field_mask, lsn): - activity = np.logical_or(lsn == 255, lsn==0) - return np.logical_and(activity, receptive_field_mask).sum(axis=(1, 2))[:, None] + activity = np.logical_or(lsn == 255, lsn == 0) + return np.logical_and(activity, receptive_field_mask).sum(axis=(1, 2))[ + :, None] return make @pytest.fixture def locally_sparse_noise(): - def make(ntr, nr, nc): - return np.around(np.random.rand(ntr, nr, nc)*255).astype(int) + return np.around(np.random.rand(ntr, nr, nc) * 255).astype(int) return make @pytest.fixture def rf_mask(): - def make(nr, nc, slices): mask = np.zeros((nr, nc)) - mask[slices] = 1 + mask[slices[0][0]:slices[0][-1], slices[1][0]:slices[1][-1]] = 1 return mask - + return make @@ -86,19 +84,17 @@ def exclusion_mask(): @pytest.fixture def events_per_pixel(): - epp = np.zeros((2, 4, 4, 2)) epp[0, 0, 0, 0] = 2 epp[0, 0, 0, 1] = 3 epp[1, 3, 3, 0] = 5 epp[1, 1, 0, 0] = 4 - + return epp @pytest.fixture def trials_per_pixel(): - tpp = np.zeros((4, 4, 2)) tpp[:, :, 0] = 2 tpp[:, :, 1] = 0 @@ -107,10 +103,10 @@ def trials_per_pixel(): # not testing d < 1 here -@pytest.mark.parametrize('r,c,d', [[2, 3, 4], [28, 16, 3], [28, 16, 2], [10, 20, 12]]) +@pytest.mark.parametrize('r,c,d', + [[2, 3, 4], [28, 16, 3], [28, 16, 2], [10, 20, 12]]) def test_interpolate_rf(r, c, d): - - image = np.arange( r * c ).reshape([ r, c ]) + image = np.arange(r * c).reshape([r, c]) delta_col = 1.0 / d delta_row = c * delta_col @@ -118,43 +114,40 @@ def test_interpolate_rf(r, c, d): obtained = chi.interpolate_RF(image, d) grad = np.gradient(obtained) - assert(np.allclose( grad[0], np.zeros_like(grad[0]) + delta_row )) - assert(np.allclose( grad[1], np.zeros_like(grad[1]) + delta_col )) + assert (np.allclose(grad[0], np.zeros_like(grad[0]) + delta_row)) + assert (np.allclose(grad[1], np.zeros_like(grad[1]) + delta_col)) # tests integration with interpolate # not testing case where r, c are small @pytest.mark.parametrize('r,c,d', [[28, 16, 3], [28, 16, 2], [10, 20, 12]]) def test_deinterpolate_rf(r, c, d): - - image = np.arange( r * c ).reshape([ r, c ]) + image = np.arange(r * c).reshape([r, c]) interp = chi.interpolate_RF(image, d) obt = chi.deinterpolate_RF(interp, c, r, d) - assert(np.allclose( image, obt )) + assert (np.allclose(image, obt)) def test_smooth_sta(): - image = np.eye(10) smoothed = chi.smooth_STA(image) - + thresholded = smoothed.copy() thresholded[thresholded < 0.5] = 0 thresholded[thresholded > 0.5] = 1 - assert(np.allclose( smoothed.T, smoothed )) - assert(np.allclose( image, thresholded )) - assert( np.count_nonzero(smoothed) > np.count_nonzero(image) ) + assert (np.allclose(smoothed.T, smoothed)) + assert (np.allclose(image, thresholded)) + assert (np.count_nonzero(smoothed) > np.count_nonzero(image)) def test_build_trial_matrix(): - tr0 = np.eye(16) * 255 tr1 = np.arange(256).reshape((16, 16)) - lsn_template = np.array([ tr0, tr1 ]) + lsn_template = np.array([tr0, tr1]) exp = np.zeros((16, 16, 2, 2)) exp[:, :, 0, 0] = np.eye(16) @@ -162,23 +155,28 @@ def test_build_trial_matrix(): exp[15, 15, 0, 1] = 1 exp[0, 0, 1, 1] = 1 - obt = chi.build_trial_matrix( lsn_template, 2 ) - assert(np.allclose( exp, obt )) + obt = chi.build_trial_matrix(lsn_template, 2) + assert (np.allclose(exp, obt)) -def test_get_expected_events_by_pixel(exclusion_mask, events_per_pixel, trials_per_pixel): +def test_get_expected_events_by_pixel(exclusion_mask, events_per_pixel, + trials_per_pixel): + obt = chi.get_expected_events_by_pixel(exclusion_mask, events_per_pixel, + trials_per_pixel) - obt = chi.get_expected_events_by_pixel(exclusion_mask, events_per_pixel, trials_per_pixel) + assert (obt[ + 0, 0, 0, 0] == 0.625) # 5 events, 8 trials (events counted + # even if 0 trials) + assert (obt[1, 1, 0, 0] == 0.5) # 4 events, 8 trials + assert (obt[0, 0, 0, 1] == 0.0) # no trials + assert (obt[1, 3, 3, 0] == 0.0) # out of mask - assert( obt[0, 0, 0, 0] == 0.625 ) # 5 events, 8 trials (events counted even if 0 trials) - assert( obt[1, 1, 0, 0] == 0.5 ) # 4 events, 8 trials - assert( obt[0, 0, 0, 1] == 0.0 ) # no trials - assert( obt[1, 3, 3, 0] == 0.0 ) # out of mask - -def test_chi_square_within_mask(exclusion_mask, events_per_pixel, trials_per_pixel): - - obt_p, obt_ch = chi.chi_square_within_mask(exclusion_mask, events_per_pixel, trials_per_pixel) +def test_chi_square_within_mask(exclusion_mask, events_per_pixel, + trials_per_pixel): + obt_p, obt_ch = chi.chi_square_within_mask(exclusion_mask, + events_per_pixel, + trials_per_pixel) resps = np.array([4, 0, 0, 0, 0, 0, 0, 0]) resids = resps - 0.5 @@ -188,15 +186,14 @@ def test_chi_square_within_mask(exclusion_mask, events_per_pixel, trials_per_pix # the zeroth test cell has a response without a trial. # this is infinitely surprising, so the pval is 0 - assert(np.allclose( obt_p, [0, exp_p] )) + assert (np.allclose(obt_p, [0, exp_p])) def test_get_disc_masks(): - lsn_template = np.zeros((9, 3, 3)) + 128 for ii in range(3): for jj in range(3): - lsn_template[3*ii+jj, ii, jj] = 0 + lsn_template[3 * ii + jj, ii, jj] = 0 lsn_template[4, 2, 2] = 255 exp1 = np.ones((3, 3)) @@ -207,16 +204,15 @@ def test_get_disc_masks(): obt = chi.get_disc_masks(lsn_template, radius=1) - assert(np.allclose( exp1, obt[1, 1, :, :] )) - assert(np.allclose( exp0, obt[0, 0, :, :] )) + assert (np.allclose(exp1, obt[1, 1, :, :])) + assert (np.allclose(exp0, obt[0, 0, :, :])) def test_get_events_per_pixel(): - events = np.zeros((3, 2)) trials = np.zeros((4, 4, 2, 3)) - # pixel 1,1 is off trial 1 and on trial 2 + # pixel 1,1 is off trial 1 and on trial 2 trials[1, 1, 1, 1] = 1 trials[1, 1, 0, 2] = 1 @@ -227,7 +223,7 @@ def test_get_events_per_pixel(): # cell 0 has 4 events on trial 2 and 1 on trial 0 events[2, 0] = 4 events[0, 0] = 1 - + # cell 1 has 2 events on trial 1 events[1, 1] = 2 @@ -238,54 +234,58 @@ def test_get_events_per_pixel(): exp[1, 1, 1, 1] = 2 obt = chi.get_events_per_pixel(events, trials) - assert(np.allclose( obt, exp )) + assert (np.allclose(obt, exp)) -@pytest.mark.parametrize('base,ex', [[5., 10], [0.1, 12], [np.arange(20), np.linspace(0, 1, 20)]]) +@pytest.mark.parametrize('base,ex', [[5., 10], [0.1, 12], + [np.arange(20), np.linspace(0, 1, 20)]]) def test_nll_to_pvalue(base, ex): - obt = chi.NLL_to_pvalue(ex, base) exp = np.power(base, -ex) - assert(np.allclose( exp, obt )) + assert (np.allclose(exp, obt)) # test by reversing nll_to_pvalue -@pytest.mark.parametrize('base,ex', [[10., 2], [10., 4], [np.array([10, 10, 10]), np.linspace(0, 1, 3)]]) +@pytest.mark.parametrize('base,ex', [[10., 2], [10., 4], + [np.array([10, 10, 10]), + np.linspace(0, 1, 3)]]) def test_pvalue_to_nll(base, ex): - pv = chi.NLL_to_pvalue(ex, base) max_nll = np.amax(ex) obt = chi.pvalue_to_NLL(pv, max_nll) - assert(np.allclose( ex, obt )) + assert (np.allclose(ex, obt)) -@pytest.mark.skipif(os.getenv('NO_TEST_RANDOM') == 'true', reason="random seed may not produce the same results on all machines") +@pytest.mark.skipif(os.getenv('NO_TEST_RANDOM') == 'true', + reason="random seed may not produce the same results on " + "all machines") def test_chi_square_binary(locally_sparse_noise, rf_events, rf_mask): - ntr = 2000 nr = 20 nc = 20 - slices = [slice(9, 11), slice(9, 11)] + slices = [range(9, 12), range(9, 12)] mask = rf_mask(nr, nc, slices) lsn = locally_sparse_noise(ntr, nr, nc) events = rf_events(mask, lsn) obt = chi.chi_square_binary(events, lsn) - assert( obt[0][slices].sum() == 0 ) - assert( obt.sum() > 0 ) + assert (obt[0][slices[0][0]:slices[0][-1], + slices[1][0]:slices[1][-1]].sum() == 0) + assert (obt.sum() > 0) -@pytest.mark.skipif(os.getenv('NO_TEST_RANDOM') == 'true', reason="random seed may not produce the same results on all machines") +@pytest.mark.skipif(os.getenv('NO_TEST_RANDOM') == 'true', + reason="random seed may not produce the same results on " + "all machines") def test_get_peak_significance(locally_sparse_noise, rf_events, rf_mask): - ntr = 2000 nr = 20 nc = 20 - slices = [slice(9, 11), slice(9, 11)] + slices = [range(9, 12), range(9, 12)] mask = rf_mask(nr, nc, slices) lsn = locally_sparse_noise(ntr, nr, nc) @@ -296,14 +296,13 @@ def test_get_peak_significance(locally_sparse_noise, rf_events, rf_mask): significant_cells, best_p, _, _ = chi.get_peak_significance(chi_nll, lsn) - assert(np.allclose( best_p, 0 )) - assert(np.allclose( significant_cells, [True] )) + assert (np.allclose(best_p, 0)) + assert (np.allclose(significant_cells, [True])) def test_locate_median(): - mask = np.eye(9) where = np.where(mask) - + obt = chi.locate_median(*where) - assert(np.allclose( obt , [4, 4] )) + assert (np.allclose(obt, [4, 4])) diff --git a/requirements.txt b/requirements.txt index 9e9fbbc74..3145b88db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -psycopg2-binary>=2.7,<3.0.0 +psycopg2-binary hdmf>=2.5.8 h5py matplotlib>=1.4.3,<3.4.3 @@ -18,7 +18,7 @@ statsmodels<=0.13.0 simpleitk>=2.0.2,<3.0.0 argschema>=3.0.1,<4.0.0 glymur==0.8.19 -xarray<0.16.0 +xarray pynwb tables>=3.6.0,<3.7.0 seaborn<1.0.0