Exemplo n.º 1
0
def test_setup_not_alfosc():
    droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/not_alfosc/grism4')
    droot += '/ALD'
    pargs = setup.parse_args(['-r', droot, '-s', 'not_alfosc'])
    setup.main(pargs)

    cwd = os.getcwd()
    setup_dir = os.path.join(cwd, 'setup_files')
    assert os.path.isdir(setup_dir), 'No setup_files directory created'

    files = glob.glob(os.path.join(setup_dir, 'not_alfosc*'))
    ext = [f.split('.')[-1] for f in files]
    expected = expected_file_extensions()
    assert np.all([e in ext for e in expected]), \
        'Did not find all setup file extensions: {0}'.format(expected)

    # Build a PypeIt file
    pargs = setup.parse_args(['-r', droot, '-s', 'not_alfosc', '-c', 'A', '-d', data_path('')])
    setup.main(pargs)
    pypeit_file = data_path('not_alfosc_A/not_alfosc_A.pypeit')
    # TODO: Why is this using pypeit.PypeIt and not pypeitsetup.PypeItSetup?
    pypeIt = pypeit.PypeIt(pypeit_file, calib_only=True)

    # Clean-up
    shutil.rmtree(setup_dir)
    shutil.rmtree(data_path('not_alfosc_A'))
Exemplo n.º 2
0
def main(args):

    import os
    import sys
    import traceback

    from pypeit import check_requirements
    from pypeit import pypeit
    from pypeit import pypeitsetup
    from pypeit import debugger

    # Initiate logging for bugs and command line help
    # These messages will not be saved to a log file
    # Set the default variables
    qck = False
    cpu = 1
    #vrb = 2

    # Load options from command line
    splitnm = os.path.splitext(args.pypeit_file)
    if splitnm[1] != '.pypeit':
        msgs.error("Bad extension for PypeIt reduction file." +
                   msgs.newline() + ".pypeit is required")
    logname = splitnm[0] + ".log"

    # Load PypeIt file to get the spectrograph (might happen twice but that is ok)
    pypeitSetup = pypeitsetup.PypeItSetup.from_pypeit_file(args.pypeit_file)

    pypeIt = pypeit.PypeIt(args.pypeit_file,
                           verbosity=args.verbosity,
                           reuse_masters=args.use_masters,
                           overwrite=args.overwrite,
                           logname=logname,
                           show=args.show)

    # JFH I don't see why this is an optional argument here. We could allow the user to modify an infinite number of parameters
    # from the command line? Why do we have the PypeIt file then? This detector can be set in the pypeit file.
    # Detector?
    if args.detector is not None:
        msgs.info("Restricting reductions to detector={}".format(
            args.detector))
        pypeIt.par['rdx']['detnum'] = int(args.detector)

    pypeIt.reduce_all()
    msgs.info('Data reduction complete')
    # QA HTML
    msgs.info('Generating QA HTML')
    pypeIt.build_qa()

    return 0
Exemplo n.º 3
0
def main(args):

    import os

    from pypeit import pypeit

    # Initiate logging for bugs and command line help
    # These messages will not be saved to a log file
    # Set the default variables
    qck = False
    cpu = 1
    #vrb = 2

    # Load options from command line
    splitnm = os.path.splitext(args.pypeit_file)
    if splitnm[1] != '.pypeit':
        msgs.error("Bad extension for PypeIt reduction file." +
                   msgs.newline() + ".pypeit is required")
    logname = splitnm[0] + ".log"

    # Instantiate the main pipeline reduction object
    pypeIt = pypeit.PypeIt(args.pypeit_file,
                           verbosity=args.verbosity,
                           reuse_masters=~args.do_not_reuse_masters,
                           overwrite=args.overwrite,
                           redux_path=args.redux_path,
                           calib_only=args.calib_only,
                           logname=logname,
                           show=args.show)

    # JFH I don't see why this is an optional argument here. We could allow the user to modify an infinite number of parameters
    # from the command line? Why do we have the PypeIt file then? This detector can be set in the pypeit file.
    # Detector?
    if args.detector is not None:
        msgs.info("Restricting reductions to detector={}".format(
            args.detector))
        pypeIt.par['rdx']['detnum'] = int(args.detector)

    if args.calib_only:
        pypeIt.calib_all()
    else:
        pypeIt.reduce_all()
    msgs.info('Data reduction complete')
    # QA HTML
    msgs.info('Generating QA HTML')
    pypeIt.build_qa()

    return 0
