Esempio n. 1
0
    def test_basic2d_lev3c_blev(self):
        """
        The regression test for this level of this task is a running of the
        task with the bias level, Doppler smoothing correction and BIAS image
        sub. parameters set (equal to 'perform').  This includes the additional
        creation of an output test file for bias levels. The input data for
        this test is a STIS CCD image.
        """

        # Prepare input files.
        self.get_input_file("input", "o3wd01060_raw.fits")
        self.get_data("input", "o3wd01060_wav.fits")
        self.get_data("input", "o3wd01060_spt.fits")

        # Run basic2d
        basic2d('o3wd01060_raw.fits',
                output="basic2d_lev3c_blev.fits",
                outblev="basic2d_lev3c_blev.dat",
                dqicorr="omit",
                lorscorr="omit",
                glincorr="omit",
                lflgcorr="omit",
                darkcorr="omit",
                flatcorr="omit",
                photcorr="omit")

        # Compare results
        outputs = [("basic2d_lev3c_blev.fits", "basic2d_lev3c_blev_ref.fits"),
                   ("basic2d_lev3c_blev.dat", "basic2d_lev3c_blev_ref.dat")]
        self.compare_outputs(outputs)
Esempio n. 2
0
    def test_basic2d_lev1a(self):
        """
        BASIC2D - stsdas/hst_calib/stis/basic2d: level 1a
        This regression test for this level of this task is a running of the
        task with ALL parameters blazing (equal to 'perform').  This includes
        the additional creation of an output test file for bias levels.
        The input data for this test is a STIS NUV_MAMA CCD image.
        """

        # Prepare input files.
        self.get_input_file("input", "o6d806030_raw.fits")

        # Run basic2d
        basic2d("o6d806030_raw.fits", output="basic2d_lev1a_flt.fits")

        # Compare results
        outputs = [("basic2d_lev1a_flt.fits", "basic2d_lev1a_flt_ref.fits")]
        self.compare_outputs(outputs)
Esempio n. 3
0
def bias_subtract_data(filename, biasfile):
    """Perform bias subtraction on input dataset

    basic2d from calstis will be run on the input dataset with the
    steps DQICORR, BLEVCORR, and BIASCORR set to perform.

    Parameters
    ----------
    filename : str
        full path to input FITS file
    biasfile : str
        full path to the bias FITS file to be subtracted

    Returns
    -------
    filename : str
        full_path to the bias subtracted file

    """

    with pyfits.open(filename) as hdu:
        if (hdu[0].header['BLEVCORR'] == 'COMPLETE') or (hdu[0].header['BIASCORR'] == 'COMPLETE'):
            print("BIAS correction already done for {}".format(filename))
            return filename

    if os.path.exists(filename.replace('raw', 'flc')):
        os.remove(filename.replace('raw', 'flc'))
    elif os.path.exists(filename.replace('raw', 'flt')):
        os.remove(filename.replace('raw', 'flt'))

    path, name = os.path.split(filename)
    name, ext = os.path.splitext(name)
    trailerfile = os.path.join(path, name + '_bias_subtract_log.txt')

    biasfile = make_path_safe(biasfile)

    pyfits.setval(filename, 'BIASFILE', ext=0, value=biasfile)
    status = basic2d(filename,
                     dqicorr='perform',
                     blevcorr='perform',
                     biascorr='perform',
                     doppcorr='omit',
                     lorscorr='omit',
                     glincorr='omit',
                     lflgcorr='omit',
                     darkcorr='omit',
                     flatcorr='omit',
                     photcorr='omit',
                     verbose=False,
                     trailer=trailerfile)
    if status != 0:
        try:
            print()
            with open(trailerfile) as tr:
                for line in tr.readlines():
                    print('    {}'.format(line.strip()))
        finally:
            raise Exception('BASIC2D failed to properly reduce {}'.format(filename))

    filename = filename.replace('raw', 'flt')

    return filename
