def test_get_stimulus_templates(behavior_stimuli_data_fixture): templates = get_stimulus_templates(behavior_stimuli_data_fixture, grating_images_dict={}) assert templates.image_set_name == 'test_image_set' assert len(templates) == 1 assert list(templates.keys()) == ['im065'] for img in templates.values(): assert isinstance(img, StimulusImage) expected_path = os.path.join(get_resources_dir(), 'stimulus_template', 'expected') expected_unwarped_path = os.path.join( expected_path, 'im065_unwarped.pkl') expected_unwarped = pd.read_pickle(expected_unwarped_path) expected_warped_path = os.path.join( expected_path, 'im065_warped.pkl') expected_warped = pd.read_pickle(expected_warped_path) for img_name in templates: img = templates[img_name] assert np.allclose(a=expected_unwarped, b=img.unwarped, equal_nan=True) assert np.allclose(a=expected_warped, b=img.warped, equal_nan=True) for img_name, img in templates.items(): img = templates[img_name] assert np.allclose(a=expected_unwarped, b=img.unwarped, equal_nan=True) assert np.allclose(a=expected_warped, b=img.warped, equal_nan=True)
def test_metadata(): release_date = '2021-03-25' with tempfile.TemporaryDirectory() as tmp_dir: bpc = VisualBehaviorOphysProjectCache.from_lims( data_release_date=release_date) bpmw = BehaviorProjectMetadataWriter( behavior_project_cache=bpc, out_dir=tmp_dir, project_name='visual-behavior-ophys', data_release_date=release_date) bpmw.write_metadata() expected_path = os.path.join(get_resources_dir(), 'project_metadata_writer', 'expected') # test behavior expected = pd.read_pickle(os.path.join(expected_path, 'behavior_session_table.pkl')) expected = sort_df(df=expected, sort_col='behavior_session_id') obtained = pd.read_csv(os.path.join(tmp_dir, 'behavior_session_table.csv'), dtype={'mouse_id': str}, parse_dates=['date_of_acquisition']) obtained = sort_df(df=obtained, sort_col='behavior_session_id') convert_strings_to_lists(df=obtained) pd.testing.assert_frame_equal(expected, obtained) # test ophys session expected = pd.read_pickle(os.path.join(expected_path, 'ophys_session_table.pkl')) expected = sort_df(df=expected, sort_col='ophys_session_id') obtained = pd.read_csv(os.path.join(tmp_dir, 'ophys_session_table.csv'), dtype={'mouse_id': str}, parse_dates=['date_of_acquisition']) obtained = sort_df(df=obtained, sort_col='ophys_session_id') convert_strings_to_lists(df=obtained) pd.testing.assert_frame_equal(expected, obtained) # test ophys experiment expected = pd.read_pickle(os.path.join(expected_path, 'ophys_experiment_table.pkl')) expected = sort_df(df=expected, sort_col='ophys_experiment_id') obtained = pd.read_csv(os.path.join(tmp_dir, 'ophys_experiment_table.csv'), dtype={'mouse_id': str}, parse_dates=['date_of_acquisition']) obtained = sort_df(df=obtained, sort_col='ophys_experiment_id') convert_strings_to_lists(df=obtained, is_session=False) pd.testing.assert_frame_equal(expected, obtained)
def test_get_ophys_session_table(TempdirBehaviorCache, session_table): cache = TempdirBehaviorCache obtained = cache.get_ophys_session_table() if cache.cache: path = cache.manifest.path_info.get("ophys_sessions").get("spec") assert os.path.exists(path) expected_path = os.path.join(get_resources_dir(), 'project_metadata', 'expected') expected = pd.read_pickle(os.path.join(expected_path, 'ophys_session_table.pkl')) pd.testing.assert_frame_equal(expected, obtained)