Source code for myoverse.datasets.filters._template
fromtypingimportLiteralimportnumpyasnp
[docs]classFilterBaseClass:"""Base class for filters. Parameters ---------- input_is_chunked : bool Whether the input is chunked or not. allowed_input_type : Literal["both", "chunked", "not chunked"] Whether the filter accepts chunked input, not chunked input or both. is_output : bool Whether the filter is an output filter. If True, the resulting signal will be outputted by and dataset pipeline. Methods ------- __call__(input_array: np.ndarray) -> np.ndarray Filters the input array. Input shape is determined by whether the allowed_input_type is "both", "chunked" or "not chunked". """def__init__(self,input_is_chunked:bool=None,allowed_input_type:Literal["both","chunked","not chunked"]=None,is_output:bool=False,name:str=None,):self.input_is_chunked=input_is_chunkedself._allowed_input_type=allowed_input_typeself.is_output=is_outputself._name=name@propertydefname(self):ifself._nameisNone:returnself.__class__.__name__returnself._namedef__run_checks(self):ifself._allowed_input_typeisNone:raiseValueError("allowed_input_type must be specified.")ifself._allowed_input_typenotin["both","chunked","not chunked"]:raiseValueError("allowed_input_type must be either 'both', 'chunked' or 'not chunked'.")ifself._allowed_input_type=="both":returnelifself._allowed_input_type=="chunked":ifnotself.input_is_chunked:raiseValueError(f"This filter ({self.__class__.__name__}) only accepts chunked input.")elifself._allowed_input_type=="not chunked":ifself.input_is_chunked:raiseValueError(f"This filter ({self.__class__.__name__}) only accepts **un** chunked input.")
def_filter(self,input_array:np.ndarray)->np.ndarray:raiseNotImplementedError("This method must be implemented in the subclass.")def__repr__(self):# return (# f"{self.__class__.__name__}"# f'({", ".join([f"{k}={v}" for k, v in self.__dict__.items() if not k.startswith("_")])})'# )ifself.name:returnf"{self.name} ({self.__class__.__name__})"returnf"{self.__class__.__name__}"def__str__(self):returnself.__repr__()
[docs]classEMGAugmentation(FilterBaseClass):"""Base class for EMG augmentation_pipelines."""def__init__(self,input_is_chunked:bool=None,is_output:bool=False):super().__init__(input_is_chunked=input_is_chunked,allowed_input_type="not chunked",is_output=is_output,)