def test_implicit_stim_conversion(): image_dir = join(get_test_data_path(), 'image') stim = ImageStim(join(image_dir, 'button.jpg')) ext = LengthExtractor() result = ext.transform(stim).to_df() assert 'text_length' in result.columns assert result['text_length'][0] == 4
def test_text_length_extractor(): stim = TextStim(text='hello world', onset=4.2, duration=1) ext = LengthExtractor() result = ext.transform(stim).to_df() assert 'text_length' in result.columns assert result['text_length'][0] == 11 assert result['onset'][0] == 4.2 assert result['duration'][0] == 1
def test_implicit_stim_conversion2(): audio_dir = join(get_test_data_path(), 'audio') stim = AudioStim(join(audio_dir, 'homer.wav')) ext = LengthExtractor() result = ext.transform(stim) first_word = result[0].to_df() assert 'text_length' in first_word.columns assert first_word['text_length'][0] > 0
def test_implicit_stim_conversion(): image_dir = join(get_test_data_path(), 'image') stim = ImageStim(join(image_dir, 'button.jpg'), onset=4.2) ext = LengthExtractor() result = ext.transform(stim).to_df() assert 'text_length' in result.columns assert result['text_length'][0] == 4 assert result['onset'][0] == 4.2
def test_implicit_stim_conversion3(): video_dir = join(get_test_data_path(), 'video') stim = VideoStim(join(video_dir, 'obama_speech.mp4')) ext = LengthExtractor() result = ext.transform(stim) first_word = result[0].to_df() # The word should be "today" assert 'text_length' in first_word.columns assert first_word['text_length'][0] == 5
def test_implicit_stim_conversion3(): video_dir = join(get_test_data_path(), 'video') stim = VideoStim(join(video_dir, 'obama_speech.mp4'), onset=4.2) ext = LengthExtractor() result = ext.transform(stim) first_word = result[0].to_df() # The word should be "today" assert 'text_length' in first_word.columns assert first_word['text_length'][0] == 5 assert first_word['onset'][0] >= 4.2
def test_implicit_stim_conversion2(): def_conv = config.get_option('default_converters') config.set_option('default_converters', {'AudioStim->TextStim': ('WitTranscriptionConverter', )}) audio_dir = join(get_test_data_path(), 'audio') stim = AudioStim(join(audio_dir, 'homer.wav'), onset=4.2) ext = LengthExtractor() result = ext.transform(stim) first_word = result[0].to_df() assert 'text_length' in first_word.columns assert first_word['text_length'][0] > 0 assert first_word['onset'][0] >= 4.2 config.set_option('default_converters', def_conv)
def test_implicit_stim_conversion2(): def_conv = config.get_option('default_converters') config.set_option('default_converters', {'AudioStim->TextStim': ('WitTranscriptionConverter',)}) audio_dir = join(get_test_data_path(), 'audio') stim = AudioStim(join(audio_dir, 'homer.wav'), onset=4.2) ext = LengthExtractor() result = ext.transform(stim) first_word = result[0].to_df() assert 'text_length' in first_word.columns assert first_word['text_length'][0] > 0 assert first_word['onset'][0] >= 4.2 config.set_option('default_converters', def_conv)
def test_big_pipeline(): pytest.importorskip('pygraphviz') filename = join(get_test_data_path(), 'video', 'obama_speech.mp4') video = VideoStim(filename) visual_nodes = [(FrameSamplingFilter(every=15), [ (TesseractConverter(), [LengthExtractor()]), VibranceExtractor(), 'BrightnessExtractor', ])] audio_nodes = [(VideoToAudioConverter(), [WitTranscriptionConverter(), 'LengthExtractor'], 'video_to_audio')] graph = Graph() graph.add_nodes(visual_nodes) graph.add_nodes(audio_nodes) results = graph.run(video, merge=False) result = merge_results(results, format='wide', extractor_names='multi') # Test that pygraphviz outputs a file drawfile = next(tempfile._get_candidate_names()) graph.draw(drawfile) assert exists(drawfile) os.remove(drawfile) assert ('LengthExtractor', 'text_length') in result.columns assert ('VibranceExtractor', 'vibrance') in result.columns # assert not result[('onset', '')].isnull().any() assert 'text[negotiations]' in result['stim_name'].values assert 'frame[90]' in result['stim_name'].values
def test_small_pipeline(): pytest.importorskip('pytesseract') filename = join(get_test_data_path(), 'image', 'button.jpg') stim = ImageStim(filename) nodes = [(TesseractConverter(), [LengthExtractor()])] graph = Graph(nodes) result = list(graph.run([stim], merge=False)) history = result[0].history.to_df() assert history.shape == (2, 8) assert history.iloc[0]['result_class'] == 'TextStim' result = merge_results(result, format='wide', extractor_names='prepend') assert (0, 'text[Exit]') in result['stim_name'].values assert 'LengthExtractor#text_length' in result.columns assert result['LengthExtractor#text_length'].values[0] == 4
def test_twitter(): # Test stim creation pytest.importorskip('twitter') factory = TweetStimFactory() status_id = 821442726461931521 pliers_tweet = factory.get_status(status_id) assert isinstance(pliers_tweet, TweetStim) assert isinstance(pliers_tweet, CompoundStim) assert len(pliers_tweet.elements) == 1 status_id = 884392294014746624 ut_tweet = factory.get_status(status_id) assert len(ut_tweet.elements) == 2 # Test extraction ext = LengthExtractor() res = ext.transform(pliers_tweet)[0].to_df() assert res['text_length'][0] == 104 # Test image extraction ext = BrightnessExtractor() res = ext.transform(ut_tweet)[0].to_df() brightness = res['brightness'][0] assert np.isclose(brightness, 0.54057, 1e-5)
def test_big_pipeline(): filename = join(get_test_data_path(), 'video', 'obama_speech.mp4') video = VideoStim(filename) visual_nodes = [(FrameSamplingConverter(every=15), [ (TesseractConverter(), [LengthExtractor()]), VibranceExtractor(), 'BrightnessExtractor', ])] audio_nodes = [(VideoToAudioConverter(), [ WitTranscriptionConverter(), 'LengthExtractor'], 'video_to_audio')] graph = Graph() graph.add_nodes(visual_nodes) graph.add_nodes(audio_nodes) result = graph.run(video) assert ('LengthExtractor', 'text_length') in result.columns assert ('VibranceExtractor', 'vibrance') in result.columns # assert not result[('onset', '')].isnull().any() assert 'text[negotiations]' in result['stim'].values assert 'frame[90]' in result['stim'].values
def test_text_length_extractor(): stim = TextStim(text='hello world') ext = LengthExtractor() result = ext.transform(stim).to_df() assert 'text_length' in result.columns assert result['text_length'][0] == 11