idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
35,600
def updateContextImage ( self , contextpar ) : self . createContext = contextpar if not contextpar : log . info ( 'No context image will be created for %s' % self . _filename ) self . outputNames [ 'outContext' ] = None
Reset the name of the context image to None if parameter context is False .
35,601
def getKeywordList ( self , kw ) : kwlist = [ ] for chip in range ( 1 , self . _numchips + 1 , 1 ) : sci_chip = self . _image [ self . scienceExt , chip ] if sci_chip . group_member : kwlist . append ( sci_chip . __dict__ [ kw ] ) return kwlist
Return lists of all attribute values for all active chips in the imageObject .
35,602
def getflat ( self , chip ) : sci_chip = self . _image [ self . scienceExt , chip ] filename = fileutil . osfn ( self . _image [ "PRIMARY" ] . header [ self . flatkey ] ) hdulist = None try : hdulist = fileutil . openImage ( filename , mode = 'readonly' , memmap = False ) data = hdulist [ ( self . scienceExt , chip ) ]...
Method for retrieving a detector s flat field .
35,603
def getExtensions ( self , extname = 'SCI' , section = None ) : if section is None : numext = 0 section = [ ] for hdu in self . _image : if 'extname' in hdu . header and hdu . header [ 'extname' ] == extname : section . append ( hdu . header [ 'extver' ] ) else : if not isinstance ( section , list ) : section = [ secti...
Return the list of EXTVER values for extensions with name specified in extname .
35,604
def buildEXPmask ( self , chip , dqarr ) : log . info ( "Applying EXPTIME weighting to DQ mask for chip %s" % chip ) exparr = self . _image [ self . scienceExt , chip ] . _exptime expmask = exparr * dqarr return expmask . astype ( np . float32 )
Builds a weight mask from an input DQ array and the exposure time per pixel for this chip .
35,605
def buildIVMmask ( self , chip , dqarr , scale ) : sci_chip = self . _image [ self . scienceExt , chip ] ivmname = self . outputNames [ 'ivmFile' ] if ivmname is not None : log . info ( "Applying user supplied IVM files for chip %s" % chip ) extn = "IVM,{}" . format ( chip ) ivm = fileutil . openImage ( ivmname , mode ...
Builds a weight mask from an input DQ array and either an IVM array provided by the user or a self - generated IVM array derived from the flat - field reference file associated with the input image .
35,606
def buildERRmask ( self , chip , dqarr , scale ) : sci_chip = self . _image [ self . scienceExt , chip ] errmask = dqarr if self . errExt is not None : try : err = self . getData ( exten = self . errExt + ',' + str ( chip ) ) log . info ( "Applying ERR weighting to DQ mask for chip %s" % chip ) exptime = sci_chip . _ex...
Builds a weight mask from an input DQ array and an ERR array associated with the input image .
35,607
def set_mt_wcs ( self , image ) : for chip in range ( 1 , self . _numchips + 1 , 1 ) : sci_chip = self . _image [ self . scienceExt , chip ] ref_chip = image . _image [ image . scienceExt , chip ] sci_chip . wcs = ref_chip . wcs . copy ( )
Reset the WCS for this image based on the WCS information from another imageObject .
35,608
def set_wtscl ( self , chip , wtscl_par ) : sci_chip = self . _image [ self . scienceExt , chip ] exptime = 1 _parval = 'unity' if wtscl_par is not None : if type ( wtscl_par ) == type ( '' ) : if not wtscl_par . isdigit ( ) : _wtscl_float = None try : _wtscl_float = float ( wtscl_par ) except ValueError : _wtscl_float...
Sets the value of the wt_scl parameter as needed for drizzling .
35,609
def _averageFromHeader ( self , header , keyword ) : _list = '' for _kw in keyword . split ( ',' ) : if _kw in header : _list = _list + ',' + str ( header [ _kw ] ) else : return None return self . _averageFromList ( _list )
Averages out values taken from header . The keywords where to read values from are passed as a comma - separated list .
35,610
def _averageFromList ( self , param ) : _result = 0.0 _count = 0 for _param in param . split ( ',' ) : if _param != '' and float ( _param ) != 0.0 : _result = _result + float ( _param ) _count += 1 if _count >= 1 : _result = _result / _count return _result
Averages out values passed as a comma - separated list disregarding the zero - valued entries .
35,611
def compute_wcslin ( self , undistort = True ) : for chip in range ( 1 , self . _numchips + 1 , 1 ) : sci_chip = self . _image [ self . scienceExt , chip ] chip_wcs = sci_chip . wcs . copy ( ) if chip_wcs . sip is None or not undistort or chip_wcs . instrument == 'DEFAULT' : chip_wcs . sip = None chip_wcs . cpdis1 = No...
Compute the undistorted WCS based solely on the known distortion model information associated with the WCS .
35,612
def set_units ( self , chip ) : sci_chip = self . _image [ self . scienceExt , chip ] _bunit = None if 'BUNIT' in sci_chip . header and sci_chip . header [ 'BUNIT' ] . find ( 'ergs' ) < 0 : _bunit = sci_chip . header [ 'BUNIT' ] else : _bunit = 'ELECTRONS/S' sci_chip . _bunit = _bunit if '/s' in _bunit . lower ( ) : _i...
Define units for this image .
35,613
def getTemplates ( fnames , blend = True ) : if not blend : newhdrs = blendheaders . getSingleTemplate ( fnames [ 0 ] ) newtab = None else : newhdrs , newtab = blendheaders . get_blended_headers ( inputs = fnames ) cleanTemplates ( newhdrs [ 1 ] , newhdrs [ 2 ] , newhdrs [ 3 ] ) return newhdrs , newtab
Process all headers to produce a set of combined headers that follows the rules defined by each instrument .
35,614
def addWCSKeywords ( wcs , hdr , blot = False , single = False , after = None ) : wname = wcs . wcs . name if not single : wname = 'DRZWCS' hdr [ 'WCSNAME' ] = wname hdr . set ( 'VAFACTOR' , value = 1.0 , after = after ) hdr . set ( 'ORIENTAT' , value = wcs . orientat , after = after ) if after in WCS_KEYWORDS : after ...
Update input header hdr with WCS keywords .
35,615
def writeSingleFITS ( data , wcs , output , template , clobber = True , verbose = True ) : outname , outextn = fileutil . parseFilename ( output ) outextname , outextver = fileutil . parseExtn ( outextn ) if fileutil . findFile ( outname ) : if clobber : log . info ( 'Deleting previous output product: %s' % outname ) f...
Write out a simple FITS file given a numpy array and the name of another FITS file to use as a template for the output image header .
35,616
def writeDrizKeywords ( hdr , imgnum , drizdict ) : _keyprefix = 'D%03d' % imgnum for key in drizdict : val = drizdict [ key ] [ 'value' ] if val is None : val = "" comment = drizdict [ key ] [ 'comment' ] if comment is None : comment = "" hdr [ _keyprefix + key ] = ( val , drizdict [ key ] [ 'comment' ] )
Write basic drizzle - related keywords out to image header as a record of the processing performed to create the image
35,617
def find_kwupdate_location ( self , hdr , keyword ) : kw_list = None last_kw = None for extn in self . fullhdrs : if keyword in extn : indx = extn . index ( keyword ) kw_list = list ( extn . keys ( ) ) [ : indx ] break if kw_list : for kw in kw_list [ : : - 1 ] : if kw in hdr : last_kw = kw break if last_kw is None : h...
Find the last keyword in the output header that comes before the new keyword in the original full input headers . This will rely on the original ordering of keywords from the original input files in order to place the updated keyword in the correct location in case the keyword was removed from the output header prior t...
35,618
def addDrizKeywords ( self , hdr , versions ) : _geom = 'User parameters' _imgnum = 0 for pl in self . parlist : _imgnum += 1 drizdict = DRIZ_KEYWORDS . copy ( ) drizdict [ 'VER' ] [ 'value' ] = pl [ 'driz_version' ] [ : 44 ] drizdict [ 'DATA' ] [ 'value' ] = pl [ 'data' ] [ : 64 ] drizdict [ 'DEXP' ] [ 'value' ] = pl ...
Add drizzle parameter keywords to header .
35,619
def iter_fit_shifts ( xy , uv , nclip = 3 , sigma = 3.0 ) : fit = fit_shifts ( xy , uv ) if nclip is None : nclip = 0 for n in range ( nclip ) : resids = compute_resids ( xy , uv , fit ) resids1d = np . sqrt ( np . power ( resids [ : , 0 ] , 2 ) + np . power ( resids [ : , 1 ] , 2 ) ) sig = resids1d . std ( ) goodpix =...
Perform an iterative - fit with nclip iterations
35,620
def fit_all ( xy , uv , mode = 'rscale' , center = None , verbose = True ) : if mode not in [ 'general' , 'shift' , 'rscale' ] : mode = 'rscale' if not isinstance ( xy , np . ndarray ) : xy = np . array ( xy ) if not isinstance ( uv , np . ndarray ) : uv = np . array ( uv ) if mode == 'shift' : logstr = 'Performing "sh...
Performs an rscale fit between matched lists of pixel positions xy and uv
35,621
def fit_arrays ( uv , xy ) : if not isinstance ( xy , np . ndarray ) : xy = np . array ( xy ) if not isinstance ( uv , np . ndarray ) : uv = np . array ( uv ) Sx = xy [ : , 0 ] . sum ( ) Sy = xy [ : , 1 ] . sum ( ) Su = uv [ : , 0 ] . sum ( ) Sv = uv [ : , 1 ] . sum ( ) Sux = np . dot ( uv [ : , 0 ] , xy [ : , 0 ] ) Sv...
Performs a generalized fit between matched lists of positions given by the 2 column arrays xy and uv .
35,622
def apply_fit ( xy , coeffs ) : x_new = coeffs [ 0 ] [ 2 ] + coeffs [ 0 ] [ 0 ] * xy [ : , 0 ] + coeffs [ 0 ] [ 1 ] * xy [ : , 1 ] y_new = coeffs [ 1 ] [ 2 ] + coeffs [ 1 ] [ 0 ] * xy [ : , 0 ] + coeffs [ 1 ] [ 1 ] * xy [ : , 1 ] return x_new , y_new
Apply the coefficients from a linear fit to an array of x y positions .
35,623
def compute_resids ( xy , uv , fit ) : print ( 'FIT coeffs: ' , fit [ 'coeffs' ] ) xn , yn = apply_fit ( uv , fit [ 'coeffs' ] ) resids = xy - np . transpose ( [ xn , yn ] ) return resids
Compute the residuals based on fit and input arrays to the fit
35,624
def AstroDrizzle ( input = None , mdriztab = False , editpars = False , configobj = None , wcsmap = None , ** input_dict ) : if isinstance ( configobj , ( str , bytes ) ) : if configobj == 'defaults' : configobj = teal . load ( __taskname__ ) else : if not os . path . exists ( configobj ) : raise RuntimeError ( 'Cannot...
AstroDrizzle command - line interface
35,625
def _dbg_dump_virtual_outputs ( imgObjList ) : global _fidx tag = 'virtual' log . info ( ( tag + ' ' ) * 7 ) for iii in imgObjList : log . info ( '-' * 80 ) log . info ( tag + ' orig nm: ' + iii . _original_file_name ) log . info ( tag + ' names.data: ' + str ( iii . outputNames [ "data" ] ) ) log . info ( tag + ' ...
dump some helpful information . strictly for debugging
35,626
def getdarkcurrent ( self , chip ) : darkcurrent = 0. try : darkcurrent = self . _image [ self . scienceExt , chip ] . header [ 'MEANDARK' ] except : msg = "#############################################\n" msg += "# #\n" msg += "# Error: #\n" ...
Return the dark current for the WFC3 UVIS detector . This value will be contained within an instrument specific keyword .
35,627
def doUnitConversions ( self ) : _handle = fileutil . openImage ( self . _filename , mode = 'readonly' , memmap = False ) for chip in self . returnAllChips ( extname = self . scienceExt ) : conversionFactor = 1.0 if '/S' in chip . _bunit : conversionFactor = chip . _exptime else : print ( "Input %s[%s,%d] already in un...
WF3 IR data come out in electrons and I imagine the photometry keywords will be calculated as such so no image manipulation needs be done between native and electrons
35,628
def getdarkcurrent ( self , extver ) : darkcurrent = 0. try : darkcurrent = self . _image [ self . scienceExt , extver ] . header [ 'MEANDARK' ] except : str = "#############################################\n" str += "# #\n" str += "# Error: #...
Return the dark current for the ACS detector . This value will be contained within an instrument specific keyword . The value in the image header will be converted to units of electrons .
35,629
def setInstrumentParameters ( self , instrpars ) : pri_header = self . _image [ 0 ] . header if self . _isNotValid ( instrpars [ 'gain' ] , instrpars [ 'gnkeyword' ] ) : instrpars [ 'gnkeyword' ] = None if self . _isNotValid ( instrpars [ 'rdnoise' ] , instrpars [ 'rnkeyword' ] ) : instrpars [ 'rnkeyword' ] = None if s...
Sets the instrument parameters .
35,630
def _sumImages ( self , numarrayObjectList ) : if numarrayObjectList in [ None , [ ] ] : return None tsum = np . zeros ( numarrayObjectList [ 0 ] . shape , dtype = numarrayObjectList [ 0 ] . dtype ) for image in numarrayObjectList : tsum += image return tsum
Sum a list of numarray objects .
35,631
def precompute_sharp_round ( nxk , nyk , xc , yc ) : s4m = np . ones ( ( nyk , nxk ) , dtype = np . int16 ) s4m [ yc , xc ] = 0 s2m = np . ones ( ( nyk , nxk ) , dtype = np . int16 ) s2m [ yc , xc ] = 0 s2m [ yc : nyk , 0 : xc ] = - 1 s2m [ 0 : yc + 1 , xc + 1 : nxk ] = - 1 return s2m , s4m
Pre - computes mask arrays to be used by the sharp_round function for roundness computations based on two - and four - fold symmetries .
35,632
def getMdriztabParameters ( files ) : _fileName = files [ 0 ] _header = fileutil . getHeader ( _fileName ) if 'MDRIZTAB' in _header : _tableName = _header [ 'MDRIZTAB' ] else : raise KeyError ( "No MDRIZTAB found in file " + _fileName ) _tableName = fileutil . osfn ( _tableName ) _filters = fileutil . getFilterNames ( ...
Gets entry in MDRIZTAB where task parameters live . This method returns a record array mapping the selected row .
35,633
def _interpretMdriztabPars ( rec ) : tabdict = { } for indx in range ( len ( rec . array . names ) ) : _name = rec . array . names [ indx ] _format = rec . array . formats [ indx ] _value = rec . field ( _name ) if _name in [ 'shiftfile' , 'mdriztab' ] : continue drizstep_names = [ 'driz_sep_' , 'final_' ] if _name in ...
Collect task parameters from the MDRIZTAB record and update the master parameters list with those values
35,634
def build ( outname , wcsname , refimage , undistort = False , applycoeffs = False , coeffsfile = None , ** wcspars ) : user_wcs_pars = convert_user_pars ( wcspars ) userwcs = wcspars [ 'userwcs' ] if util . is_blank ( refimage ) and not userwcs : print ( 'WARNING: No WCS specified... No WCS created!' ) return customwc...
Core functionality to create a WCS instance from a reference image WCS user supplied parameters or user adjusted reference WCS . The distortion information can either be read in as part of the reference image WCS or given in coeffsfile .
35,635
def create_WCSname ( wcsname ) : if util . is_blank ( wcsname ) : ptime = fileutil . getDate ( ) wcsname = "User_" + ptime return wcsname
Verify that a valid WCSNAME has been provided and if not create a default WCSNAME based on current date .
35,636
def convert_user_pars ( wcspars ) : default_pars = default_user_wcs . copy ( ) for kw in user_hstwcs_pars : default_pars [ user_hstwcs_pars [ kw ] ] = wcspars [ kw ] return default_pars
Convert the parameters provided by the configObj into the corresponding parameters from an HSTWCS object
35,637
def mergewcs ( outwcs , customwcs , wcspars ) : if outwcs . sip is not None : wcslin = stwcs . distortion . utils . undistortWCS ( outwcs ) outwcs . wcs . cd = wcslin . wcs . cd outwcs . wcs . set ( ) outwcs . setOrient ( ) outwcs . setPscale ( ) else : wcslin = outwcs if customwcs is None : if wcspars [ 'crval1' ] is ...
Merge the WCS keywords from user specified values into a full HSTWCS object This function will essentially follow the same algorithm as used by updatehdr only it will use direct calls to updatewcs . Makewcs methods instead of using updatewcs as a whole
35,638
def apply_model ( refwcs ) : if 'ocx10' in refwcs . __dict__ and refwcs . ocx10 is not None : linmat = np . array ( [ [ refwcs . ocx11 , refwcs . ocx10 ] , [ refwcs . ocy11 , refwcs . ocy10 ] ] ) / refwcs . idcscale refwcs . wcs . cd = np . dot ( refwcs . wcs . cd , linmat ) refwcs . wcs . set ( ) refwcs . setOrient ( ...
Apply distortion model to WCS including modifying CD with linear distortion terms
35,639
def replace_model ( refwcs , newcoeffs ) : print ( 'WARNING:' ) print ( ' Replacing existing distortion model with one' ) print ( ' not necessarily matched to the observation!' ) wcslin = stwcs . distortion . utils . undistortWCS ( refwcs ) outwcs = refwcs . deepcopy ( ) outwcs . wcs . cd = wcslin . wcs . cd outw...
Replace the distortion model in a current WCS with a new model Start by creating linear WCS then run
35,640
def undistortWCS ( refwcs ) : wcslin = stwcs . distortion . utils . output_wcs ( [ refwcs ] ) outwcs = stwcs . wcsutil . HSTWCS ( ) outwcs . wcs = wcslin . wcs outwcs . wcs . set ( ) outwcs . setPscale ( ) outwcs . setOrient ( ) outwcs . sip = None outwcs . inst_kw = refwcs . inst_kw for kw in refwcs . inst_kw : outwcs...
Generate an undistorted HSTWCS from an HSTWCS object with a distortion model
35,641
def generate_headerlet ( outwcs , template , wcsname , outname = None ) : siphdr = True if outwcs . sip is None : siphdr = False outwcs_hdr = outwcs . wcs2header ( sip2hdr = siphdr ) outwcs_hdr [ 'NPIX1' ] = outwcs . pixel_shape [ 0 ] outwcs_hdr [ 'NPIX2' ] = outwcs . pixel_shape [ 1 ] if template is not None and siphd...
Create a headerlet based on the updated HSTWCS object
35,642
def qderiv ( array ) : tmpArray = np . zeros ( array . shape , dtype = np . float64 ) outArray = np . zeros ( array . shape , dtype = np . float64 ) ( naxis1 , naxis2 ) = array . shape for y in range ( - 1 , 2 , 2 ) : if y == - 1 : tmpArray [ 0 : ( naxis1 - 1 ) , 1 : ( naxis2 - 1 ) ] = array [ 0 : ( naxis1 - 1 ) , 0 : ...
Take the absolute derivate of an image in memory .
35,643
def get_hstwcs ( filename , hdulist , extnum ) : hdrwcs = wcsutil . HSTWCS ( hdulist , ext = extnum ) hdrwcs . filename = filename hdrwcs . expname = hdulist [ extnum ] . header [ 'expname' ] hdrwcs . extver = hdulist [ extnum ] . header [ 'extver' ] return hdrwcs
Return the HSTWCS object for a given chip .
35,644
def calcNewEdges ( wcs , shape ) : naxis1 = shape [ 1 ] naxis2 = shape [ 0 ] numpix = naxis1 * 2 + naxis2 * 2 border = np . zeros ( shape = ( numpix , 2 ) , dtype = np . float64 ) xmin = 1. xmax = naxis1 ymin = 1. ymax = naxis2 xside = np . arange ( naxis1 ) + xmin yside = np . arange ( naxis2 ) + ymin _range0 = 0 _ran...
This method will compute sky coordinates for all the pixels around the edge of an image AFTER applying the geometry model .
35,645
def removeAllAltWCS ( hdulist , extlist ) : original_logging_level = log . level log . setLevel ( logutil . logging . WARNING ) try : hdr = hdulist [ extlist [ 0 ] ] . header wkeys = altwcs . wcskeys ( hdr ) if ' ' in wkeys : wkeys . remove ( ' ' ) for extn in extlist : for wkey in wkeys : if wkey == 'O' : continue alt...
Removes all alternate WCS solutions from the header
35,646
def restoreDefaultWCS ( imageObjectList , output_wcs ) : if not isinstance ( imageObjectList , list ) : imageObjectList = [ imageObjectList ] output_wcs . restoreWCS ( ) updateImageWCS ( imageObjectList , output_wcs )
Restore WCS information to default values and update imageObject accordingly .
35,647
def _py2round ( x ) : if hasattr ( x , '__iter__' ) : rx = np . empty_like ( x ) m = x >= 0.0 rx [ m ] = np . floor ( x [ m ] + 0.5 ) m = np . logical_not ( m ) rx [ m ] = np . ceil ( x [ m ] - 0.5 ) return rx else : if x >= 0.0 : return np . floor ( x + 0.5 ) else : return np . ceil ( x - 0.5 )
This function returns a rounded up value of the argument similar to Python 2 .
35,648
def convertWCS ( inwcs , drizwcs ) : drizwcs [ 0 ] = inwcs . crpix [ 0 ] drizwcs [ 1 ] = inwcs . crval [ 0 ] drizwcs [ 2 ] = inwcs . crpix [ 1 ] drizwcs [ 3 ] = inwcs . crval [ 1 ] drizwcs [ 4 ] = inwcs . cd [ 0 ] [ 0 ] drizwcs [ 5 ] = inwcs . cd [ 1 ] [ 0 ] drizwcs [ 6 ] = inwcs . cd [ 0 ] [ 1 ] drizwcs [ 7 ] = inwcs ...
Copy WCSObject WCS into Drizzle compatible array .
35,649
def updateWCS ( drizwcs , inwcs ) : crpix = np . array ( [ drizwcs [ 0 ] , drizwcs [ 2 ] ] , dtype = np . float64 ) crval = np . array ( [ drizwcs [ 1 ] , drizwcs [ 3 ] ] , dtype = np . float64 ) cd = np . array ( [ [ drizwcs [ 4 ] , drizwcs [ 6 ] ] , [ drizwcs [ 5 ] , drizwcs [ 7 ] ] ] , dtype = np . float64 ) inwcs ....
Copy output WCS array from Drizzle into WCSObject .
35,650
def readAltWCS ( fobj , ext , wcskey = ' ' , verbose = False ) : if isinstance ( fobj , str ) : fobj = fits . open ( fobj , memmap = False ) hdr = altwcs . _getheader ( fobj , ext ) try : original_logging_level = log . level log . setLevel ( logutil . logging . WARNING ) nwcs = pywcs . WCS ( hdr , fobj = fobj , key = w...
Reads in alternate primary WCS from specified extension .
35,651
def forward ( self , pixx , pixy ) : skyx , skyy = self . input . all_pix2world ( pixx , pixy , self . origin ) result = self . output . wcs_world2pix ( skyx , skyy , self . origin ) return result
Transform the input pixx pixy positions in the input frame to pixel positions in the output frame .
35,652
def backward ( self , pixx , pixy ) : skyx , skyy = self . output . wcs_pix2world ( pixx , pixy , self . origin ) result = self . input . all_world2pix ( skyx , skyy , self . origin ) return result
Transform pixx pixy positions from the output frame back onto their original positions in the input frame .
35,653
def createMask ( input = None , static_sig = 4.0 , group = None , editpars = False , configObj = None , ** inputDict ) : if input is not None : inputDict [ "static_sig" ] = static_sig inputDict [ "group" ] = group inputDict [ "updatewcs" ] = False inputDict [ "input" ] = input else : print >> sys . stderr , "Please sup...
The user can input a list of images if they like to create static masks as well as optional values for static_sig and inputDict .
35,654
def addMember ( self , imagePtr = None ) : numchips = imagePtr . _numchips log . info ( "Computing static mask:\n" ) chips = imagePtr . group if chips is None : chips = imagePtr . getExtensions ( ) for chip in chips : chipid = imagePtr . scienceExt + ',' + str ( chip ) chipimage = imagePtr . getData ( chipid ) signatur...
Combines the input image with the static mask that has the same signature .
35,655
def getMaskArray ( self , signature ) : if signature in self . masklist : mask = self . masklist [ signature ] else : mask = None return mask
Returns the appropriate StaticMask array for the image .
35,656
def getFilename ( self , signature ) : filename = constructFilename ( signature ) if ( fileutil . checkFileExists ( filename ) ) : return filename else : print ( "\nmMask file for " , str ( signature ) , " does not exist on disk" , file = sys . stderr ) return None
Returns the name of the output mask file that should reside on disk for the given signature .
35,657
def close ( self ) : for key in self . masklist . keys ( ) : self . masklist [ key ] = None self . masklist = { }
Deletes all static mask objects .
35,658
def deleteMask ( self , signature ) : if signature in self . masklist : self . masklist [ signature ] = None else : log . warning ( "No matching mask" )
Delete just the mask that matches the signature given .
35,659
def saveToFile ( self , imageObjectList ) : virtual = imageObjectList [ 0 ] . inmemory for key in self . masklist . keys ( ) : filename = self . masknames [ key ] newHDU = fits . PrimaryHDU ( ) newHDU . data = self . masklist [ key ] if virtual : for img in imageObjectList : img . saveVirtualOutputs ( { filename : newH...
Saves the static mask to a file it uses the signatures associated with each mask to contruct the filename for the output mask image .
35,660
def expand_image ( image , shape ) : if ( shape [ 0 ] % image . shape [ 0 ] ) or ( shape [ 1 ] % image . shape [ 1 ] ) : raise ValueError ( "Output shape must be an integer multiple of input " "image shape." ) sx = shape [ 1 ] // image . shape [ 1 ] sy = shape [ 0 ] // image . shape [ 0 ] ox = ( sx - 1.0 ) / ( 2.0 * sx...
Expand image from original shape to requested shape . Output shape must be an integer multiple of input image shape for each axis .
35,661
def bilinear_interp ( data , x , y ) : x = np . asarray ( x ) y = np . asarray ( y ) if x . shape != y . shape : raise ValueError ( "X- and Y-coordinates must have identical shapes." ) out_shape = x . shape out_size = x . size x = x . ravel ( ) y = y . ravel ( ) x0 = np . empty ( out_size , dtype = np . int ) y0 = np ....
Interpolate input data at pixel coordinates x and y .
35,662
def getflat ( self , chip ) : sci_chip = self . _image [ self . scienceExt , chip ] exten = self . errExt + ',' + str ( chip ) lflatfile = fileutil . osfn ( self . _image [ "PRIMARY" ] . header [ 'LFLTFILE' ] ) pflatfile = fileutil . osfn ( self . _image [ "PRIMARY" ] . header [ 'PFLTFILE' ] ) try : handle = fileutil ....
Method for retrieving a detector s flat field . For STIS there are three . This method will return an array the same shape as the image .
35,663
def _assignSignature ( self , chip ) : sci_chip = self . _image [ self . scienceExt , chip ] ny = sci_chip . _naxis1 nx = sci_chip . _naxis2 detnum = sci_chip . detnum instr = self . _instrument sig = ( instr + self . _detector , ( nx , ny ) , int ( detnum ) ) sci_chip . signature = sig
Assign a unique signature for the image based on the instrument detector chip and size this will be used to uniquely identify the appropriate static mask for the image .
35,664
def doUnitConversions ( self ) : for det in range ( 1 , self . _numchips + 1 , 1 ) : chip = self . _image [ self . scienceExt , det ] conversionFactor = self . effGain chip . _gain = self . effGain chip . effGain = self . effGain chip . _conversionFactor = conversionFactor
Convert the data to electrons .
35,665
def drizCR ( input = None , configObj = None , editpars = False , ** inputDict ) : log . debug ( inputDict ) inputDict [ "input" ] = input configObj = util . getDefaultConfigObj ( __taskname__ , configObj , inputDict , loadOnly = ( not editpars ) ) if configObj is None : return if not editpars : run ( configObj )
Look for cosmic rays .
35,666
def createCorrFile ( outfile , arrlist , template ) : if os . path . isfile ( outfile ) : os . remove ( outfile ) print ( "Removing old corr file: '{:s}'" . format ( outfile ) ) with fits . open ( template , memmap = False ) as ftemplate : for arr in arrlist : ftemplate [ arr [ 'sciext' ] ] . data = arr [ 'corrFile' ] ...
Create a _cor file with the same format as the original input image .
35,667
def setDefaults ( configObj = { } ) : paramDict = { 'gain' : 7 , 'grow' : 1 , 'ctegrow' : 0 , 'rn' : 5 , 'snr' : '4.0 3.0' , 'scale' : '0.5 0.4' , 'backg' : 0 , 'expkey' : 'exptime' } if len ( configObj ) > 0 : for key in configObj : paramDict [ key ] = configObj [ key ] return paramDict
Return a dictionary of the default parameters which also been updated with the user overrides .
35,668
def getMdriztabPars ( input ) : filelist , output , ivmlist , oldasndict = processFilenames ( input , None ) try : mdrizdict = mdzhandler . getMdriztabParameters ( filelist ) except KeyError : print ( 'No MDRIZTAB found for "%s". Parameters remain unchanged.' % ( filelist [ 0 ] ) ) mdrizdict = { } return mdrizdict
High - level function for getting the parameters from MDRIZTAB
35,669
def addIVMInputs ( imageObjectList , ivmlist ) : if ivmlist is None : return for img , ivmname in zip ( imageObjectList , ivmlist ) : img . updateIVMName ( ivmname )
Add IVM filenames provided by user to outputNames dictionary for each input imageObject .
35,670
def checkMultipleFiles ( input ) : f , i , o , a = buildFileList ( input ) return len ( f ) > 1
Evaluates the input to determine whether there is 1 or more than 1 valid input file .
35,671
def createImageObjectList ( files , instrpars , group = None , undistort = True , inmemory = False ) : imageObjList = [ ] mtflag = False mt_refimg = None for img in files : image = _getInputImage ( img , group = group ) image . setInstrumentParameters ( instrpars ) image . compute_wcslin ( undistort = undistort ) if 'M...
Returns a list of imageObject instances 1 for each input image in the list of input filenames .
35,672
def _getInputImage ( input , group = None ) : sci_ext = 'SCI' if group in [ None , '' ] : exten = '[sci,1]' phdu = fits . getheader ( input , memmap = False ) else : if group . find ( ',' ) > 0 : grp = group . split ( ',' ) if grp [ 0 ] . isalpha ( ) : grp = ( grp [ 0 ] , int ( grp [ 1 ] ) ) else : grp = int ( grp [ 0 ...
Factory function to return appropriate imageObject class instance
35,673
def processFilenames ( input = None , output = None , infilesOnly = False ) : ivmlist = None oldasndict = None if input is None : print ( "No input files provided to processInput" ) raise ValueError if not isinstance ( input , list ) and ( '_asn' in input or '_asc' in input ) : oldasndict = asnutil . readASNTable ( inp...
Process the input string which contains the input file information and return a filelist output
35,674
def process_input ( input , output = None , ivmlist = None , updatewcs = True , prodonly = False , wcskey = None , ** workinplace ) : newfilelist , ivmlist , output , oldasndict , origflist = buildFileListOrig ( input , output = output , ivmlist = ivmlist , wcskey = wcskey , updatewcs = updatewcs , ** workinplace ) if ...
Create the full input list of filenames after verifying and converting files as needed .
35,675
def _process_input_wcs_single ( fname , wcskey , updatewcs ) : if wcskey in [ '' , ' ' , 'INDEF' , None ] : if updatewcs : uw . updatewcs ( fname , checkfiles = False ) else : numext = fileutil . countExtn ( fname ) extlist = [ ] for extn in range ( 1 , numext + 1 ) : extlist . append ( ( 'SCI' , extn ) ) if wcskey in ...
See docs for _process_input_wcs . This is separated to be spawned in parallel .
35,676
def buildFileList ( input , output = None , ivmlist = None , wcskey = None , updatewcs = True , ** workinplace ) : newfilelist , ivmlist , output , oldasndict , filelist = buildFileListOrig ( input = input , output = output , ivmlist = ivmlist , wcskey = wcskey , updatewcs = updatewcs , ** workinplace ) return newfilel...
Builds a file list which has undergone various instrument - specific checks for input to MultiDrizzle including splitting STIS associations .
35,677
def buildASNList ( rootnames , asnname , check_for_duplicates = True ) : filelist , duplicates = checkForDuplicateInputs ( rootnames ) if check_for_duplicates and duplicates : origasn = changeSuffixinASN ( asnname , 'flt' ) dupasn = changeSuffixinASN ( asnname , 'flc' ) errstr = 'ERROR:\nMultiple valid input files foun...
Return the list of filenames for a given set of rootnames
35,678
def changeSuffixinASN ( asnfile , suffix ) : _new_asn = asnfile . replace ( '_asn.fits' , '_' + suffix + '_asn.fits' ) if os . path . exists ( _new_asn ) : os . remove ( _new_asn ) shutil . copy ( asnfile , _new_asn ) fasn = fits . open ( _new_asn , mode = 'update' , memmap = False ) fasn [ 0 ] . header [ 'DUPCHECK' ] ...
Create a copy of the original asn file and change the name of all members to include the suffix .
35,679
def resetDQBits ( imageObjectList , cr_bits_value = 4096 ) : if cr_bits_value > 0 : for img in imageObjectList : for chip in range ( 1 , img . _numchips + 1 , 1 ) : sci_chip = img . _image [ img . scienceExt , chip ] resetbits . reset_dq_bits ( sci_chip . dqfile , cr_bits_value , extver = chip , extname = sci_chip . dq...
Reset the CR bit in each input image s DQ array
35,680
def update_member_names ( oldasndict , pydr_input ) : omembers = oldasndict [ 'members' ] . copy ( ) nmembers = { } translated_names = [ f . split ( '.fits' ) [ 0 ] for f in pydr_input ] newkeys = [ fileutil . buildNewRootname ( file ) for file in pydr_input ] keys_map = list ( zip ( newkeys , pydr_input ) ) for okey ,...
Update names in a member dictionary .
35,681
def manageInputCopies ( filelist , ** workinplace ) : workingdir = os . getcwd ( ) origdir = os . path . join ( workingdir , 'OrIg_files' ) if workinplace [ 'overwrite' ] or workinplace [ 'preserve' ] : if not os . path . exists ( origdir ) : os . mkdir ( origdir ) printMsg = True for fname in filelist : copymade = Fal...
Creates copies of all input images in a sub - directory .
35,682
def _managePsets ( configobj , section_name , task_name , iparsobj = None , input_dict = None ) : configobj [ section_name ] = { } iparsobj_cfg = teal . load ( task_name ) 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...
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 .
35,683
def edit_imagefindpars ( ) : teal . teal ( imagefindpars . __taskname__ , returnAs = None , autoClose = True , loadOnly = False , canExecute = False )
Allows the user to edit the imagefindpars configObj in a TEAL GUI
35,684
def edit_refimagefindpars ( ) : teal . teal ( refimagefindpars . __taskname__ , returnAs = None , autoClose = True , loadOnly = False , canExecute = False )
Allows the user to edit the refimagefindpars configObj in a TEAL GUI
35,685
def find_d2ifile ( flist , detector ) : d2ifile = None for f in flist : fdet = fits . getval ( f , 'detector' , memmap = False ) if fdet == detector : d2ifile = f return d2ifile
Search a list of files for one that matches the detector specified .
35,686
def find_npolfile ( flist , detector , filters ) : npolfile = None for f in flist : fdet = fits . getval ( f , 'detector' , memmap = False ) if fdet == detector : filt1 = fits . getval ( f , 'filter1' , memmap = False ) filt2 = fits . getval ( f , 'filter2' , memmap = False ) fdate = fits . getval ( f , 'date' , memmap...
Search a list of files for one that matches the configuration of detector and filters used .
35,687
def run ( configobj = None , editpars = False ) : 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' ] )
Teal interface for running this code .
35,688
def retrieve_observation ( obsid , suffix = [ 'FLC' ] , archive = False , clobber = False ) : local_files = [ ] obsTable = Observations . query_criteria ( obs_id = obsid , obstype = 'all' ) if len ( obsTable ) == 0 : log . info ( "WARNING: Query for {} returned NO RESULTS!" . format ( obsid ) ) return local_files dpobs...
Simple interface for retrieving an observation from the MAST archive
35,689
def replace ( input , ** pars ) : pixvalue = pars . get ( 'pixvalue' , np . nan ) if pixvalue is None : pixvalue = np . nan newvalue = pars . get ( 'newvalue' , 0.0 ) ext = pars . get ( 'ext' , None ) if ext in [ '' , ' ' , 'None' , None ] : ext = None files = parseinput . parseinput ( input ) [ 0 ] for f in files : fi...
Replace pixels in input that have a value of pixvalue with a value given by newvalue .
35,690
def extract_input_filenames ( drzfile ) : data_kws = fits . getval ( drzfile , 'd*data' , ext = 0 , memmap = False ) if len ( data_kws ) == 0 : return None fnames = [ ] for kw in data_kws . cards : f = kw . value . split ( '[' ) [ 0 ] if f not in fnames : fnames . append ( f ) return fnames
Generate a list of filenames from a drizzled image s header
35,691
def determine_orig_wcsname ( header , wnames , wkeys ) : orig_wcsname = None orig_key = None if orig_wcsname is None : for k , w in wnames . items ( ) : if w [ : 4 ] == 'IDC_' : orig_wcsname = w orig_key = k break if orig_wcsname is None : if len ( wnames ) > 1 : orig_key = wkeys [ - 2 ] orig_wcsname = wnames [ orig_ke...
Determine the name of the original unmodified WCS solution
35,692
def parse_skypos ( ra , dec ) : rval = make_val_float ( ra ) dval = make_val_float ( dec ) if rval is None : rval , dval = radec_hmstodd ( ra , dec ) return rval , dval
Function to parse RA and Dec input values and turn them into decimal degrees
35,693
def radec_hmstodd ( ra , dec ) : hmstrans = string . maketrans ( string . ascii_letters , ' ' * len ( string . ascii_letters ) ) if isinstance ( ra , list ) : rastr = ':' . join ( ra ) elif isinstance ( ra , float ) : rastr = None pos_ra = ra elif ra . find ( ':' ) < 0 : rastr = ra . translate ( hmstrans ) . strip ( ) ...
Function to convert HMS values into decimal degrees .
35,694
def parse_exclusions ( exclusions ) : fname = fileutil . osfn ( exclusions ) if os . path . exists ( fname ) : with open ( fname ) as f : flines = f . readlines ( ) else : print ( 'No valid exclusions file "' , fname , '" could be found!' ) print ( 'Skipping application of exclusions files to source catalogs.' ) return...
Read in exclusion definitions from file named by exclusions and return a list of positions and distances
35,695
def parse_colname ( colname ) : if isinstance ( colname , list ) : cname = '' for c in colname : cname += str ( c ) + ',' cname = cname . rstrip ( ',' ) elif isinstance ( colname , int ) or colname . isdigit ( ) : cname = str ( colname ) else : cname = colname if 'c' in cname [ 0 ] : cname = cname . replace ( 'c' , '' ...
Common function to interpret input column names provided by the user .
35,696
def readcols ( infile , cols = None ) : if _is_str_none ( infile ) is None : return None if infile . endswith ( '.fits' ) : outarr = read_FITS_cols ( infile , cols = cols ) else : outarr = read_ASCII_cols ( infile , cols = cols ) return outarr
Function which reads specified columns from either FITS tables or ASCII files
35,697
def read_FITS_cols ( infile , cols = None ) : with fits . open ( infile , memmap = False ) as ftab : extnum = 0 extfound = False for extn in ftab : if 'tfields' in extn . header : extfound = True break extnum += 1 if not extfound : print ( 'ERROR: No catalog table found in ' , infile ) raise ValueError if _is_str_none ...
Read columns from FITS table
35,698
def read_ASCII_cols ( infile , cols = [ 1 , 2 , 3 ] ) : coldict = { } with open ( infile , 'r' ) as f : flines = f . readlines ( ) for l in flines : if l [ 0 ] . lstrip ( ) == '#' or l . lstrip ( ) == '' : continue else : coldict = { str ( i + 1 ) : i for i , _ in enumerate ( l . split ( ) ) } break numcols = len ( col...
Interpret input ASCII file to return arrays for specified columns .
35,699
def write_shiftfile ( image_list , filename , outwcs = 'tweak_wcs.fits' ) : rows = '' nrows = 0 for img in image_list : row = img . get_shiftfile_row ( ) if row is not None : rows += row nrows += 1 if nrows == 0 : return if os . path . exists ( outwcs ) : os . remove ( outwcs ) p = fits . HDUList ( ) p . append ( fits ...
Write out a shiftfile for a given list of input Image class objects