def _resample_stim_channels(stim_data, up, down):
 stim_data = np.atleast_2d(stim_data)
 (n_stim_channels, n_samples) = stim_data.shape
 ratio = (float(up) / down)
 resampled_n_samples = int(round((n_samples * ratio)))
 stim_resampled = np.zeros((n_stim_channels, resampled_n_samples))
 sample_picks = np.minimum((np.arange(resampled_n_samples) / ratio).astype(int), (n_samples - 1))
 windows = zip(sample_picks, np.r_[(sample_picks[1:], n_samples)])
 for (window_i, window) in enumerate(windows):
  for (stim_num, stim) in enumerate(stim_data):
   nonzero = stim[window[0]:window[1]].nonzero()[0]
   if (len(nonzero) > 0):
    val = stim[(window[0] + nonzero[0])]
   else:
    val = stim[window[0]]
   stim_resampled[(stim_num, window_i)] = val
 return stim_resampled

def _resample_stim_channels ( stim_data , up , down ) : stim_data = np . atleast_2d ( stim_data ) ( n_stim_channels , n_samples ) = stim_data . shape ratio = ( float ( up ) / down ) resampled_n_samples = int ( round ( ( n_samples * ratio ) ) ) stim_resampled = np . zeros ( ( n_stim_channels , resampled_n_samples ) ) sample_picks = np . minimum ( ( np . arange ( resampled_n_samples ) / ratio ) . astype ( int ) , ( n_samples - 1 ) ) windows = zip ( sample_picks , np . r_ [ ( sample_picks [ 1 : ] , n_samples ) ] ) for ( window_i , window ) in enumerate ( windows ) : for ( stim_num , stim ) in enumerate ( stim_data ) : nonzero = stim [ window [ 0 ] : window [ 1 ] ] . nonzero ( ) [ 0 ] if ( len ( nonzero ) > 0 ) : val = stim [ ( window [ 0 ] + nonzero [ 0 ] ) ] else : val = stim [ window [ 0 ] ] stim_resampled [ ( stim_num , window_i ) ] = val return stim_resampled
resample stim channels .