Skip to content

Instantly share code, notes, and snippets.

View adcoh's full-sized avatar

Adam Cohn adcoh

View GitHub Profile
@adcoh
adcoh / GenerateStreams.py
Last active November 23, 2020 20:04
The functions for the Streaming Dataset to generate stream of segments
def segments_generator(self, segment_list: _Segment) -> None:
"""
Generates original and augmented segments from a track.
"""
if self.config.get('get_shifts'):
segment_list = create_new_segments_from_splits(segment_list, nsplits=self.config['shift_segment'])
else:
segment_list = create_new_segments_from_splits(segment_list, nsplits=32)
if self.config.get('get_vertical_flip'):
@adcoh
adcoh / faster_splits.py
Last active November 16, 2020 15:39
Functions for faster data augmentation of timeseries
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]:
@adcoh
adcoh / createTracks.py
Last active November 16, 2020 15:24
the create_track_objects method
def create_track_objects(self):
df = self.data_df
df = self.split_train_val_as_pd(data=df, ratio=self.config.get('valratio', 6))
df.sort_values(by=['track_id', 'segment_id'], inplace=True)
df.replace({'animal': 0, 'human': 1}, inplace=True)
df['target_type'] = df['target_type'].astype(int)
# validating that each track consists of segments with same values in following columns
columns_to_check = ['geolocation_type', 'geolocation_id', 'sensor_id', 'snr_type', 'date_index', 'target_type']
# creating boolean matrix for np.select
conditions = [(df.groupby('track_id')[col].shift(0) == df.groupby('track_id')[col].shift(1).bfill())
@adcoh
adcoh / Segment.py
Created November 15, 2020 16:18
A fixed dictionary for a MAFAT radar segment
class _Segment(Dict, ABC):
segment_id: Union[int, str]
output_array: np.ndarray
doppler_burst: np.ndarray
target_type: np.ndarray
segment_count: int
@adcoh
adcoh / jupyterlab_venv_installer.sh
Last active November 1, 2020 14:22
An easy shell script to install Jupyter Lab and register your project venv as a kernel
pip install --upgrade pip
pip install upgrade jupyterlab
pip install autopep8
pip install --upgrade jupyterlab-git
venv_root_dir=${PWD##*/}
python -m ipykernel install --user --name=$venv_root_dir
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension --sys-prefix
@adcoh
adcoh / function.py
Created September 9, 2020 10:32
Byvalue Calculator
def hello_user(name):
return f'Welcome {name} and thank you for using our calculator!'
def addition(a,b):
return a+b
def subtraction(a,b):
return a-b
def division(a,b):
return a/b
def multiplication(a,b):
return a*b