Esempio n. 4
0
def crreject(input_file, workdir=None):
    if not 'oref' in os.environ:
        os.environ['oref'] = '/grp/hst/cdbs/oref/'

    path, name = os.path.split(input_file)
    name, ext = os.path.splitext(name)
    trailerfile = os.path.join(path, name+'_crreject_log.txt')

    output_blev = input_file.replace('.fits','_blev.fits')
    output_crj = input_file.replace('.fits','_crj.fits')

    with pyfits.open(input_file) as hdu:
        nimset = hdu[0].header['nextend'] / 3
        nrptexp = hdu[0].header['nrptexp']
        crcorr = hdu[0].header['crcorr']
        blevcorr = hdu[0].header['blevcorr']

    if (nimset <= 1 and crcorr != "COMPLETE"):
        print("Sorry, your input image seems to have only 1 imset, but it isn't cr-rejected.")
        print("This task can only handle 'raw' or 'flt images with the NEXTEND keyword equal to 3*N (N > 1).")
        print("Bye now... better luck next time!")
        raise ValueError('nimset <=1 and CRCORR not complete')

    if (crcorr != "COMPLETE"):
        if (nrptexp != nimset):
            pyfits.setval(input_file,'NRPTEXP',value=nimset)
            pyfits.setval(input_file,'CRSPLIT',value=1)

        pyfits.setval(input_file, 'CRCORR', value='PERFORM')
        #pyfits.setval(input_file, 'DQICORR', value='PERFORM')
        pyfits.setval(input_file, 'APERTURE', value='50CCD')
        pyfits.setval(input_file, 'APER_FOV', value='50x50')
        if (blevcorr != 'COMPLETE') :
            print('Performing BLEVCORR')
            pyfits.setval(input_file, 'BLEVCORR', value='PERFORM')
            status = basic2d(input_file,
                             output_blev,
                             outblev='',
                             dqicorr='perform',
                             blevcorr='perform',
                             doppcorr='omit',
                             lorscorr='omit',
                             glincorr='omit',
                             lflgcorr='omit',
                             biascorr='omit',
                             darkcorr='omit',
                             flatcorr='omit',
                             photcorr='omit',
                             statflag=False,
                             verbose=False,
                             trailer=trailerfile)
            if status != 0:
                try:
                    print()
                    with open(trailerfile) as tr:
                        for line in tr.readlines():
                            print('    {}'.format(line.strip()))
                finally:
                    raise Exception('BASIC2D failed to properly reduce {}'.format(input_file))
        else:
            print('Blevcorr already Performed')
            shutil.copy(input_file,output_blev)

        print('Performing OCRREJECT')
        status = ocrreject(input=output_blev,
                           output=output_crj,
                           verbose=False,
                           trailer=trailerfile)
        if status != 0:
            try:
                print()
                with open(trailerfile) as tr:
                    for line in tr.readlines():
                        print('    {}'.format(line.strip()))
            finally:
                raise Exception('OCRREJECT failed to properly reduce {}'.format(output_blev))

    elif (crcorr == "COMPLETE"):
        print("CR rejection already done")
        os.rename(input_file, output_crj)

    pyfits.setval(output_crj, 'FILENAME', value=output_crj)

    with pyfits.open(output_crj) as hdu:
        gain = hdu[0].header['atodgain']
        ccdgain = hdu[0].header['ccdgain']
        xsize = hdu[1].header['naxis1']
        ysize = hdu[1].header['naxis2']
        xbin = hdu[0].header['binaxis1']
        ybin = hdu[0].header['binaxis2']

        try:
            ncombine = hdu[0].header['ncombine']
        except:
            ncombine = hdu[1].header['ncombine']

    print(('Number of combined imsets is '+str(ncombine)+' while number of imsets is '+str(nimset ) ))
    print(('Dividing cosmic-ray-rejected image by '+str(ncombine)+'...'))
    out_div = output_crj.replace('.fits','_div.fits')

    ###this used to be a call to MSARITH, is anything else needed?
    ###modifying the error too (done), etc?
    hdu = pyfits.open(output_crj)
    hdu[('sci', 1)].data /= ncombine
    hdu[('err', 1)].data /= ncombine
    hdu.writeto(out_div, output_verify='exception', clobber=True)

    os.remove(output_blev)
    os.remove(output_crj)

    return out_div
