Beispiel #1
0
def update_doc(obj, scaling='density'):
    """Update the docstring of ``obj`` to reference available FFT methods
    """
    header = 'The available methods are:'

    # remove the old format list
    lines = obj.__doc__.splitlines()
    try:
        pos = [i for i, line in enumerate(lines) if header in line][0]
    except IndexError:
        pass
    else:
        lines = lines[:pos]

    # work out the indentation
    matches = [re.search(r'(\S)', line) for line in lines[1:]]
    indent = min(match.start() for match in matches if match)

    # build table of methods
    from astropy.table import Table
    rows = []
    for method in METHODS[scaling]:
        func = METHODS[scaling][method]
        rows.append((method, '`%s.%s`' % (func.__module__, func.__name__)))
    format_str = Table(rows=rows, names=['Method name', 'Function']).pformat(
        max_lines=-1, max_width=80, align=('>', '<'))
    format_str[1] = format_str[1].replace('-', '=')
    format_str.insert(0, format_str[1])
    format_str.append(format_str[0])
    format_str.extend(['', 'See :ref:`gwpy-signal-fft` for more details'])

    lines.extend([' ' * indent + line for line in [header, ''] + format_str])

    # and overwrite the docstring
    obj.__doc__ = '\n'.join(lines)
Beispiel #2
0
def update_doc(obj, scaling='density'):
    """Update the docstring of ``obj`` to reference available FFT methods
    """
    header = 'The available methods are:'

    # if __doc__ isn't a string, bail-out now
    if not isinstance(obj.__doc__, string_types):
        return

    # remove the old format list
    lines = obj.__doc__.splitlines()
    try:
        pos = [i for i, line in enumerate(lines) if header in line][0]
    except IndexError:
        pass
    else:
        lines = lines[:pos]

    # work out the indentation
    matches = [re.search(r'(\S)', line) for line in lines[1:]]
    indent = min(match.start() for match in matches if match)

    # build table of methods
    from astropy.table import Table
    rows = []
    for method in METHODS[scaling]:
        f = METHODS[scaling][method]
        rows.append((method, '`%s.%s`' % (f.__module__, f.__name__)))
    rows.sort(key=lambda x: x[1])
    format_str = Table(rows=rows, names=['Method name',
                                         'Function']).pformat(max_lines=-1,
                                                              max_width=80,
                                                              align=('>', '<'))
    format_str[1] = format_str[1].replace('-', '=')
    format_str.insert(0, format_str[1])
    format_str.append(format_str[0])
    format_str.extend(['', 'See :ref:`gwpy-signal-fft` for more details'])

    lines.extend([' ' * indent + line for line in [header, ''] + format_str])
    # and overwrite the docstring
    try:
        obj.__doc__ = '\n'.join(lines)
    except AttributeError:
        obj.__func__.__doc__ = '\n'.join(lines)