Exemplo n.º 4
0
    def main(args):

        import os

        from pypeit import pypeit
        from pypeit import msgs

        # Load options from command line
        splitnm = os.path.splitext(args.pypeit_file)
        if splitnm[1] != '.pypeit':
            msgs.error('Input file must have a .pypeit extension!')

        # Instantiate the main pipeline reduction object
        pypeIt = pypeit.PypeIt(args.pypeit_file,
                               verbosity=1,
                               calib_only=True,
                               show=False)

        # Grab the info without running
        calib_dict = pypeIt.calib_all(run=False)
        msgs.info('Data reduction complete')
        msgs.close()

        return calib_dict
Exemplo n.º 5
0
def main(args):

    import os
    import sys
    import numpy as np

    from IPython import embed

    from pypeit import pypeit
    from pypeit import pypeitsetup
    from pypeit.core import framematch
    from pypeit import msgs


    # Setup
    data_files = [os.path.join(args.full_rawpath, args.fileA),
                  os.path.join(args.full_rawpath,args.fileB)]
    ps = pypeitsetup.PypeItSetup(data_files, path='./', spectrograph_name='keck_nires')
    ps.build_fitstbl()
    # TODO -- Get the type_bits from  'science'
    bm = framematch.FrameTypeBitMask()
    file_bits = np.zeros(2, dtype=bm.minimum_dtype())
    file_bits[0] = bm.turn_on(file_bits[0], ['arc', 'science', 'tilt'])
    file_bits[1] = bm.turn_on(file_bits[0], ['arc', 'science', 'tilt'])

    ps.fitstbl.set_frame_types(file_bits)
    ps.fitstbl.set_combination_groups()
    # Extras
    ps.fitstbl['setup'] = 'A'
    # A-B
    ps.fitstbl['bkg_id'] = [2,1]

    # Calibrations
    master_dir = os.getenv('NIRES_MASTERS')
    if master_dir is None:
        msgs.error('You need to set an Environmental variable NIRES_MASTERS that points at the '
                   'Master Calibs')

    # Config the run
    cfg_lines = ['[rdx]']
    cfg_lines += ['    spectrograph = {0}'.format('keck_nires')]
    cfg_lines += ['    redux_path = {0}'.format(os.path.join(os.getcwd(),'keck_nires_A'))]
    # Calibrations
    cfg_lines += ['[baseprocess]']
    cfg_lines += ['    use_biasimage = False']
    cfg_lines += ['    use_overscan = False']
    cfg_lines += ['    use_pixelflat = False']
    cfg_lines += ['[calibrations]']
    cfg_lines += ['    master_dir = {0}'.format(master_dir)]
    cfg_lines += ['    raise_chk_error = False']
    cfg_lines += ['[scienceframe]']
    cfg_lines += ['    [[process]]']
    cfg_lines += ['        mask_cr = False']
    cfg_lines += ['[reduce]']
    cfg_lines += ['    [[extraction]]']
    cfg_lines += ['        skip_optimal = True']
    if args.box_radius is not None: # Boxcar radius
        cfg_lines += ['        boxcar_radius = {0}'.format(args.box_radius)]
    cfg_lines += ['    [[findobj]]']
    cfg_lines += ['        skip_second_find = True']

    # Write
    ofiles = ps.fitstbl.write_pypeit(configs='A', write_bkg_pairs=True, cfg_lines=cfg_lines)
    if len(ofiles) > 1:
        msgs.error("Bad things happened..")

    # Instantiate the main pipeline reduction object
    pypeIt = pypeit.PypeIt(ofiles[0], verbosity=2,
                           reuse_masters=True, overwrite=True,
                           logname='nires_proc_AB.log', show=False)
    # Run
    pypeIt.reduce_all()
    msgs.info('Data reduction complete')
    # QA HTML
    msgs.info('Generating QA HTML')
    pypeIt.build_qa()

    return 0
