Giter Club home page Giter Club logo

composition_sugar's Introduction

Composition Sugar

Syntactic sugar for function composition in Python

See usage examples on binder
Binder

Create readable pipelines for processing data. It is meant for quickly writing/organizing pipelines with wrapper functions that are frequently used.

data >> FuncA(args) >> FuncB(args) >> FuncC(args) >> ...

This is equivalent to:

FuncC(FuncB(FuncA(data, args), args), args)

Automatic GUI generation and updating live plots

Write a pipeline and automatically generate a GUI for parameter entry. This GUI can be connected to live plots.

See the following notebook for details: examples/gui_live_plotting.ipynb Binder

gui_gif

Logging

Besides being more readable, the functions & parameters are logged. See the binder demo for more details.

>>> pprint(container.log, width=20)

    [{'splice': {'data_column': '_RAW_CURVE',
                 'start': 0,
                 'stop': 2990}},
     {'normalize': {'data_column': 'spliced'}},
     {'rfft': {'data_column': 'normalize'}},
     {'absval': {'data_column': 'fft'}},
     {'log': {'data_column': 'absval'}},
     {'splice': {'data_column': 'log',
                 'start': 0,
                 'stop': 1000}},
     {'LDA': {'data_column': 'spliced',
              'labels_column': 'FCLUSTER_LABELS',
              'n_components': 2}}]

Data Container

Define a data container

Example with pandas DataFrame:

from fcsugar import Container

class DataFrameContainer(Container):
    def __init__(self, df: pd.DataFrame):
        self.df = df
        
    @classmethod
    def from_hdf5(cls, path: str, key: str):
        df = pd.read_hdf(path, key=key, mode='r')
        return cls(df)

Processing Node

Simply use the @node decorator on a function to use it with a data container

Example that splices arrays in a specific DataFrame column:

from fcsugar import node

@node
def splice(container, data_column, start, stop):
    container.df['spliced'] = container.df[data_column].apply(lambda a: a[start:stop])
    return container

Basic format:

@node
def func(container, *args, **kwargs):
    # do stuff to container
    return container

The first argument must always be the data container

You can also create more complex processing nodes by inheriting from Node:

from fcsugar import Node

class Complex(Node):        
    def process(self, container, *args, **kwargs):
        # do more complex stuff
        something_complex = self.some_other_func()

        # do other stuff
        final_result = do_more_stuff(something_complex)

        # the container which went through complex processing
        return final_result

    def some_other_func(self, ...):
        # does some stuff

    def do_more_stuff(self, ...):
        # more stuff

See full examples on binder
Binder

composition_sugar's People

Contributors

kushalkolar avatar

Watchers

 avatar  avatar  avatar

Forkers

danieldondorp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.