Example #1
0
def AstroDrizzle(input=None, mdriztab=False, editpars=False, configobj=None,
                 wcsmap=None, **input_dict):
    """ AstroDrizzle command-line interface """
    # Support input of filenames from command-line without a parameter name
    # then copy this into input_dict for merging with TEAL ConfigObj
    # parameters.

    # Load any user-specified configobj
    if isinstance(configobj, string_types):
        if configobj == 'defaults':
            # load "TEAL"-defaults (from ~/.teal/):
            configobj = teal.load(__taskname__)
        else:
            if not os.path.exists(configobj):
                raise RuntimeError('Cannot find .cfg file: '+configobj)
            configobj = teal.load(configobj, strict=False)
    elif configobj is None:
        # load 'astrodrizzle' parameter defaults as described in the docs:
        configobj = teal.load(__taskname__, defaults=True)

    if input and not util.is_blank(input):
        input_dict['input'] = input
    elif configobj is None:
        raise TypeError("AstroDrizzle() needs either 'input' or "
                        "'configobj' arguments")

    if 'updatewcs' in input_dict: # user trying to explicitly turn on updatewcs
        configobj['updatewcs'] = input_dict['updatewcs']
        del input_dict['updatewcs']

    # If called from interactive user-interface, configObj will not be
    # defined yet, so get defaults using EPAR/TEAL.
    #
    # Also insure that the input_dict (user-specified values) are folded in
    # with a fully populated configObj instance.
    try:
        configObj = util.getDefaultConfigObj(__taskname__, configobj,
                                             input_dict,
                                             loadOnly=(not editpars))
        log.debug('')
        log.debug("INPUT_DICT:")
        util.print_cfg(input_dict, log.debug)
        log.debug('')
        # If user specifies optional parameter for final_wcs specification in input_dict,
        #    insure that the final_wcs step gets turned on
        util.applyUserPars_steps(configObj, input_dict, step='3a')
        util.applyUserPars_steps(configObj, input_dict, step='7a')

    except ValueError:
        print("Problem with input parameters. Quitting...", file=sys.stderr)
        return

    if not configObj:
        return

    configObj['mdriztab'] = mdriztab
    # If 'editpars' was set to True, util.getDefaultConfigObj() will have
    # already called 'run()'.
    if not editpars:
        run(configObj, wcsmap=wcsmap)
Example #2
0
def AstroDrizzle(input=None, mdriztab=False, editpars=False, configobj=None,
                 wcsmap=None, **input_dict):
    """ AstroDrizzle command-line interface
    """
    # support input of filenames from command-line without a parameter name
    # then copy this into input_dict for merging with TEAL ConfigObj parameters
    if input_dict is None:
        input_dict = {}

    if input is None and configobj is None:
        raise TypeError('AstroDrizzle() needs either "input" or "configobj" arg')

    if input and not util.is_blank(input):
        input_dict['input'] = input

    # input_dict['mdriztab'] = mdriztab

    # Load any user-specified configobj
    if isinstance(configobj, str) and configobj != 'defaults':
        if not os.path.exists(configobj):
            raise RuntimeError('Cannot find .cfg file: '+configobj)
        configobj = teal.load(configobj, strict=False)

    if configobj is None or configobj == 'defaults':
        configobj = teal.load(__taskname__)

    if 'updatewcs' in input_dict: # user trying to explicitly turn on updatewcs
        configobj['updatewcs'] = input_dict['updatewcs']
        del input_dict['updatewcs']

    # If called from interactive user-interface, configObj will not be
    # defined yet, so get defaults using EPAR/TEAL.
    #
    # Also insure that the input_dict (user-specified values) are folded in
    # with a fully populated configObj instance.
    try:
        configObj = util.getDefaultConfigObj(__taskname__, configobj,
                                             input_dict,
                                             loadOnly=(not editpars))
        print("INPUT_DICT: {}".format(input_dict))
        # If user specifies optional parameter for final_wcs specification in input_dict,
        #    insure that the final_wcs step gets turned on
        util.applyUserPars_steps(configObj, input_dict, step='3a')
        util.applyUserPars_steps(configObj, input_dict, step='7a')

    except ValueError:
        print("Problem with input parameters. Quitting...", file=sys.stderr)
        return

    if not configObj:
        return

    configObj['mdriztab'] = mdriztab
    # If 'editpars' was set to True, util.getDefaultConfigObj() will have
    # already called 'run()'.
    if editpars == False:
        run(configObj, wcsmap=wcsmap)