Esempio n. 5
0
def crreject(input_file, workdir=None):
    if not 'oref' in os.environ:
        os.environ['oref'] = '/grp/hst/cdbs/oref/'

    path, name = os.path.split(input_file)
    name, ext = os.path.splitext(name)
    trailerfile = os.path.join(path, name + '_crreject_log.txt')

    output_blev = input_file.replace('.fits', '_blev.fits')
    output_crj = input_file.replace('.fits', '_crj.fits')

    with pyfits.open(input_file) as hdu:
        nimset = hdu[0].header['nextend'] / 3
        nrptexp = hdu[0].header['nrptexp']
        crcorr = hdu[0].header['crcorr']
        blevcorr = hdu[0].header['blevcorr']

    if (nimset <= 1 and crcorr != "COMPLETE"):
        print(
            "Sorry, your input image seems to have only 1 imset, but it isn't cr-rejected."
        )
        print(
            "This task can only handle 'raw' or 'flt images with the NEXTEND keyword equal to 3*N (N > 1)."
        )
        print("Bye now... better luck next time!")
        raise ValueError('nimset <=1 and CRCORR not complete')

    if (crcorr != "COMPLETE"):
        if (nrptexp != nimset):
            pyfits.setval(input_file, 'NRPTEXP', value=nimset)
            pyfits.setval(input_file, 'CRSPLIT', value=1)

        pyfits.setval(input_file, 'CRCORR', value='PERFORM')
        #pyfits.setval(input_file, 'DQICORR', value='PERFORM')
        pyfits.setval(input_file, 'APERTURE', value='50CCD')
        pyfits.setval(input_file, 'APER_FOV', value='50x50')
        if (blevcorr != 'COMPLETE'):
            print('Performing BLEVCORR')
            pyfits.setval(input_file, 'BLEVCORR', value='PERFORM')
            status = basic2d(input_file,
                             output_blev,
                             outblev='',
                             dqicorr='perform',
                             blevcorr='perform',
                             doppcorr='omit',
                             lorscorr='omit',
                             glincorr='omit',
                             lflgcorr='omit',
                             biascorr='omit',
                             darkcorr='omit',
                             flatcorr='omit',
                             photcorr='omit',
                             statflag=False,
                             verbose=False,
                             trailer=trailerfile)
            if status != 0:
                try:
                    print()
                    with open(trailerfile) as tr:
                        for line in tr.readlines():
                            print('    {}'.format(line.strip()))
                finally:
                    raise Exception(
                        'BASIC2D failed to properly reduce {}'.format(
                            input_file))
        else:
            print('Blevcorr already Performed')
            shutil.copy(input_file, output_blev)

        print('Performing OCRREJECT')
        status = ocrreject(input=output_blev,
                           output=output_crj,
                           verbose=False,
                           trailer=trailerfile)
        if status != 0:
            try:
                print()
                with open(trailerfile) as tr:
                    for line in tr.readlines():
                        print('    {}'.format(line.strip()))
            finally:
                raise Exception(
                    'OCRREJECT failed to properly reduce {}'.format(
                        output_blev))

    elif (crcorr == "COMPLETE"):
        print("CR rejection already done")
        os.rename(input_file, output_crj)

    pyfits.setval(output_crj, 'FILENAME', value=output_crj)

    with pyfits.open(output_crj) as hdu:
        gain = hdu[0].header['atodgain']
        ccdgain = hdu[0].header['ccdgain']
        xsize = hdu[1].header['naxis1']
        ysize = hdu[1].header['naxis2']
        xbin = hdu[0].header['binaxis1']
        ybin = hdu[0].header['binaxis2']

        try:
            ncombine = hdu[0].header['ncombine']
        except:
            ncombine = hdu[1].header['ncombine']

    print(('Number of combined imsets is ' + str(ncombine) +
           ' while number of imsets is ' + str(nimset)))
    print(('Dividing cosmic-ray-rejected image by ' + str(ncombine) + '...'))
    out_div = output_crj.replace('.fits', '_div.fits')

    ###this used to be a call to MSARITH, is anything else needed?
    ###modifying the error too (done), etc?
    hdu = pyfits.open(output_crj)
    hdu[('sci', 1)].data /= ncombine
    hdu[('err', 1)].data /= ncombine
    hdu.writeto(out_div, output_verify='exception', clobber=True)

    os.remove(output_blev)
    os.remove(output_crj)

    return out_div
Esempio n. 6
0
def bias_subtract_data(filename, biasfile):
    """Perform bias subtraction on input dataset

    basic2d from calstis will be run on the input dataset with the
    steps DQICORR, BLEVCORR, and BIASCORR set to perform.

    Parameters
    ----------
    filename : str
        full path to input FITS file
    biasfile : str
        full path to the bias FITS file to be subtracted

    Returns
    -------
    filename : str
        full_path to the bias subtracted file

    """

    with pyfits.open(filename) as hdu:
        if (hdu[0].header['BLEVCORR']
                == 'COMPLETE') or (hdu[0].header['BIASCORR'] == 'COMPLETE'):
            print("BIAS correction already done for {}".format(filename))
            return filename

    if os.path.exists(filename.replace('raw', 'flc')):
        os.remove(filename.replace('raw', 'flc'))
    elif os.path.exists(filename.replace('raw', 'flt')):
        os.remove(filename.replace('raw', 'flt'))

    path, name = os.path.split(filename)
    name, ext = os.path.splitext(name)
    trailerfile = os.path.join(path, name + '_bias_subtract_log.txt')

    biasfile = make_path_safe(biasfile)

    pyfits.setval(filename, 'BIASFILE', ext=0, value=biasfile)
    status = basic2d(filename,
                     dqicorr='perform',
                     blevcorr='perform',
                     biascorr='perform',
                     doppcorr='omit',
                     lorscorr='omit',
                     glincorr='omit',
                     lflgcorr='omit',
                     darkcorr='omit',
                     flatcorr='omit',
                     photcorr='omit',
                     verbose=False,
                     trailer=trailerfile)
    if status != 0:
        try:
            print()
            with open(trailerfile) as tr:
                for line in tr.readlines():
                    print('    {}'.format(line.strip()))
        finally:
            raise Exception(
                'BASIC2D failed to properly reduce {}'.format(filename))

    filename = filename.replace('raw', 'flt')

    return filename