Exemplo n.º 6
0
def main(pargs):

    import os
    import numpy as np

    from IPython import embed

    from pypeit import pypeit
    from pypeit import pypeitsetup
    from pypeit.core import framematch

    spec = pargs.spectrograph

    # Config the run
    cfg_lines = ['[rdx]']
    cfg_lines += ['    spectrograph = {0}'.format(spec)]
    cfg_lines += [
        '    redux_path = {0}_A'.format(os.path.join(os.getcwd(), spec))
    ]
    cfg_lines += ['    detnum = {0}'.format(pargs.det)]
    if pargs.ignore_headers:
        cfg_lines += ['    ignore_bad_headers = True']
    cfg_lines += ['[scienceframe]']
    cfg_lines += ['    [[process]]']
    cfg_lines += ['          cr_reject = False']
    if pargs.user_pixflat is not None:
        cfg_lines += ['[calibrations]']
        cfg_lines += ['    [[flatfield]]']
        cfg_lines += ['        frame = {0}'.format(pargs.user_pixflat)]
    cfg_lines += ['[reduce]']
    cfg_lines += ['    [[extraction]]']
    cfg_lines += ['         skip_optimal = True']
    if pargs.box_radius is not None:  # Boxcar radius
        cfg_lines += ['    boxcar_radius = {0}'.format(pargs.box_radius)]
    cfg_lines += ['    [[findobj]]']
    cfg_lines += ['         skip_second_find = True']

    # Data files
    data_files = [
        os.path.join(pargs.full_rawpath, pargs.arc),
        os.path.join(pargs.full_rawpath, pargs.flat),
        os.path.join(pargs.full_rawpath, pargs.science)
    ]

    # Setup
    ps = pypeitsetup.PypeItSetup(data_files,
                                 path='./',
                                 spectrograph_name=spec,
                                 cfg_lines=cfg_lines)
    ps.build_fitstbl()
    # TODO -- Get the type_bits from  'science'
    bm = framematch.FrameTypeBitMask()
    file_bits = np.zeros(3, dtype=bm.minimum_dtype())
    file_bits[0] = bm.turn_on(file_bits[0], ['arc', 'tilt'])
    file_bits[1] = bm.turn_on(
        file_bits[1],
        ['pixelflat', 'trace'] if pargs.user_pixflat is None else 'trace')
    file_bits[2] = bm.turn_on(file_bits[2], 'science')

    # PypeItSetup sorts according to MJD
    #   Deal with this
    asrt = []
    for ifile in data_files:
        bfile = os.path.basename(ifile)
        idx = ps.fitstbl['filename'].data.tolist().index(bfile)
        asrt.append(idx)
    asrt = np.array(asrt)

    # Set bits
    ps.fitstbl.set_frame_types(file_bits[asrt])
    ps.fitstbl.set_combination_groups()
    # Extras
    ps.fitstbl['setup'] = 'A'

    # Write
    ofiles = ps.fitstbl.write_pypeit('',
                                     configs=['A'],
                                     write_bkg_pairs=True,
                                     cfg_lines=cfg_lines)
    if len(ofiles) > 1:
        msgs.error("Bad things happened..")

    # Instantiate the main pipeline reduction object
    pypeIt = pypeit.PypeIt(ofiles[0],
                           verbosity=2,
                           reuse_masters=True,
                           overwrite=True,
                           logname='mos.log',
                           show=False)
    # Run
    pypeIt.reduce_all()
    msgs.info('Data reduction complete')
    # QA HTML
    msgs.info('Generating QA HTML')
    pypeIt.build_qa()

    return 0
Exemplo n.º 7
0
def main(args: argparse.Namespace):
    t = time.perf_counter()
    # need an arc frame and a flat frame
    root = args.fname.rstrip('0123456789.fits')
    paths = glob.glob(f'{root}*.fits')

    spectrograph = 'p200_dbsp_red' if 'red' in os.path.basename(
        args.fname) else 'p200_dbsp_blue'
    arm = spectrograph.split('_')[-1]

    CFG_LINES = get_cfg_lines(spectrograph)

    flatimg = ""
    arcimg = ""
    sciimg = args.fname

    calib_only = not os.path.isfile(sciimg)

    if calib_only:

        for path in paths:
            with fits.open(path) as hdul:
                if not flatimg:
                    if hdul[0].header['OBJECT'] == 'flat' or hdul[0].header[
                            'IMGTYPE'] == 'flat':
                        flatimg = path
                if not arcimg:
                    if hdul[0].header['OBJECT'] == 'arcs' or hdul[0].header[
                            'IMGTYPE'] == 'cal':
                        arcimg = path
                if flatimg and arcimg:
                    break

        if not (flatimg and arcimg):
            raise Exception(
                f"Could not find a flat and an arc frame in the same directory as {root}!"
            )
        files = [arcimg, flatimg]
    else:
        files = [sciimg]

    ps = PypeItSetup(files,
                     path="./",
                     spectrograph_name=spectrograph,
                     cfg_lines=CFG_LINES)
    ps.build_fitstbl()

    bm = framematch.FrameTypeBitMask()
    file_bits = np.zeros(len(files), dtype=bm.minimum_dtype())
    if calib_only:
        file_bits[0] = bm.turn_on(file_bits[0], ['arc', 'tilt'])
        file_bits[1] = bm.turn_on(file_bits[1],
                                  ['pixelflat', 'trace', 'illumflat'])
    else:
        file_bits[0] = bm.turn_on(file_bits[0], 'science')

    asrt = np.array([
        ps.fitstbl['filename'].data.tolist().index(os.path.basename(fname))
        for fname in files
    ])
    ps.fitstbl.set_frame_types(file_bits[asrt])
    ps.fitstbl.set_combination_groups()

    ps.fitstbl['setup'] = 'A'

    ofiles = ps.fitstbl.write_pypeit(configs='A', cfg_lines=CFG_LINES)

    pypeIt = pypeit.PypeIt(ofiles[0],
                           verbosity=0,
                           reuse_masters=True,
                           overwrite=True,
                           logname='dbsp_ql.log',
                           show=False,
                           calib_only=calib_only)
    if calib_only:
        pypeIt.calib_all()
    else:
        pypeIt.reduce_all()
    pypeIt.build_qa()

    output_spec2ds = list(filter(lambda f: os.path.isfile(os.path.join('Science', f)), [
            pypeIt.spec_output_file(i, True) \
            for i in range(len(pypeIt.fitstbl.table)) \
            if pypeIt.fitstbl.table[i]['frametype'] in ['science']
        ]))

    output_spec1ds = list(filter(lambda f: os.path.isfile(os.path.join('Science', f)), [
            pypeIt.spec_output_file(i) \
            for i in range(len(pypeIt.fitstbl.table)) \
            if pypeIt.fitstbl.table[i]['frametype'] in ['science']
        ]))

    if output_spec1ds and not calib_only:
        sensfiles = [
            resource_filename("dbsp_drp", f"data/sens_{arm}_archived.fits")
        ]
        FxCalib = fluxcalibrate.FluxCalibrate.get_instance(
            output_spec1ds, sensfiles, par=ps.par['fluxcalib'])

    print(f"Time elapsed: {time.perf_counter() - t}s.")

    if not calib_only and not args.no_show:
        p1 = Process(target=show_spec2d_helper, args=(output_spec2ds[0], ))
        p1.start()
        if output_spec1ds:
            with fits.open(output_spec1ds[0]) as hdul:
                specs = len(hdul) - 2
            parr = [None] * specs
            for i in range(specs):
                parr[i] = Process(target=show_spec1d_helper,
                                  args=(str(i), output_spec1ds[0]))
                parr[i].start()
