Exemplo n.º 1
0
def write_dependency_table(setup_file, path):
    ofile = os.path.join(path, 'dependencies_table.rst')

    setup = configparser.ConfigParser()
    setup.read(setup_file)

    user_requires = numpy.sort(
        setup['options']['install_requires'].split('\n')[1:])
    dev_requires = numpy.sort(
        setup['options.extras_require']['dev'].split('\n')[1:])
    required_python = setup['options']['python_requires']

    data_table = numpy.empty((3, 2), dtype=object)
    data_table[0, :] = ['Python Version', f'``{required_python}``']
    data_table[1, :] = [
        'Required for users', ', '.join([f'``{u}``' for u in user_requires])
    ]
    data_table[2, :] = [
        'Required for developers',
        ', '.join([f'``{d}``' for d in dev_requires])
    ]

    lines = string_table(data_table, delimeter='rst', has_header=False)
    with open(ofile, 'w') as f:
        f.write(lines)
    print('Wrote: {}'.format(ofile))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
def write_detector_table(ofile):

    allspec = spectrograph_classes()
    data_table = [[
        'Instrument', 'Det', 'specaxis', 'specflip', 'spatflip', 'namp',
        'gain', 'RN', 'darkcurr', 'min', 'sat', 'nonlinear', 'platescale'
    ]]
    for key in allspec.keys():
        spec = allspec[key]()
        for i in range(spec.ndet):
            det = spec.get_detector_par(i + 1)
            if det is None:  # For HIRES
                continue
            dt_row = [f'``{key}``'] if i == 0 else ['...']
            dt_row += [
                str(i + 1),
                str(det.specaxis),
                str(det.specflip),
                str(det.spatflip), '``None``' if det.numamplifiers is None else
                str(det.numamplifiers), '``None``'
                if det.gain is None else ', '.join([str(g) for g in det.gain]),
                '``None``' if det.ronoise is None else ', '.join(
                    [str(r) for r in det.ronoise]),
                '``None``' if det.darkcurr is None else str(det.darkcurr),
                f'{det.mincounts:.1e}',
                str(det.saturation), f'{det.nonlinear:.4f}',
                f'{det.platescale:.4f}'
            ]
            data_table += [dt_row]
        if key == 'vlt_fors2':
            # Get the second detector for VLT-FORS2
            det = spec.get_detector_par(2)
            dt_row = [
                '...', '2',
                str(det.specaxis),
                str(det.specflip),
                str(det.spatflip), '``None``' if det.numamplifiers is None else
                str(det.numamplifiers), '``None``'
                if det.gain is None else ', '.join([str(g) for g in det.gain]),
                '``None``' if det.ronoise is None else ', '.join(
                    [str(r) for r in det.ronoise]),
                '``None``' if det.darkcurr is None else str(det.darkcurr),
                f'{det.mincounts:.1e}',
                str(det.saturation), f'{det.nonlinear:.4f}',
                f'{det.platescale:.4f}'
            ]
            data_table += [dt_row]

    lines = string_table(numpy.atleast_1d(data_table), delimeter='rst')
    with open(ofile, 'w') as f:
        f.write(lines)
    print('Wrote: {}'.format(ofile))
Exemplo n.º 4
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))
Exemplo n.º 5
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
Exemplo n.º 6
0
def write_imgproc_def_table(ofile, spec=None):

    # List of parameters to include in the table
    # NOTE: These are ordered according to their use in
    # pypeit.images.rawimage.RawImage.process.
    par_list = [
        'apply_gain', 'use_pattern', 'empirical_rn', 'use_overscan', 'trim',
        'orient', 'use_biasimage', 'use_darkimage', 'spat_flexure_correct',
        'use_pixelflat', 'use_illumflat', 'use_specillum', 'shot_noise',
        'noise_floor', 'mask_cr'
    ]

    # NOTE: These are ordered according to their use in
    # pypeit.calibrations.Calibrations (although there are slight
    # differences between MultiSlit/Echelle and IFU).  And I've skipped
    # the pinholeframe.
    frame_list = [
        'biasframe', 'darkframe', 'traceframe', 'arcframe', 'tiltframe',
        'alignframe', 'pixelflatframe', 'illumflatframe', 'skyframe',
        'standardframe', 'scienceframe'
    ]

    procpar = ProcessImagesPar()
    par = PypeItPar() if spec is None else spec.default_pypeit_par()

    data_table = numpy.empty((len(par_list) + 1, len(frame_list) + 2),
                             dtype=object)
    data_table[0,:] = ['Parameter', 'Default'] \
                        + [f'``{t}``'.replace('frame','') for t in frame_list]
    # Parameter names and defaults
    for i, p in enumerate(par_list):
        data_table[i + 1, 0] = f'``{p}``'
        data_table[i + 1, 1] = f'``{procpar[p]}``'
    # Frame-dependent parameter defaults
    for j, t in enumerate(frame_list):
        _par = par[t]['process'] if t == 'scienceframe' else par[
            'calibrations'][t]['process']
        for i, p in enumerate(par_list):
            data_table[i + 1, j +
                       2] = '' if _par[p] == procpar[p] else f'``{_par[p]}``'

    lines = string_table(data_table, delimeter='rst')
    with open(ofile, 'w') as f:
        f.write(lines)
    print('Wrote: {}'.format(ofile))
Exemplo n.º 7
0
def write_detector_datamodel(ofile):
    det_dm = DetectorContainer.datamodel
    keys = numpy.sort(list(det_dm.keys()))
    nkeys = len(keys)
    data_table = numpy.empty((nkeys + 1, 3), dtype=object)
    data_table[0, :] = ['Key', 'Type', 'Description']
    for i, key in enumerate(keys):
        data_table[i + 1, 0] = f'``{key}``'
        if isinstance(det_dm[key]['otype'], tuple):
            data_table[i + 1, 1] = ','.join(
                [t.__name__ for t in det_dm[key]['otype']])
        else:
            data_table[i + 1, 1] = det_dm[key]['otype'].__name__
        data_table[i + 1, 2] = det_dm[key]['descr']
    lines = string_table(data_table, delimeter='rst')
    with open(ofile, 'w') as f:
        f.write(lines)
    print('Wrote: {}'.format(ofile))
Exemplo n.º 8
0
                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] = ' '
            if data_table[i+1,2][-1] == '_':
                data_table[i+1,2] = data_table[i+1,2][:-1]

            # Description
            data_table[i+1,3] = to_string(obj.datamodel[k]['descr'])

        lines += [string_table(data_table, delimeter='rst')]

        # Finish
        with open(ofile, 'w') as f:
            f.write('\n'.join(lines))

        print('Wrote: {}'.format(ofile))
    print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))