Esempio n. 1
0
def run_sky_sub(metadata, prev_suffix, curr_suffix, ns=False):
    if ns:
        run_sky_sub_ns(metadata, prev_suffix, curr_suffix)
    else:
        # subtract sky frames from science objects
        for obs in metadata['sci']:
            if len(obs['sky']) > 0:
                sky_fn = obs['sky'][0]
                sky_proc_fn = os.path.join(out_dir, '%s.p%s.fits' % (sky_fn, prev_suffix))
                for fn in obs['sci']:
                    in_fn  = os.path.join(out_dir, '%s.p%s.fits' % (fn, prev_suffix))
                    out_fn = os.path.join(out_dir, '%s.p%s.fits' % (fn, curr_suffix))
                    print('Subtracting sky frame for %s' % in_fn.split('/')[-1])
                    # subtract scaled sky frame!
                    pywifes.scaled_imarith_mef(
                        in_fn, '-', sky_proc_fn, out_fn,
                        scale='exptime')
            else:
                for fn in obs['sci']:
                    in_fn  = os.path.join(out_dir, '%s.p%s.fits' % (fn, prev_suffix))
                    out_fn = os.path.join(out_dir, '%s.p%s.fits' % (fn, curr_suffix))
                    print('Copying image %s' % in_fn.split('/')[-1])
                    # subtract scaled sky frame!
                    pywifes.imcopy(in_fn, out_fn)
        # copy stdstar frames
        std_obs_list = get_std_obs_list(metadata)
        for fn in std_obs_list:
            in_fn  = os.path.join(out_dir, '%s.p%s.fits' % (fn, prev_suffix))
            out_fn = os.path.join(out_dir, '%s.p%s.fits' % (fn, curr_suffix))
            if skip_done and os.path.isfile(out_fn):
                continue
            print('Copying standard star image %s' % in_fn.split('/')[-1])
            pywifes.imcopy(in_fn, out_fn)
    return
Esempio n. 2
0
def run_obs_coadd(metadata,
                  prev_suffix,
                  curr_suffix,
                  method='sum',
                  scale=None):
    for obs in (metadata['sci'] + metadata['std']):
        # if just one, then copy it
        if len(obs['sci']) == 1:
            fn = obs['sci'][0]
            in_fn = '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
            out_fn = '%s%s.p%s.fits' % (out_dir, fn, curr_suffix)
            print 'Copying image %s' % in_fn.split('/')[-1]
            pywifes.imcopy(in_fn, out_fn)
        # coadd sci frames!
        else:
            in_fn_list = [
                '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
                for fn in obs['sci']
            ]
            out_fn = '%s%s.p%s.fits' % (out_dir, obs['sci'][0], curr_suffix)
            print 'Coadding images for %s' % in_fn_list[0].split('/')[-1]
            pywifes.imcombine_mef(in_fn_list,
                                  out_fn,
                                  scale=scale,
                                  method=method)
    return
Esempio n. 3
0
def run_bias_sub(metadata, prev_suffix, curr_suffix,
                 method='sub', **args):
    full_obs_list = get_full_obs_list(metadata)
    sci_obs_list  = get_sci_obs_list(metadata)
    std_obs_list  = get_std_obs_list(metadata)
    sky_obs_list  = get_sky_obs_list(metadata)
    for fn in full_obs_list:
        in_fn  = os.path.join(out_dir, '%s.p%s.fits' % (fn, prev_suffix))
        out_fn = os.path.join(out_dir, '%s.p%s.fits' % (fn, curr_suffix))
        if skip_done and os.path.isfile(out_fn):
            continue
        # figure out which bias to subtract
        local_biases = get_associated_calib(metadata,fn, 'bias')
        if local_biases:
            local_bias_fn = get_associated_calib(metadata,fn,'bias')[0]
            local_superbias = os.path.join(out_dir, '%s.fits' % (local_bias_fn+'.lsb'))
            bias_fit_fn = os.path.join(out_dir, '%s.fits' % (local_bias_fn+'.lsb_fit'))
            bias_type = 'local'
        else:
            bias_fit_fn = superbias_fit_fn
            bias_type = 'global'
        # subtract it!
        print('Subtracting %s superbias for %s'%(bias_type, in_fn.split('/')[-1]))
        if method == 'copy':
            pywifes.imcopy(in_fn, out_fn)
        else:
            pywifes.imarith(in_fn, '-', bias_fit_fn, out_fn, 
                            data_hdu=my_data_hdu)
    return