Example #3
0
    def test_kernels(self, output, kernel):

        input_file = 'j8bt06nyq_flt.fits'
        print("Running the test for kernel={}".format(kernel))

        # Prepare input files.
        input_file = self.get_input_file('input', input_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        parObj['output'] = output
        parObj['build'] = True
        parObj['in_memory'] = True
        parObj['runfile'] = 'drizzlepac.run'
        parObj['STATE OF INPUT FILES']['preserve'] = False
        parObj['STATE OF INPUT FILES']['clean'] = True
        parObj['STEP 1: STATIC MASK']['static'] = False
        parObj['STEP 2: SKY SUBTRACTION']['skysub'] = False
        parObj['STEP 3: DRIZZLE SEPARATE IMAGES']['driz_separate'] = False
        parObj['STEP 4: CREATE MEDIAN IMAGE']['median'] = False
        parObj['STEP 5: BLOT BACK THE MEDIAN IMAGE']['blot'] = False
        parObj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR']['driz_cr'] = False
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_kernel'] = kernel
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_units'] = 'counts'

        astrodrizzle.AstroDrizzle(input_file, configobj=parObj)

        # Compare results
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_{}.fits'.format(kernel)
        outputs = [(outfile, reffile)]
        self.ignore_keywords += ['D001DATA', 'D001MASK']
        self.compare_outputs(outputs)
Example #4
0
    def test_kernels(self, output, kernel):

        input_file = 'j8bt06nyq_flt.fits'
        print("Running the test for kernel={}".format(kernel))

        # Prepare input files.
        input_file = self.get_input_file('input', input_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle',
                           defaults=True)  # get all default values
        parObj['output'] = output
        parObj['build'] = True
        parObj['in_memory'] = True
        parObj['runfile'] = 'drizzlepac.run'
        parObj['STATE OF INPUT FILES']['preserve'] = False
        parObj['STATE OF INPUT FILES']['clean'] = True
        parObj['STEP 1: STATIC MASK']['static'] = False
        parObj['STEP 2: SKY SUBTRACTION']['skysub'] = False
        parObj['STEP 3: DRIZZLE SEPARATE IMAGES']['driz_separate'] = False
        parObj['STEP 4: CREATE MEDIAN IMAGE']['median'] = False
        parObj['STEP 5: BLOT BACK THE MEDIAN IMAGE']['blot'] = False
        parObj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR'][
            'driz_cr'] = False
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_kernel'] = kernel
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE'][
            'final_units'] = 'counts'

        astrodrizzle.AstroDrizzle(input_file, configobj=parObj)

        # Compare results
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_{}.fits'.format(kernel)
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
    def test_acs_narrowband(self):
        rootname = 'j8dw01010'
        asn_file = rootname + '_asn.fits'

        # Prepare input files.
        # TODO: Why is input_file not referenced?
        input_file = self.get_data('input', asn_file)

        for raw_file in raw_from_asn(asn_file, suffix='_flt.fits'):
            self.get_input_file('input', raw_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle',
                           defaults=True)  # get all default values
        parObj['build'] = True
        parObj['runfile'] = 'drizzlepac.run'
        parObj['STATE OF INPUT FILES']['preserve'] = False
        parObj['STATE OF INPUT FILES']['clean'] = True
        parObj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        parObj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nsigma'] = '6 3'
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nhigh'] = 1
        parObj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR'][
            'driz_cr_snr'] = '3.0 2.5'
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_bits'] = 8578
        parObj['STEP 7a: CUSTOM WCS FOR FINAL OUTPUT']['final_wcs'] = True
        parObj['STEP 7a: CUSTOM WCS FOR FINAL OUTPUT']['final_rot'] = 0.0

        astrodrizzle.AstroDrizzle(asn_file, configobj=parObj)

        # Compare results
        outputs = [('j8dw01010_drz.fits', 'reference_narrowband.fits')]
        self.compare_outputs(outputs)
Example #6
0
    def test_perf(self, output, in_memory, num_cores, use_static, skywidth):

        # Prepare input files.
        raw_inputs = ["ib6m02d9q_flt.fits", "ib6m02daq_flt.fits"]
        inputs = [os.path.basename(self.get_input_file('input', i)) 
                      for i in raw_inputs]

        # Merge common parameter settings with test-specific settings
        input_pars = {'build':True, 'preserve':False,
                       'clean':True, 'sky_bits':None}
        input_pars['output'] = output
        input_pars['in_memory'] = in_memory
        input_pars['num_cores'] = num_cores
        input_pars['use_static'] = use_static
        input_pars['skywidth'] = skywidth
        run_file = '{}.log'.format(output)
        input_pars['runfile'] = run_file

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs, use_db=False)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        astrodrizzle.AstroDrizzle(driz_inputs, configobj=parObj, **input_pars)

        # Compare results
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_{}.fits'.format(output)
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #7
0
    def test_uvis_asn(self):
        rootname = 'iacr51010'
        asn_file = '{}_asn.fits'.format(rootname)
        output = '{}_drz.fits'.format(rootname)

        ref_file = 'reference_wfc3_uvis_asn.fits'
        runfile = ref_file.replace('.fits','.log')

        # Prepare input files.
        input_files = []
        input_asn = self.get_data('input', asn_file)
        for raw_file in raw_from_asn(asn_file, suffix='_flt.fits'):
            input_files.append(os.path.basename(self.get_input_file('input', raw_file)))

        # define input parameters to be used
        input_pars = {'output': output, 'runfile':runfile,
                      'build':True, 'in_memory':False,
                      'preserve': False, 'clean':True, 'static':True,
                      'skysub':True, 'skywidth':0.3, 'use_static':False,
                      'sky_bits':None}

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        astrodrizzle.AstroDrizzle(asn_file, mdriztab=False,
                                  configobj=parObj, **input_pars)

        # Compare results
        outputs = [(output, ref_file)]
        self.compare_outputs(outputs)
