Skip to content

Commit

Permalink
Use class directly as pipesegment decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
arahlin committed Oct 23, 2024
1 parent bd00668 commit 447d0de
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions core/python/modconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,34 @@
import re


class PipelineSegment:
"""
Wrapper class for pipeline segments. Used by the `pipesegment` function
decorator to enable auto-documentation of pipeline segments by
introspection.
"""
class pipesegment:
'''
Use as a decorator for a pre-assembled set of pipeline modules. Makes a
pseudo-module consisting of several inputs. If autodoc is True (the
default), will attempt to introspect the segment to find out what it
does. Set this to False if your module does anything complicated.
For example:
@core.pipesegment
def standardfiltering(pipe, PolyOrder=4, MaskedHighPassEll=6000, Input='CalTimestreams', Output='FilteredTimestreams'):
pipe.Add(analysis.PolyFilter, PolyOrder=PolyOrder, Input=Input,
Output='__Temp' + Output)
pipe.Add(analysis.MaskedHighPass, MaskedHighPassEll=MaskedHighPassEll, Input='__Temp' + Output, Output=Output)
def cleanup(frame):
del frame['__Temp' + Output]
pipe.Add(cleanup)
pipe.Add(standardfiltering, PolyOrder=3)
'''
__pipesegment__ = True

def __init__(self, func, autodoc=True):
self.func = self.__wrapped__ = func
self._do_autodoc = autodoc

def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
def __call__(self, pipe, *args, **kwargs):
return self.func(pipe, *args, **kwargs)

def autodoc(self):
"""
Expand Down Expand Up @@ -88,30 +102,6 @@ def __name__(self):
return self.func.__name__


def pipesegment(func, autodoc=True):
'''
Use as a decorator for a pre-assembled set of pipeline modules. Makes a
pseudo-module consisting of several inputs. If autodoc is True (the
default), will attempt to introspect the segment to find out what it
does. Set this to False if your module does anything complicated.
For example:
@core.pipesegment
def standardfiltering(pipe, PolyOrder=4, MaskedHighPassEll=6000, Input='CalTimestreams', Output='FilteredTimestreams'):
pipe.Add(analysis.PolyFilter, PolyOrder=PolyOrder, Input=Input,
Output='__Temp' + Output)
pipe.Add(analysis.MaskedHighPass, MaskedHighPassEll=MaskedHighPassEll, Input='__Temp' + Output, Output=Output)
def cleanup(frame):
del frame['__Temp' + Output]
pipe.Add(cleanup)
pipe.Add(standardfiltering, PolyOrder=3)
'''

return PipelineSegment(func, autodoc)


def pipesegment_nodoc(func):
return pipesegment(func, autodoc = False)

Expand Down

0 comments on commit 447d0de

Please sign in to comment.