Esempio n. 4
0
def run_bias_sub(metadata, prev_suffix, curr_suffix,
                 method='sub', **args):
    full_obs_list = get_full_obs_list(metadata)
    sci_obs_list  = get_sci_obs_list(metadata)
    std_obs_list  = get_std_obs_list(metadata)
    sky_obs_list  = get_sky_obs_list(metadata)
    for fn in full_obs_list:
        in_fn  = '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
        out_fn = '%s%s.p%s.fits' % (out_dir, fn, curr_suffix)
        if skip_done and os.path.isfile(out_fn):
            continue
        # figure out which bias to subtract
        local_biases = get_associated_calib(metadata,fn, 'bias')
        if local_biases:
            local_bias_fn = get_associated_calib(metadata,fn,'bias')[0]
            local_superbias = '%s%s.fits' % (out_dir, local_bias_fn+'.lsb')
            bias_fit_fn = '%s%s.fits' % (out_dir, local_bias_fn+'.lsb_fit')
            bias_type = 'local'
        else:
            bias_fit_fn = superbias_fit_fn
            bias_type = 'global'
        # subtract it!
        print 'Subtracting %s superbias for %s' % (
            bias_type, in_fn.split('/')[-1])
        if method == 'copy':
            pywifes.imcopy(in_fn, out_fn)
        else:
            pywifes.imarith(in_fn, '-', bias_fit_fn, out_fn, 
                            data_hdu=my_data_hdu)
    return
Esempio n. 5
0
def run_sky_sub(metadata, prev_suffix, curr_suffix, ns=False):
    if ns:
        run_sky_sub_ns(metadata, prev_suffix, curr_suffix)
    else:
        # subtract sky frames from science objects
        for obs in metadata['sci']:
            if len(obs['sky']) > 0:
                sky_fn = obs['sky'][0]
                sky_proc_fn = '%s%s.p%s.fits' % (out_dir, sky_fn, prev_suffix)
                for fn in obs['sci']:
                    in_fn  = '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
                    out_fn = '%s%s.p%s.fits' % (out_dir, fn, curr_suffix)
                    print 'Subtracting sky frame for %s' % in_fn.split('/')[-1]
                    # subtract scaled sky frame!
                    pywifes.scaled_imarith_mef(
                        in_fn, '-', sky_proc_fn, out_fn,
                        scale='exptime')
            else:
                for fn in obs['sci']:
                    in_fn  = '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
                    out_fn = '%s%s.p%s.fits' % (out_dir, fn, curr_suffix)
                    print 'Copying image %s' % in_fn.split('/')[-1]
                    # subtract scaled sky frame!
                    pywifes.imcopy(in_fn, out_fn)
        # copy stdstar frames
        std_obs_list = get_std_obs_list(metadata)
        for fn in std_obs_list:
            in_fn  = '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
            out_fn = '%s%s.p%s.fits' % (out_dir, fn, curr_suffix)
            if skip_done and os.path.isfile(out_fn):
                continue
            print 'Copying standard star image %s' % in_fn.split('/')[-1]
            pywifes.imcopy(in_fn, out_fn)
    return