Example #8
0
    def test_uvis_single(self):
        rootname = 'iacr51ohq'
        input_name = '{}_flt.fits'.format(rootname)
        output = '{}_drz.fits'.format(rootname)
        ref_file = 'reference_wfc3_uvis_single.fits'
        runfile = ref_file.replace('.fits','.log')

        # Prepare input files.
        input_file = os.path.basename(self.get_input_file('input', input_name))

        input_pars = {'output': output, 'runfile':runfile,
                      'build':True, 'in_memory':True,
                      'preserve': False, 'clean':True, 'static':True,
                      'skysub':True, 'skywidth':0.3, 'use_static':False,
                      'sky_bits':None,
                      'driz_separate':False, 'median':False,
                      'blot':False, 'driz_cr':False}

        # Update wcs in input file
        driz_input = updatewcs.updatewcs(input_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        astrodrizzle.AstroDrizzle(driz_input, mdriztab=False,
                                  configobj=parObj, **input_pars)

        # Compare results
        outputs = [(output, ref_file)]
        self.compare_outputs(outputs)
Example #9
0
    def test_wfc3_ir_saturated(self):
        # Prepare input files.
        raw_inputs = ['ib5w02n0q_flt.fits', 'ib5w02naq_flt.fits',
                      'ib5w02njq_flt.fits']
        inputs = [os.path.basename(self.get_input_file('input', i))
                  for i in raw_inputs]

        outname = 'wfc3_ir_sat'
        output = '{}_drz.fits'.format(outname)

        ref_file = 'reference_{}.fits'.format(outname)
        runfile = ref_file.replace('.fits','.log')

        # define input parameters to be used
        input_pars = {'output': outname, 'runfile':runfile,
                      'build':True, 'in_memory':False,
                      'preserve': False, 'clean':True, 'static':True,
                      'skysub':True, 'skystat':'mode', 'skylower':-100.0,
                      'use_static':False, 'sky_bits':None, 'driz_sep_bits':832,
                      'driz_cr_snr':'5.0 4.0', 'final_bits': 832}

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        astrodrizzle.AstroDrizzle(inputs, mdriztab=False,
                                  configobj=parObj, **input_pars)

        # Compare results
        outputs = [(output, ref_file)]
        self.compare_outputs(outputs)
Example #10
0
    def test_mef_asn(self):
        """ This test confirms that drizzlepac can correcly process input
        WFPC2 data stored in Multi-extensions FITS(MEF) format.
        """

        # Prepare input files.
        raw_inputs = ['u9yq0703m_c0m.fits', 'u9yq0704m_c0m.fits',
                      'u9yq0707m_c0m.fits', 'u9yq0708m_c0m.fits',
                      'u9yq0703m_c1m.fits', 'u9yq0704m_c1m.fits',
                      'u9yq0707m_c1m.fits', 'u9yq0708m_c1m.fits']
        inputs = [os.path.basename(self.get_input_file('input', i))
                  for i in raw_inputs]

        output = 'wfpc2_mef'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_wfpc2_asn_mef.fits'

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs[:4], use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'wfpc2_asn_mef.log'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skysub'] = False

        astrodrizzle.AstroDrizzle(driz_inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #11
0
def _managePsets(configobj, section_name, task_name, iparsobj=None, input_dict=None):
    """ Read in parameter values from PSET-like configobj tasks defined for
        source-finding algorithms, and any other PSET-like tasks under this task,
        and merge those values into the input configobj dictionary.
    """
    # Merge all configobj instances into a single object
    configobj[section_name] = {}

    # Load the default full set of configuration parameters for the PSET:
    iparsobj_cfg = teal.load(task_name)

    # Identify optional parameters in input_dicts that are from this
    # PSET and add it to iparsobj:
    if input_dict is not None:
        for key in list(input_dict.keys()):
            if key in iparsobj_cfg:
                if iparsobj is not None and key in iparsobj:
                    raise DuplicateKeyError("Duplicate parameter '{:s}' "
                        "provided for task {:s}".format(key, task_name))
                iparsobj_cfg[key] = input_dict[key]
                del input_dict[key]

    if iparsobj is not None:
        iparsobj_cfg.update(iparsobj)

    del iparsobj_cfg['_task_name_']

    # merge these parameters into full set
    configobj[section_name].merge(iparsobj_cfg)
Example #12
0
    def test_hrc_asn(self):
        rootname = 'j8bt06010'
        asn_file = rootname + '_asn.fits'

        # Prepare input files.
        input_file = self.get_data('input', asn_file)

        for raw_file in raw_from_asn(asn_file, suffix='_flt.fits'):
            self.get_input_file('input', raw_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        parObj['build'] = True
        parObj['runfile'] = 'drizzlepac.run'
        parObj['STATE OF INPUT FILES']['preserve'] = False
        parObj['STATE OF INPUT FILES']['clean'] = True
        parObj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        parObj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.1
        parObj['STEP 2: SKY SUBTRACTION']['skylower'] = -50.0
        parObj['STEP 2: SKY SUBTRACTION']['skyupper'] = 200.0
        parObj['STEP 3: DRIZZLE SEPARATE IMAGES']['driz_sep_bits'] = 8578
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nsigma'] = '6 3'
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nhigh'] = 1
        parObj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR']['driz_cr_snr'] = '3.0 2.5'
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_bits'] = 8578
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_units'] = 'counts'

        astrodrizzle.AstroDrizzle(asn_file, configobj=parObj)

        # Compare results
        outputs = [('j8bt06011_drz.fits', 'reference_asn_regress.fits')]
        self.compare_outputs(outputs)
    def test_acs_narrowband(self):
        rootname = 'j8dw01010'
        asn_file = rootname + '_asn.fits'

        # Prepare input files.
        # TODO: Why is input_file not referenced?
        input_file = self.get_data('input', asn_file)

        for raw_file in raw_from_asn(asn_file, suffix='_flt.fits'):
            self.get_input_file('input', raw_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        parObj['build'] = True
        parObj['runfile'] = 'drizzlepac.run'
        parObj['STATE OF INPUT FILES']['preserve'] = False
        parObj['STATE OF INPUT FILES']['clean'] = True
        parObj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        parObj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nsigma'] = '6 3'
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nhigh'] = 1
        parObj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR']['driz_cr_snr'] = '3.0 2.5'
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_bits'] = 8578
        parObj['STEP 7a: CUSTOM WCS FOR FINAL OUTPUT']['final_wcs'] = True
        parObj['STEP 7a: CUSTOM WCS FOR FINAL OUTPUT']['final_rot'] = 0.0

        astrodrizzle.AstroDrizzle(asn_file, configobj=parObj)

        # Compare results
        outputs = [('j8dw01010_drz.fits', 'reference_narrowband.fits')]
        self.compare_outputs(outputs)
Example #14
0
def cfg2json(cfgfilename, outpath=None):
    """Convert config files to json format

    Parameters
    ----------
    cfgfilename : str
        Input .cfg file to be converted to json format.

    outpath : str, optional
        Destination path of the json file.

    Returns
    -------
    Nothing
    """
    import drizzlepac
    from stsci.tools import teal

    # open cfg file and load up the output dictionary
    cfg_data = teal.load(cfgfilename, strict=False)
    del cfg_data['_task_name_']
    del cfg_data['_RULES_']

    out_dict = {"parameters": cfg_data, "default_values": cfg_data}

    # build output json filename
    json_filename = cfgfilename.split("/")[-1].replace(".cfg", ".json")

    if not outpath:
        code_dir = os.path.abspath(__file__)
        base_dir = os.path.dirname(os.path.dirname(code_dir))
        out_dir = os.path.join(base_dir, "pars/hap_pars")
        det = json_filename.split("_")[0]
        json_filename = json_filename.replace(det, det+"_astrodrizzle")
        if det == "any":
            json_filename = os.path.join(out_dir, det, json_filename)
        else:
            if det in ["hrc", "sbc", "wfc"]:
                inst = "acs"
            if det in ["ir", "uvis"]:
                inst = "wfc3"
            json_filename = "{}_{}".format(inst, json_filename)
            json_filename = os.path.join(out_dir, inst, det, json_filename)
    else:
        json_filename = os.path.join(outpath, "any_"+json_filename)
        json_filename = json_filename.replace("hap.json", "hap_basic.json")

    # write out data.
    if os.path.exists(json_filename):
        os.remove(json_filename)
    with open(json_filename, 'w') as fp:
        json.dump(out_dict, fp, indent=4)
    print("Wrote {}".format(json_filename))
Example #15
0
    def test_fuv_mama(self):
        """ This test confirms that drizzlepac can correcly apply the
        distortion model for STIS FUV MAMA data and create a combined product.
        """

        # Prepare input files.
        raw_inputs = [
            'o60q02f3q_flt.fits', 'o60q02f4q_flt.fits', 'o60q02f6q_flt.fits',
            'o60q02f8q_flt.fits', 'o60q02fbq_flt.fits', 'o60q02fcq_flt.fits',
            'o60q02feq_flt.fits', 'o60q02fgq_flt.fits', 'o60q02fiq_flt.fits'
        ]
        all_inputs = [self.get_input_file('input', i) for i in raw_inputs]
        inputs = [os.path.basename(i) for i in all_inputs]
        print("[STIS_01] Found inputs: \n{}".format(inputs))

        output = 'final_stis_01'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_stis_01.fits'

        # Update WCS for all inputs
        updatewcs.updatewcs(inputs, use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'stis_01'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skystat'] = 'mean'
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.1
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skylower'] = -50.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skyupper'] = 200.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parobj['STEP 3: DRIZZLE SEPARATE IMAGES'][
            'driz_separate'] = False
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['median'] = False
        adriz_parobj['STEP 5: BLOT BACK THE MEDIAN IMAGE']['blot'] = False
        adriz_parobj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR'][
            'driz_cr'] = False

        astrodrizzle.AstroDrizzle(inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #16
0
    def test_stis_ccd(self):
        """ This test confirms that drizzlepac can correcly apply the
        distortion model for STIS CCD data and create a combined product.
        """

        # Prepare input files.
        raw_inputs = [
            'o6cl10arq_flt.fits', 'o6cl10asq_flt.fits', 'o6cl10atq_flt.fits',
            'o6cl10auq_flt.fits', 'o6cl10axq_flt.fits', 'o6cl10ayq_flt.fits',
            'o6cl10azq_flt.fits', 'o6cl10b0q_flt.fits'
        ]

        all_inputs = [self.get_input_file('input', i) for i in raw_inputs]
        inputs = [os.path.basename(i) for i in all_inputs]

        output = 'final_stis_04'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_stis_04.fits'

        # Update WCS for all inputs
        updatewcs.updatewcs(inputs, use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'stis_04'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.1
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skylower'] = -50.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skyupper'] = 200.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_type'] = 'median'
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_nsigma'] = '6 3'
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_nhigh'] = 1
        adriz_parobj['STEP 7: DRIZZLE FINAL COMBINED IMAGE'][
            'final_bits'] = 528

        astrodrizzle.AstroDrizzle(inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #17
0
    def test_fuv_mama(self):
        """ This test confirms that drizzlepac can correcly apply the
        distortion model for STIS FUV MAMA data and create a combined product.
        """

        # Prepare input files.
        raw_inputs = ['o60q02f3q_flt.fits', 'o60q02f4q_flt.fits',
                      'o60q02f6q_flt.fits', 'o60q02f8q_flt.fits',
                      'o60q02fbq_flt.fits', 'o60q02fcq_flt.fits',
                      'o60q02feq_flt.fits', 'o60q02fgq_flt.fits',
                      'o60q02fiq_flt.fits']
        all_inputs = [self.get_input_file('input', i) for i in raw_inputs]
        inputs = [os.path.basename(i) for i in all_inputs]
        print("[STIS_01] Found inputs: \n{}".format(inputs))

        output = 'final_stis_01'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_stis_01.fits'

        # Update WCS for all inputs
        updatewcs.updatewcs(inputs, use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'stis_01'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skystat'] = 'mean'
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.1
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skylower'] = -50.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skyupper'] = 200.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parobj['STEP 3: DRIZZLE SEPARATE IMAGES']['driz_separate'] = False
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['median'] = False
        adriz_parobj['STEP 5: BLOT BACK THE MEDIAN IMAGE']['blot'] = False
        adriz_parobj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR']['driz_cr'] = False

        astrodrizzle.AstroDrizzle(inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #18
0
    def test_stis_ccd(self):
        """ This test confirms that drizzlepac can correcly apply the
        distortion model for STIS CCD data and create a combined product.
        """

        # Prepare input files.
        raw_inputs = ['o6cl10arq_flt.fits', 'o6cl10asq_flt.fits',
                      'o6cl10atq_flt.fits', 'o6cl10auq_flt.fits',
                      'o6cl10axq_flt.fits', 'o6cl10ayq_flt.fits',
                      'o6cl10azq_flt.fits', 'o6cl10b0q_flt.fits']

        all_inputs = [self.get_input_file('input', i) for i in raw_inputs]
        inputs = [os.path.basename(i) for i in all_inputs]

        output = 'final_stis_04'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_stis_04.fits'

        # Update WCS for all inputs
        updatewcs.updatewcs(inputs, use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'stis_04'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.1
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skylower'] = -50.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skyupper'] = 200.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_type'] = 'median'
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_nsigma'] = '6 3'
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['combine_nhigh'] = 1
        adriz_parobj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_bits'] = 528

        astrodrizzle.AstroDrizzle(inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #19
0
    def test_waiver_single(self):
        """ This test confirms that drizzlepac can correcly process .
        """
        # Prepare input files.
        raw_inputs = ["u40x010hm_c0f.fits", "u40x010hm_c1f.fits"]
        inputs = [
            os.path.basename(self.get_input_file('input', i))
            for i in raw_inputs
        ]

        output = 'wfpc2_single_waiver'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_single_waiver.fits'

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs[0], use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = False
        adriz_parobj['runfile'] = 'wfpc2_single_waiver.log'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skysub'] = True
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skystat'] = 'mode'
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.3
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skylower'] = -100.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parobj['STEP 3: DRIZZLE SEPARATE IMAGES'][
            'driz_separate'] = False
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['median'] = False
        adriz_parobj['STEP 5: BLOT BACK THE MEDIAN IMAGE']['blot'] = False
        adriz_parobj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR'][
            'driz_cr'] = False

        astrodrizzle.AstroDrizzle(driz_inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #20
0
    def test_waiver_single(self):
        """ This test confirms that drizzlepac can correcly process .
        """
        # Prepare input files.
        raw_inputs = ["u40x010hm_c0f.fits", "u40x010hm_c1f.fits"]
        inputs = [os.path.basename(self.get_input_file('input', i))
                  for i in raw_inputs]

        output = 'wfpc2_single_waiver'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_single_waiver.fits'

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs[0], use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = False
        adriz_parobj['runfile'] = 'wfpc2_single_waiver.log'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skysub'] = True
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skystat'] = 'mode'
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.3
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skylower'] = -100.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parobj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parobj['STEP 3: DRIZZLE SEPARATE IMAGES']['driz_separate'] = False
        adriz_parobj['STEP 4: CREATE MEDIAN IMAGE']['median'] = False
        adriz_parobj['STEP 5: BLOT BACK THE MEDIAN IMAGE']['blot'] = False
        adriz_parobj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR']['driz_cr'] = False

        astrodrizzle.AstroDrizzle(driz_inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #21
0
    def test_waiver_asn(self):
        """ This test confirms that drizzlepac can correcly process input
        WFPC2 data stored in WAIVER fits format.
        """

        # Prepare input files.
        raw_inputs = [
            'u40x010hm_c0f.fits', 'u40x010im_c0f.fits', 'u40x010jm_c0f.fits',
            'u40x010km_c0f.fits', 'u40x010hm_c1f.fits', 'u40x010im_c1f.fits',
            'u40x010jm_c1f.fits', 'u40x010km_c1f.fits'
        ]
        inputs = [
            os.path.basename(self.get_input_file('input', i))
            for i in raw_inputs
        ]

        output = 'wfpc2_waiver'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_wfpc2_asn_waiver.fits'

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs[:4], use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'wfpc2_asn_waiver.log'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skysub'] = False

        astrodrizzle.AstroDrizzle(driz_inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #22
0
    def test_mef_asn(self):
        """ This test confirms that drizzlepac can correcly process input
        WFPC2 data stored in Multi-extensions FITS(MEF) format.
        """

        # Prepare input files.
        raw_inputs = [
            'u9yq0703m_c0m.fits', 'u9yq0704m_c0m.fits', 'u9yq0707m_c0m.fits',
            'u9yq0708m_c0m.fits', 'u9yq0703m_c1m.fits', 'u9yq0704m_c1m.fits',
            'u9yq0707m_c1m.fits', 'u9yq0708m_c1m.fits'
        ]
        inputs = [
            os.path.basename(self.get_input_file('input', i))
            for i in raw_inputs
        ]

        output = 'wfpc2_mef'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_wfpc2_asn_mef.fits'

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs[:4], use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'wfpc2_asn_mef.log'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skysub'] = False

        astrodrizzle.AstroDrizzle(driz_inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #23
0
    def test_waiver_asn(self):
        """ This test confirms that drizzlepac can correcly process input
        WFPC2 data stored in WAIVER fits format.
        """

        # Prepare input files.
        raw_inputs = ['u40x010hm_c0f.fits', 'u40x010im_c0f.fits',
                      'u40x010jm_c0f.fits', 'u40x010km_c0f.fits',
                      'u40x010hm_c1f.fits', 'u40x010im_c1f.fits',
                      'u40x010jm_c1f.fits', 'u40x010km_c1f.fits']
        inputs = [os.path.basename(self.get_input_file('input', i))
                  for i in raw_inputs]

        output = 'wfpc2_waiver'
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_wfpc2_asn_waiver.fits'

        # Update WCS for all inputs
        driz_inputs = updatewcs.updatewcs(inputs[:4], use_db=False)

        # run astrodrizzle now...
        adriz_parobj = teal.load('astrodrizzle', defaults=True)
        adriz_parobj['output'] = output
        adriz_parobj['build'] = True
        adriz_parobj['in_memory'] = True
        adriz_parobj['runfile'] = 'wfpc2_asn_waiver.log'
        adriz_parobj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parobj['STATE OF INPUT FILES']['clean'] = True
        adriz_parobj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        adriz_parobj['STEP 2: SKY SUBTRACTION']['skysub'] = False

        astrodrizzle.AstroDrizzle(driz_inputs, configobj=adriz_parobj)

        # Compare results
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #24
0
    def test_hrc_asn(self):
        rootname = 'j8bt06010'
        asn_file = rootname + '_asn.fits'

        # Prepare input files.
        input_file = self.get_data('input', asn_file)

        for raw_file in raw_from_asn(asn_file, suffix='_flt.fits'):
            self.get_input_file('input', raw_file)

        # run astrodrizzle now...
        parObj = teal.load('astrodrizzle',
                           defaults=True)  # get all default values
        parObj['build'] = True
        parObj['runfile'] = 'drizzlepac.run'
        parObj['STATE OF INPUT FILES']['preserve'] = False
        parObj['STATE OF INPUT FILES']['clean'] = True
        parObj['STEP 1: STATIC MASK']['static_sig'] = 3.0
        parObj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.1
        parObj['STEP 2: SKY SUBTRACTION']['skylower'] = -50.0
        parObj['STEP 2: SKY SUBTRACTION']['skyupper'] = 200.0
        parObj['STEP 3: DRIZZLE SEPARATE IMAGES']['driz_sep_bits'] = 8578
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nsigma'] = '6 3'
        parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_nhigh'] = 1
        parObj['STEP 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR'][
            'driz_cr_snr'] = '3.0 2.5'
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE']['final_bits'] = 8578
        parObj['STEP 7: DRIZZLE FINAL COMBINED IMAGE'][
            'final_units'] = 'counts'

        astrodrizzle.AstroDrizzle(asn_file, configobj=parObj)

        # Compare results
        outputs = [('j8bt06011_drz.fits', 'reference_asn_regress.fits')]
        self.compare_outputs(outputs)
Example #25
0
def AstroDrizzle(input=None,
                 mdriztab=False,
                 editpars=False,
                 configobj=None,
                 wcsmap=None,
                 **input_dict):
    """ AstroDrizzle command-line interface """
    # Support input of filenames from command-line without a parameter name
    # then copy this into input_dict for merging with TEAL ConfigObj
    # parameters.

    # Load any user-specified configobj
    if isinstance(configobj, (str, bytes)):
        if configobj == 'defaults':
            # load "TEAL"-defaults (from ~/.teal/):
            configobj = teal.load(__taskname__)
        else:
            if not os.path.exists(configobj):
                raise RuntimeError('Cannot find .cfg file: ' + configobj)
            configobj = teal.load(configobj, strict=False)
    elif configobj is None:
        # load 'astrodrizzle' parameter defaults as described in the docs:
        configobj = teal.load(__taskname__, defaults=True)

    if input and not util.is_blank(input):
        input_dict['input'] = input
    elif configobj is None:
        raise TypeError("AstroDrizzle() needs either 'input' or "
                        "'configobj' arguments")

    if 'updatewcs' in input_dict:  # user trying to explicitly turn on updatewcs
        configobj['updatewcs'] = input_dict['updatewcs']
        del input_dict['updatewcs']

    # If called from interactive user-interface, configObj will not be
    # defined yet, so get defaults using EPAR/TEAL.
    #
    # Also insure that the input_dict (user-specified values) are folded in
    # with a fully populated configObj instance.
    try:
        configObj = util.getDefaultConfigObj(__taskname__,
                                             configobj,
                                             input_dict,
                                             loadOnly=(not editpars))
        log.debug('')
        log.debug("INPUT_DICT:")
        util.print_cfg(input_dict, log.debug)
        log.debug('')
        # If user specifies optional parameter for final_wcs specification in input_dict,
        #    insure that the final_wcs step gets turned on
        util.applyUserPars_steps(configObj, input_dict, step='3a')
        util.applyUserPars_steps(configObj, input_dict, step='7a')

    except ValueError:
        print("Problem with input parameters. Quitting...", file=sys.stderr)
        return

    if not configObj:
        return

    configObj['mdriztab'] = mdriztab
    # If 'editpars' was set to True, util.getDefaultConfigObj() will have
    # already called 'run()'.
    if not editpars:
        run(configObj, wcsmap=wcsmap)
Example #26
0
    def test_tweak(self):
        """ This test confirms that image alignment performed by tweakreg
        works to find the correct alignment solution and that the solution
        can be used to correctly update the headers of the inputs to generate
        a properly aligned, combined mosaic using astrodrizzle.
        """
        input_file1 = 'j94f05bgq_flt.fits'
        input_file2 = 'j9irw1rqq_flt.fits'
        output = 'acs_tweak'

        # Prepare input files.
        input_file1 = self.get_input_file('input', input_file1)
        input_file2 = self.get_input_file('input', input_file2)
        inputs = ','.join([input_file1, input_file2])

        tweak_parObj = teal.load('tweakreg', defaults=True)
        tweak_parObj['input'] = 'j94f05bgq_flt.fits,j9irw1rqq_flt.fits'
        tweak_parObj['writecat'] = False
        tweak_parObj['clean'] = True
        tweak_parObj['OBJECT MATCHING PARAMETERS']['searchrad'] = 3.0
        tweak_parObj['OBJECT MATCHING PARAMETERS']['see2dplot'] = False
        tweak_parObj['OBJECT MATCHING PARAMETERS']['separation'] = 0.0
        tweak_parObj['CATALOG FITTING PARAMETERS']['residplot'] = 'No plot'
        tweak_parObj['CATALOG FITTING PARAMETERS']['nclip'] = 5
        tweak_parObj['CATALOG FITTING PARAMETERS']['sigma'] = 2.8
        imfind_parObj = teal.load('imagefindpars', defaults=True)
        imfind_parObj['computesig'] = False
        imfind_parObj['skysigma'] = 20.0
        imfind_parObj['conv_width'] = 2.0
        imfind_parObj['threshold'] = 500.0
        imfind_parObj['dqbits'] = None
        rfind_parObj = teal.load('refimagefindpars', defaults=True)
        rfind_parObj['computesig'] = False
        rfind_parObj['skysigma'] = 20.0
        rfind_parObj['conv_width'] = 2.0
        rfind_parObj['threshold'] = 500.0
        rfind_parObj['dqbits'] = None

        tweakreg.TweakReg(files=inputs, configobj=tweak_parObj,
                          imagefindcfg=imfind_parObj,
                          refimagefindcfg=rfind_parObj,
                          updatehdr=True, wcsname='TWEAK_regress')

        # run astrodrizzle now...
        adriz_parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        adriz_parObj['output'] = 'acs_tweak'
        adriz_parObj['build'] = True
        adriz_parObj['in_memory'] = True
        adriz_parObj['runfile'] = 'drizzlepac.run'
        adriz_parObj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parObj['STATE OF INPUT FILES']['clean'] = True
        adriz_parObj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.3
        adriz_parObj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parObj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7

        astrodrizzle.AstroDrizzle(inputs, configobj=adriz_parObj)

        # Compare results
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_tweak.fits'
        outputs = [(outfile, reffile)]
        self.compare_outputs(outputs)
Example #27
0
def TweakReg(files=None, editpars=False, configobj=None, imagefindcfg=None,
             refimagefindcfg=None, **input_dict):
    """
    """
    # support input of filenames from command-line without a parameter name
    # then copy this into input_dict for merging with TEAL ConfigObj parameters

    # Get default or user-specified configobj for primary task
    if isinstance(configobj, string_types):
        if configobj == 'defaults':
            # load "TEAL"-defaults (from ~/.teal/):
            configobj = teal.load(__taskname__)
        else:
            if not os.path.exists(configobj):
                raise RuntimeError('Cannot find .cfg file: '+configobj)
            configobj = teal.load(configobj, strict=False)
    elif configobj is None:
        # load 'astrodrizzle' parameter defaults as described in the docs:
        configobj = teal.load(__taskname__, defaults=True)

    if files and not util.is_blank(files):
        input_dict['input'] = files
    elif configobj is None:
        raise TypeError("TweakReg() needs either 'files' or "
                        "'configobj' arguments")

    if 'updatewcs' in input_dict: # user trying to explicitly turn on updatewcs
        configobj['updatewcs'] = input_dict['updatewcs']
        del input_dict['updatewcs']

    # Merge PSET configobj with full task configobj
    _managePsets(configobj, PSET_SECTION, imagefindpars.__taskname__,
                 iparsobj=imagefindcfg, input_dict=input_dict)
    _managePsets(configobj, PSET_SECTION_REFIMG,
                 refimagefindpars.__taskname__, iparsobj=refimagefindcfg)
    # !! NOTE - the above line needs to be done so that getDefaultConfigObj()
    # can merge in input_dict, however the TEAL GUI is not going to understand
    # the extra section, (or use it), so work needs to be done here - some
    # more thinking about how to accomplish what we want to with PSETS.
    # !! For now, warn them that imagefindpars args will be ignored in GUI.
    if editpars and input_dict:
        idkeys = input_dict.keys()
        for i in idkeys:
            if i in configobj[PSET_SECTION]:
                print('WARNING: ignoring imagefindpars setting "'+i+
                     '='+str(input_dict[i])+'", for now please enter directly into TEAL.')
                input_dict.pop(i)
        del configobj[PSET_SECTION] # force run() to pull it again after GUI use
        del configobj[PSET_SECTION_REFIMG] # force run() to pull it again after GUI use

    # If called from interactive user-interface, configObj will not be
    # defined yet, so get defaults using EPAR/TEAL.
    #
    # Also insure that the input_dict (user-specified values) are folded in
    # with a fully populated configObj instance.
    try:
        configObj = util.getDefaultConfigObj(__taskname__, configobj,
                                             input_dict,
                                             loadOnly=(not editpars))
    except ValueError:
        print("Problem with input parameters. Quitting...")
        return

    if configObj is None:
        return
    # If 'editpars' was set to True, util.getDefaultConfigObj() will have
    # already called 'run()'.
    if not editpars:
        # Pass full set of parameters on to the task
        run(configObj)
Example #28
0
    def test_tweak(self):
        """ This test confirms that image alignment performed by tweakreg
        works to find the correct alignment solution and that the solution
        can be used to correctly update the headers of the inputs to generate
        a properly aligned, combined mosaic using astrodrizzle.
        """
        input_file1 = 'j94f05bgq_flt.fits'
        input_file2 = 'j9irw1rqq_flt.fits'
        output = 'acs_tweak'

        # Prepare input files.
        input_file1 = self.get_input_file('input', input_file1)
        input_file2 = self.get_input_file('input', input_file2)
        inputs = ','.join([input_file1, input_file2])

        tweak_parObj = teal.load('tweakreg', defaults=True)
        tweak_parObj['input'] = 'j94f05bgq_flt.fits,j9irw1rqq_flt.fits'
        tweak_parObj['writecat'] = False
        tweak_parObj['clean'] = True
        tweak_parObj['OBJECT MATCHING PARAMETERS']['searchrad'] = 3.0
        tweak_parObj['OBJECT MATCHING PARAMETERS']['see2dplot'] = False
        tweak_parObj['OBJECT MATCHING PARAMETERS']['separation'] = 0.0
        tweak_parObj['CATALOG FITTING PARAMETERS']['residplot'] = 'No plot'
        tweak_parObj['CATALOG FITTING PARAMETERS']['nclip'] = 5
        tweak_parObj['CATALOG FITTING PARAMETERS']['sigma'] = 2.8
        imfind_parObj = teal.load('imagefindpars', defaults=True)
        imfind_parObj['computesig'] = False
        imfind_parObj['skysigma'] = 20.0
        imfind_parObj['conv_width'] = 2.0
        imfind_parObj['threshold'] = 500.0
        imfind_parObj['dqbits'] = None
        rfind_parObj = teal.load('refimagefindpars', defaults=True)
        rfind_parObj['computesig'] = False
        rfind_parObj['skysigma'] = 20.0
        rfind_parObj['conv_width'] = 2.0
        rfind_parObj['threshold'] = 500.0
        rfind_parObj['dqbits'] = None

        tweakreg.TweakReg(files=inputs, configobj=tweak_parObj,
                          imagefindcfg=imfind_parObj,
                          refimagefindcfg=rfind_parObj,
                          updatehdr=True, wcsname='TWEAK_regress')

        # run astrodrizzle now...
        adriz_parObj = teal.load('astrodrizzle', defaults=True)  # get all default values
        adriz_parObj['output'] = 'acs_tweak'
        adriz_parObj['build'] = True
        adriz_parObj['in_memory'] = True
        adriz_parObj['runfile'] = 'drizzlepac.run'
        adriz_parObj['STATE OF INPUT FILES']['preserve'] = False
        adriz_parObj['STATE OF INPUT FILES']['clean'] = True
        adriz_parObj['STEP 2: SKY SUBTRACTION']['skywidth'] = 0.3
        adriz_parObj['STEP 2: SKY SUBTRACTION']['use_static'] = False
        adriz_parObj['STEP 2: SKY SUBTRACTION']['sky_bits'] = None
        adriz_parObj['STEP 4: CREATE MEDIAN IMAGE']['combine_maskpt'] = 0.7

        astrodrizzle.AstroDrizzle(inputs, configobj=adriz_parObj)

        # Compare results
        outfile = '{}_drz.fits'.format(output)
        reffile = 'reference_tweak.fits'
        outputs = [(outfile, reffile)]
        for i in range(1,5):
            self.ignore_keywords += ['D00{}DATA'.format(i), 'D00{}MASK'.format(i)]
        self.compare_outputs(outputs)
Example #29
0
def getDefaultConfigObj(taskname, configObj, input_dict={}, loadOnly=True):
    """ Return default configObj instance for task updated
        with user-specified values from input_dict.

        Parameters
        ----------
        taskname : string
            Name of task to load into TEAL

        configObj : string
            The valid values for 'configObj' would be::

                None                      - loads last saved user .cfg file
                'defaults'                - loads task default .cfg file
                name of .cfg file (string)- loads user-specified .cfg file

        input_dict : dict
            Set of parameters and values specified by user to be different from
            what gets loaded in from the .cfg file for the task

        loadOnly : bool
            Setting 'loadOnly' to False causes the TEAL GUI to start allowing the
            user to edit the values further and then run the task if desired.

    """
    if configObj is None:
        # Start by grabbing the default values without using the GUI
        # This insures that all subsequent use of the configObj includes
        # all parameters and their last saved values
        configObj = teal.load(taskname)
    elif isinstance(configObj, str):
        if configObj.lower().strip() == 'defaults':
            # Load task default .cfg file with all default values
            configObj = teal.load(taskname, defaults=True)
            # define default filename for configObj
            configObj.filename = taskname.lower() + '.cfg'
        else:
            # Load user-specified .cfg file with its special default values
            # we need to call 'fileutil.osfn()' to insure all environment
            # variables specified by the user in the configObj filename are
            # expanded to the full path
            configObj = teal.load(fileutil.osfn(configObj))

    # merge in the user values for this run
    # this, though, does not save the results for use later
    if input_dict not in [None, {}]:  # and configObj not in [None, {}]:
        # check to see whether any input parameters are unexpected.
        # Any unexpected parameters provided on input should be reported and
        # the code should stop
        validateUserPars(configObj, input_dict)

        # If everything looks good, merge user inputs with configObj and continue
        cfgpars.mergeConfigObj(configObj, input_dict)
        # Update the input .cfg file with the updated parameter values
        #configObj.filename = os.path.join(cfgpars.getAppDir(),os.path.basename(configObj.filename))
        #configObj.write()

    if not loadOnly:
        # We want to run the GUI AFTER merging in any parameters
        # specified by the user on the command-line and provided in
        # input_dict
        configObj = teal.teal(configObj, loadOnly=False)

    return configObj
Example #30
0
def getDefaultConfigObj(taskname,configObj,input_dict={},loadOnly=True):
    """ Return default configObj instance for task updated
        with user-specified values from input_dict.

        Parameters
        ----------
        taskname : string
            Name of task to load into TEAL

        configObj : string
            The valid values for 'configObj' would be::

                None                      - loads last saved user .cfg file
                'defaults'                - loads task default .cfg file
                name of .cfg file (string)- loads user-specified .cfg file

        input_dict : dict
            Set of parameters and values specified by user to be different from
            what gets loaded in from the .cfg file for the task

        loadOnly : bool
            Setting 'loadOnly' to False causes the TEAL GUI to start allowing the
            user to edit the values further and then run the task if desired.

    """
    if configObj is None:
        # Start by grabbing the default values without using the GUI
        # This insures that all subsequent use of the configObj includes
        # all parameters and their last saved values
        configObj = teal.load(taskname)
    elif isinstance(configObj,str):
        if configObj.lower().strip() == 'defaults':
            # Load task default .cfg file with all default values
            configObj = teal.load(taskname,defaults=True)
            # define default filename for configObj
            configObj.filename = taskname.lower()+'.cfg'
        else:
            # Load user-specified .cfg file with its special default values
            # we need to call 'fileutil.osfn()' to insure all environment
            # variables specified by the user in the configObj filename are
            # expanded to the full path
            configObj = teal.load(fileutil.osfn(configObj))

    # merge in the user values for this run
    # this, though, does not save the results for use later
    if input_dict not in [None,{}]:# and configObj not in [None, {}]:
        # check to see whether any input parameters are unexpected.
        # Any unexpected parameters provided on input should be reported and
        # the code should stop
        validateUserPars(configObj,input_dict)

        # If everything looks good, merge user inputs with configObj and continue
        cfgpars.mergeConfigObj(configObj, input_dict)
        # Update the input .cfg file with the updated parameter values
        #configObj.filename = os.path.join(cfgpars.getAppDir(),os.path.basename(configObj.filename))
        #configObj.write()

    if not loadOnly:
    # We want to run the GUI AFTER merging in any parameters
    # specified by the user on the command-line and provided in
    # input_dict
        configObj = teal.teal(configObj,loadOnly=False)

    return configObj