<s> """<STR_LIT>""" <EOL> from nose . tools import assert_raises <EOL> import numpy as np <EOL> from nilearn . _utils . ndimage import largest_connected_component , _peak_local_max <EOL> def test_largest_cc ( ) : <EOL> """<STR_LIT>""" <EOL> a = np . zeros ( ( <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:6> ) ) <EOL> assert_raises ( ValueError , largest_connected_component , a ) <EOL> a [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:3> ] = <NUM_LIT:1> <EOL> np . testing . assert_equal ( a , largest_connected_component ( a ) ) <EOL> b = a . copy ( ) <EOL> b [ <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ] = <NUM_LIT:1> <EOL> np . testing . assert_equal ( a , largest_connected_component ( b ) ) <EOL> def test_empty_peak_local_max ( ) : <EOL> image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:20> ) ) <EOL> result = _peak_local_max ( image , min_distance = <NUM_LIT:1> , threshold_rel = <NUM_LIT:0> ) <EOL> assert np . all ( ~ result ) <EOL> def test_flat_peak_local_max ( ) : <EOL> image = np . zeros ( ( <NUM_LIT:5> , <NUM_LIT:5> ) ) <EOL> image [ <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:3> ] = <NUM_LIT:10> <EOL> peaks = _peak_local_max ( image , min_distance = <NUM_LIT:1> ) <EOL> np . testing . assert_equal ( len ( peaks [ peaks == <NUM_LIT:1> ] ) , <NUM_LIT:4> ) <EOL> def test_relative_and_absolute_thresholds_in_peak_local_max ( ) : <EOL> image = np . zeros ( ( <NUM_LIT:5> , <NUM_LIT:5> ) ) <EOL> image [ <NUM_LIT:1> , <NUM_LIT:1> ] = <NUM_LIT:10> <EOL> image [ <NUM_LIT:3> , <NUM_LIT:3> ] = <NUM_LIT:20> <EOL> peaks_rel = _peak_local_max ( image , min_distance = <NUM_LIT:1> , threshold_rel = <NUM_LIT:0.5> ) <EOL> np . testing . assert_equal ( len ( peaks_rel [ peaks_rel == <NUM_LIT:1> ] ) , <NUM_LIT:1> ) <EOL> peaks_abs = _peak_local_max ( image , min_distance = <NUM_LIT:1> , threshold_abs = <NUM_LIT:10> ) <EOL> np . testing . assert_equal ( len ( peaks_abs [ peaks_abs == <NUM_LIT:1> ] ) , <NUM_LIT:1> ) <EOL> def test_constant_image_in_peak_local_max ( ) : <EOL> image = <NUM_LIT> * np . ones ( ( <NUM_LIT:20> , <NUM_LIT:20> ) ) <EOL> peaks = _peak_local_max ( image , min_distance = <NUM_LIT:1> ) <EOL> np . testing . assert_equal ( len ( peaks [ peaks == <NUM_LIT:1> ] ) , <NUM_LIT:0> ) <EOL> def test_trivial_cases_in_peak_local_max ( ) : <EOL> trivial = np . zeros ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> peaks = _peak_local_max ( trivial , min_distance = <NUM_LIT:1> ) <EOL> assert ( peaks . astype ( np . bool ) == trivial ) . all ( ) </s>
