Exemple #1
0
def parser(options=None):
    # TODO: Add argument that specifies the log file
    parser = argparse.ArgumentParser(
        description="Script to setup a PypeIt run [v3]")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-r',
                       '--root',
                       type=str,
                       default=None,
                       help='File path+root, e.g. /data/Kast/b ')
    #group.add_argument('-p', '--pypeit_file', type=str, default=None,
    #                   help='PypeIt file to use')
    parser.add_argument('-s',
                        '--spectrograph',
                        default=None,
                        type=str,
                        help='A valid spectrograph identifier: {0}'.format(
                            ', '.join(valid_spectrographs())))
    parser.add_argument(
        '-e',
        '--extension',
        default='.fits',
        help='File extension; compression indicators (e.g. .gz) not required.')
    parser.add_argument('-d',
                        '--output_path',
                        default=None,
                        help='Path to top-level output directory.  '
                        'Default is the current working directory.')
    parser.add_argument('-o',
                        '--overwrite',
                        default=False,
                        action='store_true',
                        help='Overwrite any existing files/directories')
    parser.add_argument(
        '-c',
        '--cfg_split',
        default=None,
        type=str,
        help=
        'Generate the PypeIt files and folders by input configuration. [all or A,B or B,D,E or E]'
    )
    parser.add_argument(
        '-b',
        '--background',
        default=False,
        action='store_true',
        help='Include the background-pair columns for the user to edit')
    parser.add_argument('-v',
                        '--verbosity',
                        type=int,
                        default=2,
                        help='Level of verbosity from 0 to 2; default is 2.')
    #    parser.add_argument('-q', '--quick', default=False, help='Quick reduction',
    #                        action='store_true')
    #    parser.add_argument('-c', '--cpus', default=False,
    #                        help='Number of CPUs for parallel processing', action='store_true')
    #    parser.print_help()

    return parser.parse_args() if options is None else parser.parse_args(
        options)
Exemple #2
0
def main(args):

    import os
    import pdb as debugger

    from pypeit import msgs
    from pypeit.pypeitsetup import PypeItSetup

    # Check that the spectrograph is provided if using a file root
    if args.root is not None:
        if args.spectrograph is None:
            raise ValueError(
                'Must provide spectrograph identifier with file root.')
        # Check that input spectrograph is supported
        instruments_served = valid_spectrographs()
        if args.spectrograph not in instruments_served:
            raise ValueError(
                'Instrument \'{0}\' unknown to PypeIt.\n'.format(
                    args.spectrograph) +
                '\tOptions are: {0}\n'.format(', '.join(instruments_served)) +
                '\tSelect an available instrument or consult the documentation '
                + 'on how to add a new instrument.')

    # Get the output directory
    output_path = os.getcwd() if args.output_path is None else args.output_path
    sort_dir = os.path.join(output_path, 'setup_files')

    # Initialize PypeItSetup based on the arguments
    if args.root is not None:
        ps = PypeItSetup.from_file_root(args.root,
                                        args.spectrograph,
                                        extension=args.extension,
                                        output_path=sort_dir)
    else:
        # Should never reach here
        raise IOError('Need to set -r !!')

    # Run the setup
    ps.run(setup_only=True, sort_dir=sort_dir, write_bkg_pairs=args.background)

    # Use PypeItMetaData to write the complete PypeIt file
    if args.cfg_split is not None:
        pypeit_file = os.path.join(output_path,
                                   '{0}.pypeit'.format(args.spectrograph))
        config_list = [item.strip() for item in args.cfg_split.split(',')]
        ps.fitstbl.write_pypeit(pypeit_file,
                                cfg_lines=ps.user_cfg,
                                write_bkg_pairs=args.background,
                                configs=config_list)
    return 0
Exemple #3
0
def parser(options=None):

    import argparse
    from pypeit.spectrographs.util import valid_spectrographs

    parser = argparse.ArgumentParser()

    # Require either a pypeit file or a fits file
    inp = parser.add_mutually_exclusive_group(required=True)
    inp.add_argument('-f',
                     '--pypeit_file',
                     default=None,
                     type=str,
                     help='PypeIt reduction file')
    inp.add_argument('-t',
                     '--trace_file',
                     default=None,
                     type=str,
                     help='Image to trace')

    parser.add_argument(
        '-g',
        '--group',
        default=None,
        help='If providing a pypeit file, use the trace images for this '
        'calibration group.  If None, use the first calibration group.')
    parser.add_argument(
        '-d',
        '--detector',
        default=None,
        type=int,
        help='Only analyze the specified detector; otherwise analyze all.')
    parser.add_argument(
        '-s',
        '--spectrograph',
        default=None,
        type=str,
        help='A valid spectrograph identifier, which is only used if providing'
        'files directly: {0}'.format(', '.join(valid_spectrographs())))
    parser.add_argument(
        '-b',
        '--binning',
        default=None,
        type=str,
        help='Image binning in spectral and spatial directions.  Only used if'
        'providing files directly; default is 1,1.')
    parser.add_argument('-p',
                        '--redux_path',
                        default=None,
                        help='Path to top-level output directory.  '
                        'Default is the current working directory.')
    parser.add_argument(
        '-m',
        '--master_dir',
        default='Masters',
        help='Name for directory in output path for Master file(s) relative '
        'to the top-level directory.')
    parser.add_argument('-o',
                        '--overwrite',
                        default=False,
                        action='store_true',
                        help='Overwrite any existing files/directories')

    parser.add_argument('--debug',
                        default=False,
                        action='store_true',
                        help='Run in debug mode.')
    parser.add_argument(
        '--show',
        default=False,
        action='store_true',
        help='Show the stages of trace refinements (only for the new code).')

    return parser.parse_args() if options is None else parser.parse_args(
        options)
    lines += p.to_rst_table()
    lines += ['']

    lines += ['Instrument-Specific Default Configuration']
    lines += ['+++++++++++++++++++++++++++++++++++++++++']
    lines += ['']

    lines += textwrap.wrap('The following provides the changes to the global default parameters '
                           'provided above for each instrument.  That is, if one were to include '
                           'these in the PypeIt file, you would be reproducing the effect of the '
                           '`default_pypeit_par` method specific to each derived '
                           ':class:`pypeit.spectrographs.spectrograph.Spectrograph` class.', 72)
    lines += ['']

    spectrographs = valid_spectrographs()
    for spec in spectrographs:
        s = load_spectrograph(spec)
        lines += [ ' '.join([s.telescope['name'], s.camera]) ]
        lines += [ '-'*len(lines[-1]) ]
        lines += [ 'Alterations to the default parameters are::' ]
        lines += ['']
        sl = s.default_pypeit_par().to_config(include_descr=False, exclude_defaults=True)
        lines += [ '  ' + l for l in sl ]
        lines += ['']
    lines += ['']

    output_rst = os.path.join(pypeit_root, 'doc', 'pypeit_par.rst')
    with open(output_rst, 'w') as f:
        f.write('\n'.join(lines))