def edit_refimagefindpars(): """ Allows the user to edit the refimagefindpars configObj in a TEAL GUI """ teal.teal(refimagefindpars.__taskname__, returnAs=None, autoClose=True, loadOnly=False, canExecute=False)
def run(configobj=None,editpars=False): """ Teal interface for running this code. """ if configobj is None: configobj =teal.teal(__taskname__,loadOnly=(not editpars)) update(configobj['input'],configobj['refdir'], local=configobj['local'],interactive=configobj['interactive'], wcsupdate=configobj['wcsupdate'])
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
raise ValueError('Too many input arguments') targ = os.path.split(os.getcwd())[-1] cat_path = '/astro/pabeta/HSC_Catalogs' all_cats = glob.glob('{}/*_hsc.radec'.format(cat_path)) cats = [] if not os.path.exists(targ + '_hsc.radec'): for derp in all_cats: if targ in derp.upper(): print derp cats.append(derp) if len(cats) > 1: print 'TOO MANY CATALOGS MATCHED' raise else: cat = cats[0] shutil.copy(cat, '.') cat = os.path.split(cat)[-1] print cat else: cat = targ + '_hsc.radec' if options.t: teal.teal('tweakreg') if os.path.exists(cat): if options.a: calc_shift(ims[0], cat) shift_wrap() else: print 'NO HSC ENTRY IN CATALOG DIRECTORY FOR {}'.format(targ)
# drzs.remove(drzs[0]) for f in drzs: hdr = fits.getheader(f) if hdr['DETECTOR'] == 'IR': ir_ims.append(f) elif hdr['DETECTOR'] == 'UVIS' or hdr['DETECTOR'] == 'WFC': vis_ims.append(f) if fits.getval(ref, 'DETECTOR') == 'IR': thresh = 5. cw = 2.5 elif fits.getval(ref, 'DETECTOR') == 'UVIS' or fits.getval(ref, 'DETECTOR') == 'WFC': thresh = 20. cw = 3.5 # Determine WCS name if '_hsc.radec' in options.c: wcsname = 'HSC' else: wcsname = 'TWEAK' if options.t: teal.teal('tweakreg') if len(vis_ims)>0: tweakreg.TweakReg(vis_ims, updatehdr=True, expand_refcat=False,enforce_user_order=False,refimage=ref, imagefindcfg={'threshold':5.,'conv_width':3.5}, refimagefindcfg={'threshold':thresh,'conv_width':cw}, refcat=options.c,shiftfile=True,outshifts='vis_shifts.txt', wcsname=wcsname) if len(ir_ims)>0: tweakreg.TweakReg(ir_ims, updatehdr=True, expand_refcat=False,enforce_user_order=True,refimage=ref, imagefindcfg={'threshold':5.,'conv_width':2.5}, refimagefindcfg={'threshold':thresh,'conv_width':cw}, refcat=options.c,shiftfile=True,outshifts='ir_shifts.txt', wcsname=wcsname)
final_ra=ra, final_dec=dec, final_scale=scl, combine_type=med_alg, combine_nhigh=combine_nhigh, runfile='ADRIZ_{}'.format(out), clean=True, build=True, context=False) input_wcs = fits.getval(exps[0], 'wcsname', 1) if input_wcs == 'HSC': prod_name = glob.glob('{}_dr?.fits'.format(out))[0] fits.setval(prod_name, keyword='wcsname', value='HSC', extname='sci') if __name__ == '__main__': options = parse_args() filts = options.f if options.f != None: filts = [filt.upper() for filt in filts] exps_by_filt = parse_filters(filts) if options.t: teal.teal('astrodrizzle') if options.n != 0: p = Pool(options.n) p.map(final_drizzle, exps_by_filt) else: map(final_drizzle, exps_by_filt)
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
astrodrizzle.AstroDrizzle(exps,output=out, mdriztab=False, num_cores=1, in_memory=False,final_wcs=True,final_rot=rot, final_outnx=outnx,final_outny=outny, final_ra=ra, final_dec=dec,final_scale=scl,median=False, blot=False,driz_cr=False,runfile='ADRIZ_{}'.format(out), clean=True,build=True) else: astrodrizzle.AstroDrizzle(exps,output=out, mdriztab=False, num_cores=1, in_memory=False,final_wcs=True,final_rot=rot, final_outnx=outnx,final_outny=outny, final_ra=ra, final_dec=dec,final_scale=scl,combine_type=med_alg, combine_nhigh=combine_nhigh,runfile='ADRIZ_{}'.format(out), clean=True,build=True) input_wcs = fits.getval(exps[0],'wcsname',1) if input_wcs == 'HSC': prod_name = glob.glob('{}_dr?.fits'.format(out))[0] fits.setval(prod_name,keyword='wcsname',value='HSC',extname='sci') if __name__ == '__main__': options = parse_args() filts = options.f if options.f != None: filts = [filt.upper() for filt in options.f] exps_by_filt = parse_filters(filts) teal.teal('astrodrizzle') p = Pool(24) p.map(final_drizzle,exps_by_filt) # map(final_drizzle,exps_by_filt)
from drizzlepac import astrodrizzle, tweakreg, tweakback from stwcs import updatewcs import glob, os from astropy.io import fits from multiprocessing import Pool from stsci.tools import teal drzs = glob.glob('f127m*drz.fits')+glob.glob('f153m*drz.fits') teal.teal('tweakreg') tweakreg.TweakReg(drzs, updatehdr=True, expand_refcat=False,enforce_user_order=False,refimage='F139M_drz.fits', refimagefindcfg={'threshold':25,'conv_width':2.5})
# continue # elif hdr['FILTER'] == 'F128N': flts.append(f) filts[f] = hdr['FILTER'] targs[f] = hdr['TARGNAME'] print f, hdr['FILTER'], hdr['TARGNAME'] print sorted(flts) # p = Pool(12) # p.map(updatewcs.updatewcs, flts) # map(upwcs, flts) print '______________________________' for f in filts.keys(): print f, filts[f], targs[f] print filts.values(), targs.values() print set(filts.values()), sorted(set(targs.values())) teal.teal('tweakreg') flts_by_targ = [] for targ in set(targs.values()): for filt in set(filts.values()): exps = [] print filt for f in flts: if filts[f] == filt and targs[f] == targ: exps.append(f) flts_by_targ.append(exps) # teal.teal('astrodrizzle') # p = Pool(3) # map(reg,flts_by_targ) #