Package multidrizzle
[hide private]
[frames] | no frames]

Source Code for Package multidrizzle

  1  """ 
  2  MultiDrizzle combines astronomical images while removing 
  3  distortion and cosmic-rays. The Python syntax for using 
  4  MultiDrizzle relies on initializing a MultiDrizzle object, 
  5  building up the parameters necessary for combining the images, 
  6  then performing the actual processing necessary to generate 
  7  the final product.  The process starts with the input of the 
  8  image names to initialize the MultiDrizzle object: 
  9   
 10  >>> import multidrizzle 
 11  >>> md = multidrizzle.MultiDrizzle(input,'other parameters') 
 12  >>> md.build() 
 13  >>> md.run() 
 14   
 15  MultiDrizzle defines default values for all inputs, and only 
 16  those values which need to be over-ridden should be entered. 
 17   
 18  Further help can be obtained interactively using: 
 19  >>> md.help() 
 20   
 21  :author: Warren Hack, Christopher Hanley, Ivo Busko, and David Grumm 
 22   
 23  """ 
 24  from __future__ import division # confidence high 
 25   
 26   
 27  # Do not use this here.  It kills epydoc. 
 28  # 
 29  # __docformat__ = 'restructuredtext' 
 30   
 31   
 32   
 33  # Begin Import Modules --------------------------------------------------- 
 34  import os, shutil, sys, string 
 35  import numpy as np 
 36  from pydrizzle import pydrizzle, process_input 
 37  from pydrizzle import drutil 
 38  import pyfits 
 39  from pytools import fileutil 
 40  import mdzhandler 
 41  import manager 
 42  from manager import ImageManager 
 43  import mdrizpars 
 44  from procstep import ProcSteps, timestamp 
 45  # This module is used to replicate IRAF style inputs. 
 46  from pytools import parseinput 
 47  from pytools.parseinput import parseinput 
 48   
 49  # End Import Modules ----------------------------------------------------- 
 50   
 51   
 52  # Begin Version Information ------------------------------------------- 
 53  __version__ = '3.3.8' 
 54  __vdate__ = '08-Jul-2010' 
 55  # End Version Information --------------------------------------------- 
 56  # Revision based version info 
 57  try: 
 58      import svn_version 
 59      __svn_version__ = svn_version.__svn_version__ 
 60  except ImportError: 
 61      __svn_version__ = 'Unable to determine SVN revision' 
 62   
