Last active
November 16, 2020 15:39
-
-
Save adcoh/bfc7805d0e382a31e43a1cac8bc4d07e to your computer and use it in GitHub Desktop.
Functions for faster data augmentation of timeseries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_Nd_array(array: np.ndarray, nsplits: int) -> List[np.ndarray]: | |
if array.ndim == 1: | |
indices = range(0, len(array) - 31, nsplits) | |
segments = [np.take(array, np.arange(i, i + 32), axis=0).copy() for i in indices] | |
else: | |
indices = range(0, array.shape[1] - 31, nsplits) | |
segments = [np.take(array, np.arange(i, i + 32), axis=1).copy() for i in indices] | |
return segments | |
def create_new_segments_from_splits(segment: _Segment, nsplits: int) -> List[_Segment]: | |
new_segments = [] | |
if segment['output_array'].shape[1] > 32: | |
output_array = split_Nd_array(array=segment['output_array'], nsplits=nsplits) | |
bursts = split_Nd_array(array=segment['doppler_burst'], nsplits=nsplits) | |
new_segments.extend([_Segment(segment_id=f'{segment["segment_id"]}_{j}', | |
output_array=array, | |
doppler_burst=bursts[j], | |
target_type=segment['target_type'], | |
segment_count=1) | |
for j, array in enumerate(output_array)]) | |
else: | |
new_segments.append(segment) | |
return new_segments | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment