def __init__( self, index=None, columns=None, ignore_absent_index=False, ignore_absent_columns=False, **kwargs, ): """Constructor Arguments ------------------ index : list A list of indices that should be filtered for coluns :list A list of columns that should be filtered for ignore_absent_index : bool If indices which are not found in the given index should be ignored or should throw an error ignore_absent_columns : bool If columns which are not found in the given columns should be ignored or should throw an error """ PipeElement.__init__(self, **kwargs) self.index = index self.columns = columns self.ignore_absent_index = ignore_absent_index self.ignore_absent_columns = ignore_absent_columns
def __init__(self, resolution, mode="m", **kwargs): """ Arguments ------------------ resolution : tuple The resolution that should result from depadding mode : str One of the following string values "m" Removes the pixels from the outside in. When only one pixel should be removed from an axis the bottom and right sides will be preferred "tl" Preserves the top-left corner and depads from the bottom-right "tr" Preserves the top-right corner and depads from the bottom-left "bl" Preserves the bottom-left corner and depads from the top-right "br" Preserves the bottom-right corner and depads from the top-left """ PipeElement.__init__(self, **kwargs) self.resolution = resolution self.mode = mode
def __init__(self, rotations=None, remove_padding=False, keep_original=False, **kwargs): """Constructor Arguments ------------------ rotations : list or set A list like object containing the degrees of the required rotations from -359 to 359 degrees remove_padding : bool If the padding, which is added during rotation should be removed after rotating keep_original : bool If the original images should be included in the resulting array """ PipeElement.__init__(self, **kwargs) verified_rotations = [ r % 360 if r >= 0 else r % -360 for r in rotations ] if keep_original: verified_rotations.append(0) self.keep_original = keep_original self.rotations = sorted(set(verified_rotations)) self.n_rotations = len(self.rotations) self.remove_padding = remove_padding
def __init__(self, convert=True, **kwargs): """ Arguments ------------------ convert : bool If the input should be converted into a pandas.DataFrame """ PipeElement.__init__(self, **kwargs) self.convert = convert
def __init__(self, scalar, **kwargs): """Constructor Arguments ------------------ scalar : float / int The scalar with which the input should be scaled with """ PipeElement.__init__(self, **kwargs) self.scalar = scalar
def __init__(self, n_result=None, **kwargs): """Constructor for _Split Arguments ------------------ n_result : int The amount of FlowData that should be produced. Will be changed to amount of downstream elements if more than one downstream element is set """ if n_result is not None and n_result < 1: raise ValueError("Expected number of outputs cannot be less than 1") self.n_result = n_result PipeElement.__init__(self, **kwargs)
def __init__(self, axis=0, ignore_index=False, **kwargs): """Constructor Arguments ------------------ axis : int The axis along which to merge the data along ignore_index : bool If the axis along which is concatenated is renamed """ PipeElement.__init__(self, **kwargs) self.axis = axis self.ignore_index = ignore_index
def __init__(self, columns=None, delimiter=",", **kwargs): """Constructor Arguments ------------------ columns : list The columns of the DataFrame on which this transformation should be applied delimiter : str or list of str The delimiter(s) used to split the string """ self.columns = columns self.delimiter = delimiter PipeElement.__init__(self, **kwargs)
def from_config(cls, config): """Creates a PipeSystem from Pipesystem configuration Arguments ------------------ config : dict The configuration that should be converted into a PipeSystem Returns ------------------ PipeSystem Configured PipeSystem """ inlets = [Inlet.from_config(c, element_id=True) for c in config["inlets"]] outlets = [Outlet.from_config(c, element_id=True) for c in config["outlets"]] elements = [ PipeElement.from_config(c, element_id=True) for c in config["elements"] ] _all = inlets + outlets + elements for e in _all: e.reconfigure(*_all) return cls(inlets=inlets, outlets=outlets, name=config["name"])
def __init__(self, index, ignore_absent=False, **kwargs): """Constructor Arguments ------------------ index : list A list of indices that should be filtered for ignore_absent : bool If indices which are not found in the given index should be ignored or should throw an error """ PipeElement.__init__(self, **kwargs) self.index = index self.ignore_absent = ignore_absent
def __init__(self, columns, ignore_absent=False, **kwargs): """Constructor Arguments ------------------ columns : list A list of columns that should be filtered for ignore_absent : bool If columns which are not found in the given columns should be ignored or should throw an error """ PipeElement.__init__(self, **kwargs) self.columns = columns self.ignore_absent = ignore_absent
def __init__(self, columns=None, dependent=False, scale_from=(None, None), scale_to=(0, 1), **kwargs): """Constructor Arguments ------------------ columns : list (default=None) The columns of the given input that should be normalized. If None then all columns of the given input will be used. dependent : bool (default=False) If the columns of the given input should be transformed dependent on the others scale_from : tuple The minimum, maximum from where the values are scaled from scale_to : tuple The minimum, maximum from where the values are scaled to Raises ------------------ ValueError When given range scale_from/scale_to are not in the correct format """ PipeElement.__init__(self, **kwargs) self.columns = columns self.dependent = dependent if len(scale_from) != 2 or scale_from[1] > scale_from[0]: raise ValueError( """scale_from should be a 2-tuple where n=0 should be the minimum value and n=1 the maximum value""") self.scale_from = scale_from if len(scale_to) != 2 or scale_to[1] > scale_to[0]: raise ValueError( """scale_to should be a 2-tuple where n=0 should be the minimum value and n=1 the maximum value""") self.scale_to = scale_to
def __init__(self, columns=None, sparse=False, ignore_absent=False, keep=False, **kwargs): """Constructor for the Categorizer class Arguments ------------------ columns : list (default=None) The columns that should be converted to categorical data. If None then all given columns will be converted sparse : bool (default=False) If the resulting columns should be converted to spare or dense matrix ignore_absent : bool (default=False) If any given columns are not found in the given data should be ignored. Execution will halt if false keep : bool (default=False) If the columns that are categorized should be kept in the output Raises ------------------ ValueError When column parameter is not given as a list or set as None """ PipeElement.__init__(self, **kwargs) if isinstance(columns, list) or columns is None: self.columns = columns else: raise ValueError("Given columns has to be of type list or None") self.sparse = sparse self.ignore_absent = ignore_absent self.keep = keep
def concatenate(*pipe_system): """Concatenates the given PipeSystems into a single Sequential PipeSystem The PipeSystems are concatenated together by removing their inlets and outlets and connecting them via a PipeElement. This expects that the amount of Outlets matches the amount of Inlets of the PipeSystem is supposed to connect to. If a discrepancy here is found an Exception is raised. Arguments ------------------ *pipe_system : PipeSystem The PipeSystems that should be concatenated together Returns ------------------ ps : PipeSystem The single PipeSystem with the concatenated PipeSystem Raises ------------------ TypeError When something else other than a PipeSystem is trying to be added AttributeError When the length of the outlets of a PipeSystem do not match the following PipeSystem's outlets """ for e in pipe_system: if not isinstance(e, PipeSystem): raise TypeError(f"Cannot extend PipeSystems with type {type(e)}") if len(pipe_system) == 1: return pipe_system[0] for i, ps in enumerate(pipe_system): if i > 0: if len(pipe_system[i - 1].outlets) != len(pipe_system[i].inlets): raise AttributeError( f"{pipe_system[i-1]} outlets do not match amount of " f"{pipe_system[i]} inlets" ) inlets = pipe_system[0].inlets outlets = pipe_system[-1].outlets name = "" for i, ps in enumerate(pipe_system): if i > 0: for outlet, inlet in zip( pipe_system[i - 1].outlets, pipe_system[i].inlets ): up = outlet.upstream[0] down = inlet.downstream[0] up.detach_downstream() down.detach_upstream() down(PipeElement(name=outlet.name + inlet.name)(up)) name += ps.name return PipeSystem(inlets=inlets, outlets=outlets, name=name)
def __init__(self, dependent=False, **kwargs): PipeElement.__init__(self, **kwargs) self.dependent = dependent