Esempio n. 6
0
def run_obs_coadd(metadata,
                  prev_suffix,
                  curr_suffix,
                  method='sum',
                  scale=None):
    for obs in (metadata['sci'] + metadata['std']):
        # if just one, then copy it
        if len(obs['sci']) == 1:
            fn = obs['sci'][0]
            in_fn = os.path.join(out_dir, '%s.p%s.fits' % (fn, prev_suffix))
            out_fn = os.path.join(out_dir, '%s.p%s.fits' % (fn, curr_suffix))
            if skip_done and os.path.isfile(out_fn):
                continue
            print('Copying image %s' % in_fn.split('/')[-1])
            pywifes.imcopy(in_fn, out_fn)
        # coadd sci frames!
        else:
            in_fn_list = [
                os.path.join(out_dir, '%s.p%s.fits' % (fn, prev_suffix))
                for fn in obs['sci']
            ]
            out_fn = os.path.join(out_dir,
                                  '%s.p%s.fits' % (obs['sci'][0], curr_suffix))
            print('Coadding images for %s' % in_fn_list[0].split('/')[-1])
            pywifes.imcombine_mef(in_fn_list,
                                  out_fn,
                                  scale=scale,
                                  method=method)
    return
Esempio n. 7
0
def run_superbias(metadata,
                  prev_suffix,
                  curr_suffix,
                  method='row_med',
                  **args):
    bias_list = [
        os.path.join(out_dir, '%s.p%s.fits' % (x, prev_suffix))
        for x in metadata['bias']
    ]
    print('Calculating Global Superbias')
    pywifes.imcombine(bias_list, superbias_fn, data_hdu=my_data_hdu)
    # decide what bias model you will actually subtract - could be just data
    if method == 'fit' or method == 'row_med':
        # Fit a smart surface to the bias or take the median
        # A bit experimental so far ... but you know what you are doing, right ?
        pywifes.generate_wifes_bias_fit(superbias_fn,
                                        superbias_fit_fn,
                                        data_hdu=my_data_hdu,
                                        method=method,
                                        **args)
    else:
        pywifes.imcopy(superbias_fn, superbias_fit_fn)
    # generate local superbiases for any science frames
    sci_obs_list = get_sci_obs_list(metadata)
    std_obs_list = get_std_obs_list(metadata)
    for fn in (sci_obs_list + std_obs_list):
        # Find if there is an associated bias (or more ?)
        local_biases = get_associated_calib(metadata, fn, 'bias')
        if local_biases:
            local_bias_fn = get_associated_calib(metadata, fn, 'bias')[0]
            print('Calculating Local Superbias for %s' % local_bias_fn)
            local_superbias = os.path.join(
                out_dir, '%s.fits' % (local_bias_fn + '.lsb'))
            local_superbias_fit = os.path.join(
                out_dir, '%s.fits' % (local_bias_fn + '.lsb_fit'))
            if os.path.isfile(local_superbias_fit):
                continue
            # step 1 - coadd biases
            local_biases_filename = [
                os.path.join(out_dir, '%s.p%s.fits' % (x, prev_suffix))
                for x in local_biases
            ]
            pywifes.imcombine(local_biases_filename,
                              local_superbias,
                              data_hdu=my_data_hdu)
            # step 2 - generate fit!
            if method == 'fit' or method == 'row_med':
                pywifes.generate_wifes_bias_fit(local_superbias,
                                                local_superbias_fit,
                                                data_hdu=my_data_hdu,
                                                method=method,
                                                **args)
            else:
                pywifes.imcopy(local_superbias, local_superbias_fit)
    return
