コード例 #1
0
def write_bitmask_table(obj, path):
    bm = obj()
    ofile = os.path.join(path, '{0}_table.rst'.format(obj.__name__.lower()))

    data_table = numpy.empty((bm.nbits+1, 4), dtype=object)
    data_table[0,:] = ['Bit Name', 'Bit Number', 'Decimal Value', 'Description']
    for i,k in enumerate(bm.bits.keys()):
        data_table[i+1,0] = k
        data_table[i+1,1] = to_string(bm.bits[k])
        data_table[i+1,2] = to_string(int(2**bm.bits[k]))
        data_table[i+1,3] = to_string(bm.descr[bm.bits[k]])

    lines = string_table(data_table, delimeter='rst')
    with open(ofile, 'w') as f:
        f.write(lines)
    print('Wrote: {}'.format(ofile))
コード例 #2
0
ファイル: build_spectbl_rst.py プロジェクト: ninoc/PypeIt
def write_spec_table(path):
    ofile = os.path.join(path, 'spectrographs_table.rst')

    spec = spectrograph_classes()
    nspec = len(spec.keys())

    data_table = numpy.empty((nspec + 1, 7), dtype=object)
    data_table[0, :] = [
        '``PypeIt`` Name', '``PypeIt`` Class', 'Telescope', 'Camera',
        'Pipeline Approach', 'Supported', 'Comments'
    ]
    for i, cls in enumerate(spec.values()):
        data_table[i + 1, 0] = cls.name
        data_table[i + 1,
                   1] = ':class:`~' + cls.__module__ + '.' + cls.__name__ + '`'
        data_table[i + 1, 2] = cls.telescope['name']
        data_table[i + 1, 3] = cls.camera
        data_table[i + 1, 4] = cls.pypeline
        data_table[i + 1, 5] = to_string(cls.supported)
        data_table[i + 1, 6] = '' if cls.comment is None else cls.comment

    lines = string_table(data_table, delimeter='rst')
    with open(ofile, 'w') as f:
        f.write(lines)
    print('Wrote: {}'.format(ofile))
コード例 #3
0
def build_tbl(obj):

    #    data_model = obj.full_datamodel(include_children=False)
    data_model = obj.datamodel
    keys = list(data_model.keys())
    keys.sort()

    data_table = numpy.empty((len(keys) + 1, 4), dtype=object)
    data_table[0, :] = ['HDU Name', 'Obj Type', 'Array Type', 'Description']
    alternate_keys = []
    for i, k in enumerate(keys):
        # Key
        # Rename?
        _k = k.upper()
        if obj.hdu_prefix is not None:
            _k = obj.hdu_prefix + _k
        alternate_keys.append(_k)
        data_table[i + 1, 0] = to_string(_k, use_repr=False, verbatim=True)
        # Object Type
        if isinstance(data_model[k]['otype'], (list, tuple)):
            data_table[i + 1, 1] = ', '.join(
                [t.__name__ for t in data_model[k]['otype']])
        else:
            data_table[i + 1, 1] = data_model[k]['otype'].__name__
        # Array type
        if 'atype' in data_model[k].keys():
            data_table[i + 1, 2] = data_model[k]['atype'].__name__
        else:
            data_table[i + 1, 2] = ' '
        # Description
        data_table[i + 1, 3] = to_string(data_model[k]['descr'])

    # Restrict by output_to_disk?
    if obj.output_to_disk is not None:
        keep_rows = [0]
        for _k in obj.output_to_disk:
            keep_rows.append(alternate_keys.index(_k) + 1)
    else:
        keep_rows = numpy.arange(len(data_table)).astype(int)

    # Parse
    data_table = data_table[numpy.asarray(keep_rows)]

    tbl_lines = [string_table(data_table, delimeter='rst')]
    return tbl_lines
コード例 #4
0
ファイル: build_specobj_rst.py プロジェクト: tbowers7/PypeIt
        lines = []
        lines += ['']

        # Start to append the automatically generated documentation
        lines += ['']
        lines += ['Version: {:s}'.format(obj.version)]
        lines += ['']

        keys = list(obj.datamodel.keys())
        keys.sort()

        data_table = numpy.empty((len(obj.datamodel)+1, 4), dtype=object)
        data_table[0,:] = ['Obj Key', 'Obj Type', 'Array Type', 'Description']
        for i,k in enumerate(keys):
            # Key
            data_table[i+1,0] = to_string(k, use_repr=False, verbatim=True)
            # Object Type
            if isinstance(obj.datamodel[k]['otype'], (list,tuple)):
                data_table[i+1,1] = ', '.join([t.__name__ for t in obj.datamodel[k]['otype']])
            else:
                data_table[i+1,1] = obj.datamodel[k]['otype'].__name__
            # Array type
            if 'atype' in obj.datamodel[k].keys():
                if isinstance(obj.datamodel[k]['atype'], tuple):
                    data_table[i+1,2] = ','.join(['.'.join([a.__module__, a.__name__])
                                                    if a.__module__ == 'numpy' else a.__name__ 
                                                    for a in obj.datamodel[k]['atype']])
                else:
                    data_table[i+1,2] = obj.datamodel[k]['atype'].__name__
            else:
                data_table[i+1,2] = ' '