Exemplo n.º 8
0
def main(pargs):

    import os
    import numpy as np

    from IPython import embed

    from pypeit import pypeit
    from pypeit import pypeitsetup
    from pypeit.core import framematch

    spec = 'keck_deimos'

    # Setup
    data_files = [
        os.path.join(pargs.full_rawpath, pargs.arc),
        os.path.join(pargs.full_rawpath, pargs.flat),
        os.path.join(pargs.full_rawpath, pargs.science)
    ]
    ps = pypeitsetup.PypeItSetup(data_files, path='./', spectrograph_name=spec)
    ps.build_fitstbl()
    # TODO -- Get the type_bits from  'science'
    bm = framematch.FrameTypeBitMask()
    bits = [
        bm.bits[iftype]
        for iftype in ['arc', 'pixelflat', 'trace', 'science', 'tilt']
    ]
    ps.fitstbl.set_frame_types(
        np.array(
            [2**bits[0] + 2**bits[4], 2**bits[1] + 2**bits[2],
             2**bits[3]]))  # 1=arc, 16=pixelflat, 32=science, trace=128
    ps.fitstbl.set_combination_groups()
    # Extras
    ps.fitstbl['setup'] = 'A'

    # Config the run
    rdx_path = '{0}_A'.format(os.path.join(os.getcwd(), spec))
    cfg_lines = ['[rdx]']
    cfg_lines += ['    spectrograph = {0}'.format(spec)]
    cfg_lines += ['    redux_path = {0}'.format(rdx_path)]
    cfg_lines += ['    detnum = {0}'.format(pargs.det)]
    cfg_lines += ['[calibrations]']
    cfg_lines += ['    [[scienceframe]]']
    cfg_lines += ['        [[process]]']
    cfg_lines += ['              cr_reject = False']
    cfg_lines += ['[scienceimage]']
    cfg_lines += ['    boxcar_only = True']
    cfg_lines += ['    skip_second_find = True']
    # Boxcar radius
    if pargs.box_radius is not None:
        cfg_lines += ['    boxcar_radius = {0}'.format(pargs.box_radius)]

    # Write
    ofiles = ps.fitstbl.write_pypeit('',
                                     configs=['A'],
                                     write_bkg_pairs=True,
                                     cfg_lines=cfg_lines)
    if len(ofiles) > 1:
        msgs.error("Bad things happened..")

    # Instantiate the main pipeline reduction object
    pypeIt = pypeit.PypeIt(ofiles[0],
                           verbosity=2,
                           reuse_masters=True,
                           overwrite=True,
                           logname='deimos.log',
                           show=False)
    # Run
    pypeIt.reduce_all()
    msgs.info('Data reduction complete')
    # QA HTML
    msgs.info('Generating QA HTML')
    pypeIt.build_qa()

    return 0