Esempio n. 8
0
def run_superbias(metadata, prev_suffix, curr_suffix,
                  method='row_med', **args):
    bias_list = [
        '%s%s.p%s.fits' % (out_dir, x, prev_suffix)
        for x in metadata['bias']]
    print 'Calculating Global Superbias'
    pywifes.imcombine(bias_list, superbias_fn, data_hdu=my_data_hdu)
    # decide what bias model you will actually subtract - could be just data
    if method == 'fit' or method == 'row_med':
        # Fit a smart surface to the bias or take the median
        # A bit experimental so far ... but you know what you are doing, right ?
        pywifes.generate_wifes_bias_fit(
            superbias_fn, superbias_fit_fn, 
            data_hdu=my_data_hdu, method=method, **args)
    else:
        pywifes.imcopy(superbias_fn, superbias_fit_fn)
    # generate local superbiases for any science frames
    sci_obs_list  = get_sci_obs_list(metadata)
    std_obs_list  = get_std_obs_list(metadata)
    for fn in (sci_obs_list + std_obs_list):
        # Find if there is an associated bias (or more ?)
        local_biases = get_associated_calib(metadata,fn, 'bias')
        if local_biases:
            local_bias_fn = get_associated_calib(metadata,fn,'bias')[0]
            print 'Calculating Local Superbias for %s' % local_bias_fn
            local_superbias = '%s%s.fits' % (out_dir, local_bias_fn+'.lsb')
            local_superbias_fit = '%s%s.fits' % (out_dir, local_bias_fn+'.lsb_fit')
            if os.path.isfile(local_superbias_fit):
                continue
            # step 1 - coadd biases
            local_biases_filename = [
                '%s%s.p%s.fits' % (out_dir, x, prev_suffix)
                for x in local_biases]
            pywifes.imcombine(local_biases_filename,local_superbias, data_hdu=my_data_hdu)
            # step 2 - generate fit!
            if method == 'fit' or method == 'row_med':
                pywifes.generate_wifes_bias_fit(local_superbias, 
                                                local_superbias_fit,
                                                data_hdu=my_data_hdu,
                                                method=method, **args)
            else:
                pywifes.imcopy(local_superbias, local_superbias_fit)
    return
Esempio n. 9
0
def run_obs_coadd(metadata, prev_suffix, curr_suffix,
                  method='sum', scale=None):
    for obs in (metadata['sci']+metadata['std']):
        # if just one, then copy it
        if len(obs['sci']) == 1:
            fn = obs['sci'][0]
            in_fn  = '%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
            out_fn = '%s%s.p%s.fits' % (out_dir, fn, curr_suffix)
            print 'Copying image %s' % in_fn.split('/')[-1]
            pywifes.imcopy(in_fn, out_fn)            
        # coadd sci frames!
        else:
            in_fn_list = ['%s%s.p%s.fits' % (out_dir, fn, prev_suffix)
                          for fn in obs['sci']]
            out_fn = '%s%s.p%s.fits' % (out_dir, obs['sci'][0], curr_suffix)
            print 'Coadding images for %s' % in_fn_list[0].split('/')[-1]
            pywifes.imcombine_mef(in_fn_list, out_fn,
                                  scale=scale,
                                  method=method)
    return
Esempio n. 10
0
def run_superbias(metadata, prev_suffix, curr_suffix,
                  method='row_med', **args):
    bias_list = [
        os.path.join(out_dir, '%s.p%s.fits' % (x, prev_suffix))
        for x in metadata['bias']]
    print('Calculating Global Superbias')
    pywifes.imcombine(bias_list, superbias_fn, data_hdu=my_data_hdu)
    # decide what bias model you will actually subtract - could be just data
    if method == 'fit' or method == 'row_med':
        # Fit a smart surface to the bias or take the median
        # A bit experimental so far ... but you know what you are doing, right ?
        pywifes.generate_wifes_bias_fit(
            superbias_fn, superbias_fit_fn, 
            data_hdu=my_data_hdu, method=method, **args)
    else:
        pywifes.imcopy(superbias_fn, superbias_fit_fn)
    # generate local superbiases for any science frames
    sci_obs_list  = get_sci_obs_list(metadata)
    std_obs_list  = get_std_obs_list(metadata)
    for fn in (sci_obs_list + std_obs_list):
        # Find if there is an associated bias (or more ?)
        local_biases = get_associated_calib(metadata,fn, 'bias')
        if local_biases:
            local_bias_fn = get_associated_calib(metadata,fn,'bias')[0]
            print('Calculating Local Superbias for %s' % local_bias_fn)
            local_superbias = os.path.join(out_dir, '%s.fits' % (local_bias_fn+'.lsb'))
            local_superbias_fit = os.path.join(out_dir, '%s.fits' % (local_bias_fn+'.lsb_fit'))
            if os.path.isfile(local_superbias_fit):
                continue
            # step 1 - coadd biases
            local_biases_filename = [