63 -class Multidrizzle:
64 """ 65 The MultiDrizzle object manages the processing of the images. All 66 input parameters, including the input, have default values, so only 67 those parameters which need to be changed should be specified. The 68 processing requires the following steps to be performed in order: 69 - input all parameters and convert all input images to 70 multi-extension FITS (MEF) files 71 72 >>> md = multidrizzle.MultiDrizzle (input, output=None, 73 editpars=no,**input_dict) 74 75 where editpars turns on/off the GUI parameter editor 76 input_dict contains all parameters which have non-default values 77 78 - (optionally) edit all input parameter values with Traits-based GUI 79 80 >>> md.editpars() 81 82 - build parameters necessary for combining the images 83 84 >>> md.build() 85 86 - process the images through the steps which were turned on 87 88 >>> md.run( static = None, skysub = None, 89 driz_separate = None, median = None, 90 blot = None, driz_cr = None, 91 driz_combine = None, timing = None): 92 93 where each parameter controls whether a processing step gets performed. 94 95 A full list of the parameters can be obtained from the MultiDrizzle 96 help file. 97 98 99 """ 100 init_keys = ['mdriztab','runfile','workinplace', 101 'context','clean','shiftfile','staticfile', 102 'static_sig','coeffs'] 103 104 driz_keys = ['refimage','group','ra','dec','build'] 105 106 instr_keys = ['gain','gnkeyword','rdnoise','rnkeyword', 107 'exptime', 'expkeyword','crbit'] 108 sky_keys = ['skywidth','skystat', 'skylower','skyupper', 109 'skyclip','skylsigma','skyusigma','skyuser'] 110 111 median_keys = ['median_newmasks','combine_type','combine_nsigma', 112 'combine_nlow', 'combine_nhigh','combine_lthresh', 113 'combine_hthresh','combine_grow','combine_maskpt','nsigma1','nsigma2' ] 114 115 drizcr_keys = ['driz_cr_snr','driz_cr_scale', 'driz_cr_corr', 116 'driz_cr_grow','driz_cr_ctegrow'] 117 118 blot_keys = ['blot_interp','blot_sinscl'] 119
120 - def __init__(self, 121 input = '*flt.fits', 122 output = None, 123 editpars = False, 124 shiftfile = None, 125 updatewcs = True, 126 **input_dict):
127 128 timestamp() 129 print 'Running MultiDrizzle ',__version__ 130 131 # Print version information for all external python modules used 132 self.versions = versioninfo() 133 134 self.shiftfile = shiftfile 135 self.updatewcs = updatewcs 136 if input_dict.has_key('proc_unit'): 137 self.proc_unit = input_dict['proc_unit'] 138 else: 139 self.proc_unit = "native" 140 141 142 # We need to parse the input to get the list of filenames 143 # that are to be processed by Multidrizzle. 144 # 145 # VARIABLE DEFINITIONS 146 # self.output: the 'user' specified output string used to name 147 # the output file created by Multidrizzle. 148 # 149 # self.files: A python list containing the input file names to be 150 # processed by Multidrizzle. 151 # 152 # self.ivmlist: A python list containing the input filenames representing 153 # input IVM files 154 # 155 # self.numInputs: Integer value representing the number of individual science 156 # data files that will need to drizzled by Multidrizzle 157 # 158 # self.numASNfiles: The number of association files that Multidrizzle has 159 # received as input 160 # 161 # self.parseSTISflag: Boolean value used to indicate if a STIS association 162 # file was given as input and subsequently split into 163 # multiple files. 164 # 165 # self.parseWFPC2flag: Boolean value used to indicate if WFPC2 data was given 166 # as GEIS format files and convereted to multi extension FITS. 167 # 168 # self.translatedNames: Dictionary mapping input filenames to translated filenames 169 # 170 # self.translatedNameOrder: List copying order of original inputs 171 # 172 # self.excludedFileList: List containing names of input files excluded from 173 # Multidrizzle processing 174 # 175 # 176 #self.output,self.files,self.ivmlist,self.numInputs,\ 177 #self.numASNfiles,self.parseSTISflag,self.parseWFPC2flag, \ 178 #self.translatedNames, self.translatedNameOrder, self.excludedFileList \ 179 # = self._parseInput(input,output) 180 181 # Initialize attribute for zero exposure time asn table. Will only 182 # be created if the input association file containings members whose 183 # EXPTIME value is zero 184 #self.zeroExptimeAsnTable = None 185 186 # We need to make certain that we have not thrown out all of the data 187 # because of the zero exposure time problem. 188 # 189 # numInputs <= 0: We have no input. 190 self.errorstate = False 191 192 # Remember the original user 'input' value 193 self.input = input 194 asndict, ivmfiles, output = process_input.process_input(input, output=output, updatewcs=self.updatewcs, shiftfile=shiftfile) 195 self.asndict = asndict 196 self.ivmlist = ivmfiles 197 self.output = output 198 if not self.asndict: 199 self.errorstate = True 200 return 201 # Check status of file processing. If all files have been 202 # Report the names of the input files that have just been parsed. 203 self.files = [fileutil.buildRootname(f) for f in self.asndict['order']] 204 205 self.printInputFiles() 206 207 # Check input files. This is the private method used to call the 208 # MAKEWCS application. MAKEWCS is used to recompute and update the 209 # WCS for input images, which updatewcs makes optional 210 211 #self._checkInputFiles(self.files, updatewcs) 212 213 # Initialize the master parameter dictionary. 214 # This needs to be done after any input file conversion 215 # since it needs to be able to open the file to read the 216 # MDRIZTAB keyword, if this parameter is set to TRUE. 217 218 self.pars = mdrizpars.MDrizPars(self.input, self.output, 219 dict=input_dict,files=self.files) 220 221 # Initialize attributes needed for each processing step 222 # These get populated by the 'build' method. 223 self.steps = None 224 self.skypars = {} 225 self.medianpars = {} 226 self.drizcrpars = {} 227 self.blotpars = {} 228 self.driz_sep_pars = {} 229 self.driz_final_pars = {} 230 self.instrpars = {} 231 232 self.image_manager = None 233 234 # Convenience for user: if they specify 'editpars' on 235 # command line as parameter, then automatically run GUI 236 # editor for them. 237 self.traits_edited = False 238 if editpars: 239 self.editpars()
240
241 - def editpars(self):
242 """ Run Python GUI parameter editor to set parameter values. """ 243 self.pars.edit_traits() 244 self.traits_edited = True
245 246
247 - def build(self):
248 """ Parses parameter list into dictionaries for use by 249 each processing step, builds the PyDrizzle input 250 association table, builds the PyDrizzle object and 251 uses that to build the InputImage instances needed 252 for MultiDrizzle processing. 253 """ 254 255 if self.errorstate == True: 256 # If we are in this conditional, the Multidrizzle constructor 257 # exited with a return without actually completing it's normal 258 # processing. This exit from Multidrizzle is to allow for 259 # the stopping of execution withour raising an acception. This 260 # keeps the HST pipeline from crashing because of a raised 261 # reception. This state likely occured because all of the input 262 # images the user provided to Multidrizzle were excluded from 263 # processing because of problems with the data (like a 0 EXPTIME 264 # value). 265 # 266 # Just return and end exection 267 return 268 269 #Update master_pars dictionary, and switches dictionary 270 # based on last set values. 271 if self.traits_edited: 272 self.pars.updateMasterPars() 273 274 # Use the values in the master parlist to set the values 275 # for the attributes necessary for initializing this class 276 for kw in self.init_keys: 277 self.__dict__[kw] = self.pars.master_pars[kw] 278 # runfile could have been converted to an integer by the above, 279 # so we have to make sure it's a string 280 self.runfile = str(self.runfile) 281 282 283 # Create object that controls step execution and mark 284 # initialization step. 285 self.steps = self.pars.steps 286 self.steps.doStep(ProcSteps.doInitialize) 287 288 self.skypars = self.pars.getParList(self.sky_keys) 289 self.medianpars = self.pars.getParList(self.median_keys,prefix='combine_') 290 self.drizcrpars = self.pars.getParList(self.drizcr_keys) 291 self.blotpars = self.pars.getParList(self.blot_keys, prefix='blot_') 292 293 # Finalize building PyDrizzle and instrument parameters. 294 # If not defined by the user, use defaults. 295 self.driz_sep_pars = self.pars.getDrizPars(prefix='driz_sep',keylist=self.driz_keys) 296 self.driz_final_pars = self.pars.getDrizPars(prefix='driz_final',keylist=self.driz_keys) 297 self.instrpars = self.pars.getParList(self.instr_keys) 298 299 # Finish massaging median pars parameters to account for 300 # special processing of input values 301 self.setMedianPars() 302 303 304 # SINGELTON TEST: Verify that if only one file is provided for 305 # processing that the median, blot, and driz_cr steps are 306 # then turned off. If they are not turned off, the program 307 # will fail because you cannot create a median image with 308 # only 1 input. ;-) 309 if (len(self.files) == 1): 310 if self.pars.switches['median'] == True: 311 errorstr = "####################################\n" 312 errorstr += "# #\n" 313 errorstr += "# WARNING: #\n" 314 errorstr += "# Step 4: CREATE MEDIAN IMAGE has #\n" 315 errorstr += "# been turned off because only #\n" 316 errorstr += "# one file was provided as input. #\n" 317 errorstr += "# #\n" 318 errorstr += "####################################\n\n" 319 print errorstr 320 self.pars.switches['median'] = False 321 if self.pars.switches['blot'] == True: 322 errorstr = "############################################\n" 323 errorstr += "# #\n" 324 errorstr += "# WARNING: #\n" 325 errorstr += "# Step 5: BLOT BACK THE MEDIAN IMAGE has #\n" 326 errorstr += "# been turned off because only one file #\n" 327 errorstr += "# was provided as input. #\n" 328 errorstr += "# #\n" 329 errorstr += "############################################\n\n" 330 print errorstr 331 self.pars.switches['blot'] = False 332 if self.pars.switches['driz_cr'] == True: 333 errorstr = "#######################################################\n" 334 errorstr += "# #\n" 335 errorstr += "# WARNING: #\n" 336 errorstr += "# Step 6: REMOVE COSMIC RAYS WITH DERIV, DRIZ_CR has #\n" 337 errorstr += "# been turned off because only one file was provided #\n" 338 errorstr += "# as input. #\n" 339 errorstr += "# #\n" 340 errorstr += "#######################################################\n\n" 341 print errorstr 342 self.pars.switches['driz_cr'] = False 343 344 345 346 # Extract the 'driz_final_wht_type' parameter 347 wht_type = self.pars.master_pars['driz_final_wht_type'] 348 # Verify that ERR extension exists if final_wht_type = ERR 349 if ( wht_type != None and wht_type.upper() == 'ERR'): 350 for file in self.files: 351 if not fileutil.findFile(file+"[err,1]"): 352 raise ValueError,"! final_wht_type = ERR, no ERR array found for %s"%(file) 353 # Check static file. Can only be done after reading MDRIZTAB. 354 if (self.staticfile != None): 355 self._checkStaticFile(self.staticfile) 356 357 358 # Create copies of input files for processing 359 if not self.workinplace: 360 self._createInputCopies(self.files) 361 else: 362 print "\n\n********************" 363 print "WARNING: Sky will be subtracted from sci extensions" 364 print "WARNING: Units of sci extensions will be electrons" 365 print "WARNING: Value of MDRIZSKY is in units of input data sci extensions." 366 print "********************\n\n" 367 368 # Extract bits value and final units from master dictionary for use in setupAssociation 369 self.driz_sep_bits = self.pars.master_pars['driz_sep_bits'] 370 self.final_bits = self.pars.master_pars['driz_final_bits'] 371 self.final_units = self.pars.master_pars['driz_final_units'] 372 373 # Build association object 374 #association = self._setupAssociation() 375 # Run PyDrizzle; make sure there are no intermediate products 376 # laying around... 377 #self.asndict.update(shiftfile=self.shiftfile) 378 #asnname = fileutil.buildNewRootname(self.asndict['output'], extn='_asn.fits') 379 #print 'asnname', asnname 380 381 assoc = pydrizzle._PyDrizzle(self.asndict, output=self.output, 382 idckey=self.coeffs, 383 section=self.driz_sep_pars['group'], 384 bits_single=self.driz_sep_bits, 385 bits_final=self.final_bits, 386 ) 387 388 # Use PyDrizzle to clean up any previously produced products... 389 if self.clean: 390 assoc.clean() 391 392 print 'Initial parameters: ' 393 assoc.printPars(format=1) 394 395 # Add any specifed IVM filenames to the association object 396 for plist in assoc.parlist: 397 fname,extname = fileutil.parseFilename(plist['data']) 398 ivmname = None 399 if len(self.ivmlist) > 0: 400 for index in xrange(len(self.ivmlist)): 401 if self.files[index] == fname: 402 ivmname = self.ivmlist[index] 403 plist['ivmname'] = ivmname 404 405 # Build the manager object. 406 #self.image_manager = ImageManager(association, self.context, self.instrpars, self.workinplace, \ 407 #self.staticfile, self.updatewcs) 408 self.image_manager = ImageManager(assoc, self.context, self.instrpars, self.workinplace, self.staticfile, self.proc_unit) 409 410 # Done with initialization. 411 self.steps.markStepDone(ProcSteps.doInitialize)
412 413
414 - def printInputFiles(self):
415 """ 416 417 METHOD : printInputFiles 418 PURPOSE : Print out the names of the file that Multidrizzle has identified 419 for processing based upon the given input string. 420 INPUT : String representing the user provided input string 421 OUTPUT : none 422 423 """ 424 425 print "Input string provided to Multidrizzle: ", str(self.input) 426 print "The following files have been identified by the given input string:" 427 for filename in self.files: 428 print " ",str(filename) 429 print "Output rootname: ", str(self.output)
430 431
432 - def setMedianPars(self):
433 """ Sets the special median parameters which need to 434 be parsed out of the original input parameters. """ 435 436 (_nsigma1, _nsigma2) = _splitNsigma(self.medianpars['nsigma']) 437 self.medianpars['nsigma1'] = _nsigma1 438 self.medianpars['nsigma2'] = _nsigma2 439 self.medianpars['newmasks'] = self.medianpars['median_newmasks']
440 441
442 - def _createInputCopies(self,files):
443 """ 444 Creates copies of all input images. 445 446 If a previous execution of multidrizzle has failed and _OrIg 447 files already exist, before removing the _OrIg files, we will 448 copy the 'sci' extensions out of those files _OrIg files and 449 use them to overwrite what is currently in the existing 450 input files. This protects us against crashes in the HST 451 pipeline where Multidrizzle is restarted after the sky 452 has already been subtracted from the input files. 453 """ 454 455 for _img in files: 456 # Only make copies of files that exist 457 if os.path.exists(_img): 458 # Create filename for copy 459 _copy = manager.modifyRootname(_img) 460 # Make sure we remove any previous copies first, 461 # after we copy 'sci' extension into the 462 # possibly corrupted input file. This 463 # ensures that Multidrizzle restarts will 464 # always have pristine input to use. 465 if os.path.exists(_copy): 466 fimage = fileutil.openImage(_img,mode='update') 467 fcopy = fileutil.openImage(_copy) 468 index = 0 469 for extn in fcopy: 470 if extn.name.upper() == 'SCI': 471 fimage[index].data = fcopy[index].data 472 index += 1 473 fimage.close() 474 fcopy.close() 475 os.remove(_copy) 476 477 # Copy file into new filename 478 shutil.copyfile(_img,_copy) 479 480 #def _checkInputFiles(self, files, updatewcs): 481 482 """ Checks input files before they are required later. """ 483 484 """ Checks that MAKEWCS is run on any ACS image in 'files' list. """ 485 """ 486 for p in files: 487 488 if fileutil.getKeyword(p,'idctab') != None: 489 if fileutil.getKeyword(p,'PA_V3') != None: 490 # Update the CD matrix using the new IDCTAB 491 # Not perfect, but it removes majority of errors... 492 if updatewcs == True: 493 makewcs.run(input=p) # optionally update wcs 494 495 elif (os.path.exists(p[0:p.find('_')]+'_spt.fits')): 496 msgstr = "\n########################################\n" 497 msgstr += "# #\n" 498 msgstr += "# WARNING: #\n" 499 msgstr += "# The keyword PA_V3 was not found in #\n" 500 msgstr += "# the primary header of file: #\n" 501 msgstr += " "+str(p)+"\n" 502 msgstr += "# Attempting to extract value from #\n" 503 msgstr += "# corresponding SPT file and append #\n" 504 msgstr += "# it to the primary header file of #\n" 505 msgstr += "# the input image. #\n" 506 msgstr += "# #\n" 507 msgstr += "########################################\n" 508 print msgstr 509 510 try: 511 # Build the name of the SPT we are trying to find 512 sptfilename = p[0:p.find('_')]+'_spt.fits' 513 # Extract the PA_V3 value from the primary header 514 # of the SPT file 515 pa_v3 = fileutil.getKeyword(sptfilename,'PA_V3') 516 # If the PA_V3 value is None, raise an exception 517 if (pa_v3 == None): 518 raise ValueError 519 # Open the file we are tyring to process in update 520 # mode. 521 img = pyfits.open(p,mode='update') 522 # Add the PA_V3 value to the input file 523 img[0].header.update("PA_V3",float(pa_v3)) 524 # Close the input file. 525 img.close() 526 # Optionally run makewcs 527 if updatewcs == True: makewcs.run(input=p) 528 except: 529 # We have failed to add the PA_V3 value to the 530 # input file. Raise an exception and give up. 531 self.__pav3errmsg(p) 532 raise ValueError, "Multidrizzle exiting..." 533 else: 534 self.__pav3errmsg(p) 535 raise ValueError, "Multidrizzle exiting..." 536 """
537 """ 538 def __pav3errmsg(self,filename): 539 msgstr = "\n*******************************************\n" 540 msgstr += "* *\n" 541 msgstr += "* Primary header keyword PA_V3 not found! *\n" 542 msgstr += "* World Coordinate keywords cannot be *\n" 543 msgstr += "* recomputed without a valid PA_V3 value. *\n" 544 msgstr += "* Please insure that PA_V3 is populated *\n" 545 msgstr += "* in the primary header of *\n" 546 msgstr += " %s \n"%(filename) 547 msgstr += "* This keyword is generated by versions *\n" 548 msgstr += "* of OPUS 15.7 or later. If the data were *\n" 549 msgstr += "* obtained from an earlier version of *\n" 550 msgstr += "* OPUS, please re-retrieve the data from *\n" 551 msgstr += "* the archive after OPUS 15.7 has been *\n" 552 msgstr += "* installed, or manually add the keyword *\n" 553 msgstr += "* with the proper value to the header (it *\n" 554 msgstr += "* may be found in the SPT file header) *\n" 555 msgstr += "* *\n" 556 msgstr += "*******************************************\n" 557 558 print msgstr 559 560 """
561 - def _checkStaticFile(self, static_file):
562 563 """ Checks input files before they are required later. """ 564 565 # Checks existence of static mask. 566 # Setup error string in case it can not find file... 567 if (static_file != None): 568 _err_str = "Cannot find static mask file: " + static_file 569 try: 570 # This call avoids unnecessary file open calls. 571 _exist = fileutil.checkFileExists(static_file) 572 if not _exist: 573 raise ValueError, _err_str 574 except IOError: 575 raise ValueError, _err_str 576 577 # Verify that the number of sci extensions in the input is equal 578 # to the number of MASK extensions in the static file. 579 580 try: 581 # Count the number of sci extensions 582 sciimg = pyfits.open(self.files[0]) 583 scicount = 0 584 for extension in sciimg: 585 if extension.header.has_key('extname'): 586 if (extension.header['extname'].upper() == 'SCI'): 587 scicount += 1 588 # Count the number of mask extensions 589 maskimg = pyfits.open(static_file) 590 maskcount = 0 591 for extension in maskimg: 592 if extension.header.has_key('extname'): 593 if (extension.header['extname'].upper() == 'MASK'): 594 maskcount += 1 595 596 if (scicount != maskcount): 597 raise ValueError 598 except ValueError: 599 # If the sci and mask extension counts don't mask raise a value error 600 errorstr = "\n############################################\n" 601 errorstr += "# #\n" 602 errorstr += "# ERROR: #\n" 603 errorstr += "# The user supplied static mask file #\n" 604 errorstr += " " + str(static_file) + "\n" 605 errorstr += "# does not contain enough MASK #\n" 606 errorstr += "# extensions. There needs to be 1 #\n" 607 errorstr += "# MASK extension for every SCI #\n" 608 errorstr += "# extension. #\n" 609 errorstr += "# #\n" 610 errorstr += "############################################\n" 611 raise ValueError, errorstr 612 except: 613 errorstr = "\n############################################\n" 614 errorstr += "# #\n" 615 errorstr += "# Error: #\n" 616 errorstr += "# Unable to verify the user supplied #\n" 617 errorstr += "# static mask file is in the correct #\n" 618 errorstr += "# format. Test could not complete. #\n" 619 errorstr += "# #\n" 620 errorstr += "############################################\n" 621 raise IOError, errorstr
622 623 624
625 - def _preMedian(self, skysub):
626 """ Perform the steps that take place before median computation: 627 build static mask, subtract sky, drizzle into separate images. 628 """ 629 # Build static mask 630 631 if self.steps.doStep(ProcSteps.doBuildStatic): 632 self.image_manager.createStatic(static_sig=self.static_sig) 633 self.steps.markStepDone(ProcSteps.doBuildStatic) 634 635 # Process sky. 636 # 637 # Note that we must use the boolean flag returned by the step 638 # controller, not the local skysub variable. This is because 639 # the MDRIZTAB reading routine may redefine the flag; thus 640 # rendering the local variable inaccurate. 641 if self.steps.getFlag(ProcSteps.doSky): 642 self.steps.printTimestamp(ProcSteps.doSky) 643 self.steps.resetStep(ProcSteps.doSky) 644 self.image_manager.doSky(self.skypars,self.steps.getFlag(ProcSteps.doSky)) 645 self.steps.markStepDone(ProcSteps.doSky) 646 647 # Drizzle separate 648 649 if self.steps.doStep(ProcSteps.doDrizSeparate): 650 self.image_manager.doDrizSeparate (self.driz_sep_pars) 651 self.steps.markStepDone(ProcSteps.doDrizSeparate)
652 653
654 - def _postMedian(self, blotpars, drizcrpars, skypars):
655 """ Perform the steps that take place after median computation: 656 blot, and drizcr. 657 """ 658 659 # Blot 660 661 if self.steps.doStep(ProcSteps.doBlot): 662 self.image_manager.doBlot(blotpars) 663 self.steps.markStepDone(ProcSteps.doBlot) 664 665 # Driz CR 666 667 if self.steps.doStep(ProcSteps.doDrizCR): 668 self.image_manager.doDrizCR(drizcrpars, skypars) 669 self.steps.markStepDone(ProcSteps.doDrizCR)
670
671 - def run(self, 672 static = None, 673 skysub = None, 674 driz_separate = None, 675 median = None, 676 blot = None, 677 driz_cr = None, 678 driz_combine = None, 679 timing = None):
680 681 if self.errorstate == True: 682 # If we are in this conditional, the Multidrizzle constructor 683 # exited with a return without actually completing it's normal 684 # processing. This exit from Multidrizzle is to allow for 685 # the stopping of execution without raising an acception. This 686 # keeps the HST pipeline from crashing because of a raised 687 # exception. This state likely occured because all of the input 688 # images the user provided to Multidrizzle were excluded from 689 # processing because of problems with the data (like a 0 EXPTIME 690 # value). 691 # 692 # Just return and end exection 693 return 694 695 696 # Update object that controls step execution. Use either user 697 # interface switches, or MDRIZTAB switches. 698 self.pars.setProcSteps(static=static, 699 skysub=skysub, 700 driz_separate = driz_separate, 701 median = median, 702 blot = blot, 703 driz_cr = driz_cr, 704 driz_combine = driz_combine, 705 timing = timing) 706 707 # Start by applying input parameters to redefine 708 # the output frame as necessary 709 self.image_manager._setOutputFrame(self.driz_sep_pars) 710 711 self._preMedian(skysub) 712 if self.steps.doStep(ProcSteps.doMedian): 713 self.image_manager.createMedian(self.medianpars) 714 self.steps.markStepDone(ProcSteps.doMedian) 715 716 self._postMedian(self.blotpars, self.drizcrpars, self.skypars) 717 718 if self.steps.doStep(ProcSteps.doFinalDriz): 719 self.driz_final_pars['runfile'] = self.runfile 720 self.image_manager.doFinalDriz(self.driz_final_pars) 721 self.runfile = self.driz_final_pars['runfile'] 722 self.image_manager.updateMdrizVerHistory(self.driz_final_pars['build'],self.versions) 723 self.steps.markStepDone(ProcSteps.doFinalDriz) 724 725 # Close open file handles opened by PyDrizzle 726 # Now that we are done with the processing, 727 # delete any input copies we created. 728 729 if not self.workinplace: 730 self.image_manager.removeInputCopies() 731 732 # If clean has been set, remove intermediate products now. 733 if self.clean: 734 # Start by deleting the runfile 735 if os.path.exists(self.runfile): 736 os.remove(self.runfile) 737 738 # Now have image_manager remove all image products 739 self.image_manager.removeMDrizProducts() 740 741 if self.pars.switches['timing']: 742 self.steps.reportTimes()
743
744 - def help(self):
745 """ 746 747 Purpose 748 ======= 749 Help function on Multidrizzle Class that 750 prints __doc__ string. 751 752 """ 753 754 print 'MultiDrizzle Version ',__version__ 755 print self.__doc__
756 757
758 -def _splitNsigma(s):
759 """ 760 761 Purpose 762 ======= 763 This is a help function that is used to split up the "combine_nsigma" 764 string. If a second value is specified, then this will be used later 765 in "minmed" where a second-iteration rejection is done. Typically 766 the second value should be around 3 sigma, while the first 767 can be much higher. 768 769 """ 770 _sig = s.split(" ") 771 _nsigma1 = float(_sig[0]) 772 _nsigma2 = float(_sig[0]) 773 if len(_sig) > 1: 774 _nsigma2 = float(_sig[1]) 775 return (_nsigma1, _nsigma2)
776 777
778 -def help():
779 """ 780 781 Purpose 782 ======= 783 Function prints help information for MultiDrizzle. 784 785 """ 786 787 788 help_str = "MultiDrizzle combines astronomical images while removing \n" 789 help_str += "distortion and cosmic-rays. The Python syntax for using \n" 790 help_str += "MultiDrizzle relies on initializing a MultiDrizzle object, \n" 791 help_str += "building up the parameters necessary for combining the images, \n" 792 help_str += "then performing the actual processing necessary to generate \n" 793 help_str += "the final product. The process starts with the input of the \n" 794 help_str += "image names to initialize the MultiDrizzle object: \n" 795 help_str += " \n" 796 help_str += ">>> import multidrizzle \n" 797 help_str += ">>> md = multidrizzle.MultiDrizzle(input,args,...) \n" 798 help_str += ">>> md.build() \n" 799 help_str += ">>> md.run() \n" 800 help_str += " \n" 801 help_str += "MultiDrizzle defines default values for all inputs, and only \n" 802 help_str += "those values which need to be over-ridden should be entered. \n" 803 help_str += " \n" 804 print 'MultiDrizzle Version ',__version__ 805 print help_str
806 807
808 -def versioninfo():
809 """ 810 811 Purpose 812 ======= 813 Function prints version information for packages used by Multidrizzle 814 815 """ 816 817 # Initialize version dictionary 818 version_dict = {} 819 820 # Set up version ID's for printing to the log file 821 mdrizzle_key = " MultiDrizzle " 822 array_key = " NUMPY Version " 823 pydrizzle_key = " PyDrizzle Version " 824 pyfits_key = " PyFITS Version " 825 python_key = " Python Version: " 826 827 version_dict[mdrizzle_key] = __version__ 828 version_dict[array_key]= np.__version__ 829 version_dict[pydrizzle_key]= pydrizzle.__version__ 830 version_dict[pyfits_key] = pyfits.__version__ 831 832 _sys_version_list = sys.version.split("\n") 833 _sys_version = " # " 834 for _sys_str in _sys_version_list: 835 _sys_version += _sys_str+"\n # " 836 version_dict[python_key] = '\n'+_sys_version 837 838 # Print out version information for libraries used by MultiDrizzle 839 print "\n" 840 print " Version Information for MultiDrizzle "+version_dict[mdrizzle_key] 841 print "-------------------------------------------- " 842 print array_key + version_dict[array_key] 843 print pyfits_key + version_dict[pyfits_key] 844 print pydrizzle_key + version_dict[pydrizzle_key] 845 print python_key + version_dict[python_key] 846 print "\n" 847 848 return version_dict
849