@testing.requires_testing_data
def test_crop():
 raw = concatenate_raws([read_raw_fif(f) for f in [fif_fname, fif_fname]])
 split_size = 10.0
 sfreq = raw.info['sfreq']
 nsamp = ((raw.last_samp - raw.first_samp) + 1)
 tmins = np.r_[(1.0, np.round(np.arange(0.0, (nsamp - 1), (split_size * sfreq))))]
 tmins = np.sort(tmins)
 tmaxs = np.concatenate(((tmins[1:] - 1), [(nsamp - 1)]))
 tmaxs /= sfreq
 tmins /= sfreq
 raws = ([None] * len(tmins))
 for (ri, (tmin, tmax)) in enumerate(zip(tmins, tmaxs)):
  raws[ri] = raw.copy().crop(tmin, tmax)
 all_raw_2 = concatenate_raws(raws, preload=False)
 assert_equal(raw.first_samp, all_raw_2.first_samp)
 assert_equal(raw.last_samp, all_raw_2.last_samp)
 assert_array_equal(raw[:, :][0], all_raw_2[:, :][0])
 tmins = np.round(np.arange(0.0, (nsamp - 1), (split_size * sfreq)))
 tmaxs = np.concatenate(((tmins[1:] - 1), [(nsamp - 1)]))
 tmaxs /= sfreq
 tmins /= sfreq
 raws = ([None] * len(tmins))
 for (ri, (tmin, tmax)) in enumerate(zip(tmins, tmaxs)):
  raws[ri] = raw.copy().crop(tmin, tmax)
 all_raw_1 = concatenate_raws(raws, preload=False)
 all_raw_2 = raw.copy().crop(0, None)
 for ar in [all_raw_1, all_raw_2]:
  assert_equal(raw.first_samp, ar.first_samp)
  assert_equal(raw.last_samp, ar.last_samp)
  assert_array_equal(raw[:, :][0], ar[:, :][0])
 data = np.zeros((1, 1002001))
 info = create_info(1, 1000)
 raw = RawArray(data, info)
 for tmin in range(0, 1001, 100):
  raw1 = raw.copy().crop(tmin=tmin, tmax=(tmin + 2))
  assert_equal(raw1[:][0].shape, (1, 2001))

@ testing . requires_testing_data def test_crop ( ) : raw = concatenate_raws ( [ read_raw_fif ( f ) for f in [ fif_fname , fif_fname ] ] ) split_size = 10.0 sfreq = raw . info [ 'sfreq' ] nsamp = ( ( raw . last_samp - raw . first_samp ) + 1 ) tmins = np . r_ [ ( 1.0 , np . round ( np . arange ( 0.0 , ( nsamp - 1 ) , ( split_size * sfreq ) ) ) ) ] tmins = np . sort ( tmins ) tmaxs = np . concatenate ( ( ( tmins [ 1 : ] - 1 ) , [ ( nsamp - 1 ) ] ) ) tmaxs /= sfreq tmins /= sfreq raws = ( [ None ] * len ( tmins ) ) for ( ri , ( tmin , tmax ) ) in enumerate ( zip ( tmins , tmaxs ) ) : raws [ ri ] = raw . copy ( ) . crop ( tmin , tmax ) all_raw_2 = concatenate_raws ( raws , preload = False ) assert_equal ( raw . first_samp , all_raw_2 . first_samp ) assert_equal ( raw . last_samp , all_raw_2 . last_samp ) assert_array_equal ( raw [ : , : ] [ 0 ] , all_raw_2 [ : , : ] [ 0 ] ) tmins = np . round ( np . arange ( 0.0 , ( nsamp - 1 ) , ( split_size * sfreq ) ) ) tmaxs = np . concatenate ( ( ( tmins [ 1 : ] - 1 ) , [ ( nsamp - 1 ) ] ) ) tmaxs /= sfreq tmins /= sfreq raws = ( [ None ] * len ( tmins ) ) for ( ri , ( tmin , tmax ) ) in enumerate ( zip ( tmins , tmaxs ) ) : raws [ ri ] = raw . copy ( ) . crop ( tmin , tmax ) all_raw_1 = concatenate_raws ( raws , preload = False ) all_raw_2 = raw . copy ( ) . crop ( 0 , None ) for ar in [ all_raw_1 , all_raw_2 ] : assert_equal ( raw . first_samp , ar . first_samp ) assert_equal ( raw . last_samp , ar . last_samp ) assert_array_equal ( raw [ : , : ] [ 0 ] , ar [ : , : ] [ 0 ] ) data = np . zeros ( ( 1 , 1002001 ) ) info = create_info ( 1 , 1000 ) raw = RawArray ( data , info ) for tmin in range ( 0 , 1001 , 100 ) : raw1 = raw . copy ( ) . crop ( tmin = tmin , tmax = ( tmin + 2 ) ) assert_equal ( raw1 [ : ] [ 0 ] . shape , ( 1 , 2001 ) )
test tfr cropping .