code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
# Sort the points lexicographically (tuples are compared lexicographically). # Remove duplicates to detect the case we have just one unique point. points = sorted(set(points)) # Boring case: no points or a single point, possibly repeated multiple times. if len(points) <= 1: return poi...
def convex_hull(points)
Computes the convex hull of a set of 2D points. Implements `Andrew's monotone chain algorithm <http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain>`_. The algorithm has O(n log n) complexity. Credit: `<http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Con...
1.721629
1.726715
0.997054
print("Computing initial guess for X and Y shifts...") # create ZP matrix zpmat = _xy_2dhist(imgxy, refxy, r=searchrad) nonzeros = np.count_nonzero(zpmat) if nonzeros == 0: # no matches within search radius. Return (0, 0): print("WARNING: No matches found within a search radiu...
def _estimate_2dhist_shift(imgxy, refxy, searchrad=3.0)
Create a 2D matrix-histogram which contains the delta between each XY position and each UV position. Then estimate initial offset between catalogs.
3.388013
3.412613
0.992791
if self._im.closed: if not self._dq.closed: self._dq.release() assert(self._dq.closed) fi = FileExtMaskInfo(clobber=False, doNotOpenDQ=not openDQ, im_fmode=self.open_mode) ...
def openFile(self, openDQ=False)
Open file and set up filehandle for image file
7.777596
7.378477
1.054092
wcslist = [] for chip in self.chip_catalogs: wcslist.append(self.chip_catalogs[chip]['wcs']) return wcslist
def get_wcs(self)
Helper method to return a list of all the input WCS objects associated with this image.
4.085604
3.755383
1.087932
self.all_radec = None self.all_radec_orig = None ralist = [] declist = [] fluxlist = [] idlist = [] for scichip in self.chip_catalogs: skycat = self.chip_catalogs[scichip]['catalog'].radec xycat = self.chip_catalogs[scichip]['catal...
def buildSkyCatalog(self)
Convert sky catalog for all chips into a single catalog for the entire field-of-view of this image.
2.350483
2.308245
1.018299
self.default_refWCS = None if self.use_wcs: wcslist = [] for scichip in self.chip_catalogs: wcslist.append(self.chip_catalogs[scichip]['wcs']) self.default_refWCS = utils.output_wcs(wcslist)
def buildDefaultRefWCS(self)
Generate a default reference WCS for this image.
4.41727
4.31918
1.02271
if not isinstance(ref_wcs, pywcs.WCS): print(textutil.textbox('Reference WCS not a valid HSTWCS object'), file=sys.stderr) raise ValueError # Need to concatenate catalogs from each input if self.outxy is None or force: outxy = ref_wc...
def transformToRef(self,ref_wcs,force=False)
Transform sky coords from ALL chips into X,Y coords in reference WCS.
5.148005
5.113509
1.006746
if len(self.all_radec_orig[2].nonzero()[0]) == 0: warn_str = "Source catalog NOT trimmed by flux/mag. No fluxes read in for sources!" print('\nWARNING: ',warn_str,'\n') log.warning(warn_str) return clip_catalog = False clip_prefix = '' ...
def sortSkyCatalog(self)
Sort and clip the source catalog based on the flux range specified by the user. It keeps a copy of the original full list in order to support iteration.
2.538644
2.496267
1.016976
# Insure filehandle is open and available... self.openFile() pars = kwargs.copy() rms_pars = self.fit['rms_keys'] str_kw = ['descrip','history','author','hdrfile'] for kw in str_kw: if pars[kw] == '': pars[kw] = None # Call function with pr...
def writeHeaderlet(self,**kwargs)
Write and/or attach a headerlet based on update to PRIMARY WCS
5.548428
5.448035
1.018427
if self.all_radec is None: return ralist = self.all_radec[0]#.tolist() declist = self.all_radec[1]#.tolist() f = open(filename,'w') f.write("#Sky positions for: "+self.name+'\n') f.write("#RA Dec\n") f.write("#(deg) (deg)\n") ...
def write_skycatalog(self,filename)
Write out the all_radec catalog for this image to a file.
2.504605
2.292807
1.092375
catstr = self.name+' ' if 'input_xy' in self.catalog_names: for xycat in self.catalog_names['input_xy']: catstr += ' '+xycat return catstr + '\n'
def get_xy_catnames(self)
Return a string with the names of input_xy catalog names
5.89003
4.060413
1.450599
f = open(filename,'w') f.write("#Pixel positions for: "+self.name+'\n') f.write("#X Y\n") f.write("#(pix) (pix)\n") for i in range(self.all_radec[0].shape[0]): f.write('%f %f\n'%(self.outxy[i,0],self.outxy[i,1])) f.close()
def write_outxy(self,filename)
Write out the output(transformed) XY catalog for this image to a file.
3.350318
3.191676
1.049705
if self.fit is not None: rowstr = '%s %0.6f %0.6f %0.6f %0.6f %0.6f %0.6f\n'%( self.name,self.fit['offset'][0],self.fit['offset'][1], self.fit['rot'],self.fit['scale'][0], self.fit['rms'][0],self.fit['rms'][1]) ...
def get_shiftfile_row(self)
Return the information for a shiftfile for this image to provide compatability with the IRAF-based MultiDrizzle.
3.167439
3.119689
1.015306
#TODO: add cleaning of mask files, *if* created ... for f in self.catalog_names: if 'match' in f: if os.path.exists(self.catalog_names[f]): log.info('Deleting intermediate match file: %s'% self.catalog_names[f]) ...
def clean(self)
Remove intermediate files created.
4.802206
4.357256
1.102117
f = open(filename,'w') f.write("#Sky positions for cumulative reference catalog. Initial catalog from: "+self.name+'\n') header1 = "#RA Dec" header2 = "#(deg) (deg)" if show_flux: header1 += " Flux" header2 += " (counts)" ...
def write_skycatalog(self, filename, show_flux=False, show_id=False)
Write out the all_radec catalog for this image to a file.
2.85332
2.797926
1.019798
if 'refxyunits' in self.pars and self.pars['refxyunits'] == 'pixels': log.info('Creating RA/Dec positions for reference sources...') self.outxy = np.column_stack([self.all_radec[0][:,np.newaxis],self.all_radec[1][:,np.newaxis]]) skypos = self.wcs.wcs_pix2world(self.a...
def transformToRef(self)
Transform reference catalog sky positions (self.all_radec) to reference tangent plane (self.wcs) to create output X,Y positions.
2.993905
2.571261
1.164372
if not util.is_blank(self.catalog.catname) and os.path.exists(self.catalog.catname): os.remove(self.catalog.catname)
def clean(self)
Remove intermediate files created
4.926157
4.757232
1.035509
if self._image is None: return # mcara: I think the code below is not necessary but in order to # preserve the same functionality as the code removed below, # I make an empty copy of the image object: empty_image = fits.HDUList() for u ...
def close(self)
Close the object nicely and release all the data arrays from memory YOU CANT GET IT BACK, the pointers and data are gone so use the getData method to get the data array returned for future use. You can use putData to reattach a new data array to the imageObject.
8.045906
7.680976
1.047511
clean_files = ['blotImage','crmaskImage','finalMask', 'staticMask','singleDrizMask','outSky', 'outSContext','outSWeight','outSingle', 'outMedian','dqmask','tmpmask', 'skyMatchMask'] log.info('Removi...
def clean(self)
Deletes intermediate products generated for this imageObject.
13.556894
11.73851
1.154908
if exten.lower().find('sci') > -1: # For SCI extensions, the current file will have the data fname = self._filename else: # otherwise, the data being requested may need to come from a # separate file, as is the case with WFPC2 DQ data. ...
def getData(self,exten=None)
Return just the data array from the specified extension fileutil is used instead of fits to account for non- FITS input images. openImage returns a fits object.
6.102051
5.806983
1.050813
_image=fileutil.openImage(self._filename, clobber=False, memmap=False) _header=fileutil.getExtn(_image,extn=exten).header _image.close() del _image return _header
def getHeader(self,exten=None)
Return just the specified header extension fileutil is used instead of fits to account for non-FITS input images. openImage returns a fits object.
6.353606
4.681429
1.357194
_extnum=self._interpretExten(exten) fimg = fileutil.openImage(self._filename, mode='update', memmap=False) fimg[_extnum].data = data fimg[_extnum].header = self._image[_extnum].header fimg.close()
def updateData(self,exten,data)
Write out updated data and header to the original input file for this object.
7.362586
5.908292
1.246145
if data is None: log.warning("No data supplied") else: extnum = _interpretExten(exten) ext = self._image[extnum] # update the bitpix to the current datatype, this aint fancy and # ignores bscale ext.header['BITPIX'] = _NUM...
def putData(self,data=None,exten=None)
Now that we are removing the data from the object to save memory, we need something that cleanly puts the data array back into the object so that we can write out everything together using something like fits.writeto....this method is an attempt to make sure that when yo...
9.583224
7.146739
1.340923
extensions = self._findExtnames(extname=extname,exclude=exclude) for i in range(1,self._nextend+1,1): if hasattr(self._image[i],'_extension') and \ "IMAGE" in self._image[i]._extension: extver = self._image[i].header['extver'] if (se...
def getAllData(self,extname=None,exclude=None)
This function is meant to make it easier to attach ALL the data extensions of the image object so that we can write out copies of the original image nicer. If no extname is given, the it retrieves all data from the original file and attaches it. Otherwise, give the name ...
5.914876
5.912988
1.000319
extensions = self._findExtnames(extname=extname,exclude=exclude) chiplist = [] for i in range(1,self._nextend+1,1): if 'extver' in self._image[i].header: extver = self._image[i].header['extver'] else: extver = 1 if hasa...
def returnAllChips(self,extname=None,exclude=None)
Returns a list containing all the chips which match the extname given minus those specified for exclusion (if any).
4.493784
4.477063
1.003735
#make a list of the available extension names for the object extensions=[] if extname is not None: if not isinstance(extname,list): extname=[extname] for extn in extname: extensions.append(extn.upper()) else: #restore all the exten...
def _findExtnames(self, extname=None, exclude=None)
This method builds a list of all extensions which have 'EXTNAME'==extname and do not include any extensions with 'EXTNAME'==exclude, if any are specified for exclusion at all.
4.43012
4.380999
1.011212
extnum = None extname = extname.upper() if not self._isSimpleFits: for ext in self._image: if (hasattr(ext,'_extension') and 'IMAGE' in ext._extension and (ext.extname == extname) and (ext.extver == extver)): extnum = ...
def findExtNum(self, extname=None, extver=1)
Find the extension number of the give extname and extver.
5.006927
4.767971
1.050117
extname=self._image[self.scienceExt,chip].header["EXTNAME"].lower() extver=self._image[self.scienceExt,chip].header["EXTVER"] expname = self._rootname # record extension-based name to reflect what extension a mask file corresponds to self._image[self.scienceExt,chip].ro...
def _assignRootname(self, chip)
Assign a unique rootname for the image based in the expname.
6.005898
5.54127
1.083849
# Define FITS output filenames for intermediate products # Build names based on final DRIZZLE output name # where 'output' normally would have been created # by 'process_input()' # outFinal = rootname+suffix+'.fits' outSci = rootname+suffix+'_sci.fits'...
def _setOutputNames(self,rootname,suffix='_drz')
Define the default output filenames for drizzle products, these are based on the original rootname of the image filename should be just 1 filename, so call this in a loop for chip names contained inside a file.
4.668521
4.611894
1.012279
self.virtualOutputs = {} for product in self.outputNames: self.virtualOutputs[product] = None
def _initVirtualOutputs(self)
Sets up the structure to hold all the output data arrays for this image in memory.
5.519304
4.988256
1.10646
if not self.inmemory: return for outname in outdict: self.virtualOutputs[outname] = outdict[outname]
def saveVirtualOutputs(self,outdict)
Assign in-memory versions of generated products for this ``imageObject`` based on dictionary 'outdict'.
4.079978
3.711721
1.099215
val = self.outputNames[name] if self.inmemory: # if inmemory was turned on... # return virtualOutput object saved with that name val = self.virtualOutputs[val] return val
def getOutputName(self,name)
Return the name of the file or PyFITS object associated with that name, depending on the setting of self.inmemory.
14.749196
9.245404
1.5953
outputvals = self.outputValues outputvals['output'] = output_wcs.outputNames['outFinal'] outputvals['outnx'], outputvals['outny'] = output_wcs.wcs.pixel_shape outputvals['texptime'] = output_wcs._exptime outputvals['texpstart'] = output_wcs._expstart outputvals[...
def updateOutputValues(self,output_wcs)
Copy info from output WCSObject into outputnames for each chip for use in creating outputimage object.
3.674964
3.502348
1.049286
self.createContext = contextpar if not contextpar: log.info('No context image will be created for %s' % self._filename) self.outputNames['outContext'] = None
def updateContextImage(self, contextpar)
Reset the name of the context image to `None` if parameter ``context`` is `False`.
10.630541
9.36223
1.135471
dqfile = None dq_suffix=None if(self.maskExt is not None): for hdu in self._image: # Look for DQ extension in input file if 'extname' in hdu.header and hdu.header['extname'].lower() == self.maskExt.lower(): dqfile = self._f...
def find_DQ_extension(self)
Return the suffix for the data quality extension and the name of the file which that DQ extension should be read from.
4.072658
3.710251
1.097677
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
def getKeywordList(self, kw)
Return lists of all attribute values for all active chips in the ``imageObject``.
7.852935
6.811547
1.152886
sci_chip = self._image[self.scienceExt, chip] # The keyword for ACS flat fields in the primary header of the flt # file is pfltfile. This flat file is already in the required # units of electrons. # The use of fileutil.osfn interprets any environment variable, such as ...
def getflat(self, chip)
Method for retrieving a detector's flat field. Returns ------- flat: array This method will return an array the same shape as the image in **units of electrons**.
4.410247
4.325498
1.019593
sci_chip = self._image[self.scienceExt,chip] return np.ones(sci_chip.image_shape,dtype=sci_chip.image_dtype) * sci_chip._rdnoise
def getReadNoiseImage(self, chip)
Notes ===== Method for returning the readnoise image of a detector (in electrons). The method will return an array of the same shape as the image. :units: electrons
8.701744
8.850444
0.983199
sci_chip = self._image[self.scienceExt,chip] if sci_chip._wtscl_par == 'expsq': wtscl = sci_chip._exptime*sci_chip._exptime else: wtscl = sci_chip._exptime return np.ones(sci_chip.image_shape,dtype=sci_chip.image_dtype)*wtscl
def getexptimeimg(self,chip)
Notes ===== Return an array representing the exposure time per pixel for the detector. This method will be overloaded for IR detectors which have their own EXP arrays, namely, WFC3/IR and NICMOS images. :units: None Returns ======= exptimeimg :...
6.676717
7.577618
0.88111
sci_chip = self._image[self.scienceExt,chip] return np.ones(sci_chip.image_shape,dtype=sci_chip.image_dtype)*sci_chip.darkcurrent
def getdarkimg(self,chip)
Notes ===== Return an array representing the dark image for the detector. The method will return an array of the same shape as the image. :units: electrons
11.054105
10.223405
1.081255
sci_chip = self._image[self.scienceExt,chip] return np.ones(sci_chip.image_shape,dtype=sci_chip.image_dtype)*sci_chip.subtractedSky
def getskyimg(self,chip)
Notes ===== Return an array representing the sky image for the detector. The value of the sky is what would actually be subtracted from the exposure by the skysub step. :units: electrons
10.555392
10.198093
1.035036
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): ...
def getExtensions(self, extname='SCI', section=None)
Return the list of EXTVER values for extensions with name specified in extname.
2.99817
2.73849
1.094826
count=0 #simple fits image if (self._image['PRIMARY'].header["EXTEND"]): for i,hdu in enumerate(self._image): if i > 0: hduExtname = False if 'EXTNAME' in hdu.header: self._image[i].extnum=i ...
def _countEXT(self,extname="SCI")
Count the number of extensions in the file with the given name (``EXTNAME``).
3.169939
3.291926
0.962943
dqarr = self.getData(exten=self.maskExt+','+str(chip)) dqmask = buildmask.buildMask(dqarr,bits) if write: phdu = fits.PrimaryHDU(data=dqmask,header=self._image[self.maskExt,chip].header) dqmask_name = self._image[self.scienceExt,chip].dqrootname+'_dqmask.fits' ...
def buildMask(self,chip,bits=0,write=False)
Build masks as specified in the user parameters found in the configObj object. We should overload this function in the instrument specific implementations so that we can add other stuff to the badpixel mask? Like vignetting areas and chip boundries in nicmos which are camera dep...
4.134411
3.976192
1.039792
log.info("Applying EXPTIME weighting to DQ mask for chip %s" % chip) #exparr = self.getexptimeimg(chip) exparr = self._image[self.scienceExt,chip]._exptime expmask = exparr*dqarr return expmask.astype(np.float32)
def buildEXPmask(self, chip, dqarr)
Builds a weight mask from an input DQ array and the exposure time per pixel for this chip.
8.736843
7.391082
1.182079
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) #Parse the input file name to get the extension we are working on extn = "IVM,{...
def buildIVMmask(self ,chip, dqarr, scale)
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.
5.418044
5.166123
1.048764
sci_chip = self._image[self.scienceExt,chip] # Set default value in case of error, or lack of ERR array errmask = dqarr if self.errExt is not None: try: # Attempt to open the ERR image. err = self.getData(exten=self.errExt+','+str(ch...
def buildERRmask(self,chip,dqarr,scale)
Builds a weight mask from an input DQ array and an ERR array associated with the input image.
6.076285
5.931678
1.024379
for chip in range(1,self._numchips+1,1): sci_chip = self._image[self.scienceExt,chip] ref_chip = image._image[image.scienceExt,chip] # Do we want to keep track of original WCS or not? No reason now... sci_chip.wcs = ref_chip.wcs.copy()
def set_mt_wcs(self, image)
Reset the WCS for this image based on the WCS information from another imageObject.
7.382182
6.517708
1.132635
sci_chip = self._image[self.scienceExt,chip] exptime = 1 #sci_chip._exptime _parval = 'unity' if wtscl_par is not None: if type(wtscl_par) == type(''): if not wtscl_par.isdigit(): # String passed in as value, check for 'exptime' o...
def set_wtscl(self, chip, wtscl_par)
Sets the value of the wt_scl parameter as needed for drizzling.
3.613101
3.533178
1.022621
if isinstance(value, str) and value in ['None', '', ' ', 'INDEF']: value = None if value and (keyword is not None and keyword.strip() != ''): exceptionMessage = "ERROR: Your input is ambiguous! Please specify either a value or a keyword.\n You specifed both " + str(va...
def getInstrParameter(self, value, header, keyword)
This method gets a instrument parameter from a pair of task parameters: a value, and a header keyword. The default behavior is: - if the value and header keyword are given, raise an exception. - if the value is given, use it. - if the value is blank and...
4.666164
4.598581
1.014696
_list = '' for _kw in keyword.split(','): if _kw in header: _list = _list + ',' + str(header[_kw]) else: return None return self._averageFromList(_list)
def _averageFromHeader(self, header, keyword)
Averages out values taken from header. The keywords where to read values from are passed as a comma-separated list.
4.093936
3.529355
1.159967
_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
def _averageFromList(self, param)
Averages out values passed as a comma-separated list, disregarding the zero-valued entries.
2.691044
2.533114
1.062346
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 = Non...
def compute_wcslin(self,undistort=True)
Compute the undistorted WCS based solely on the known distortion model information associated with the WCS.
5.77054
5.789257
0.996767
# Determine output value of BUNITS # and make sure it is not specified as 'ergs/cm...' 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'] ...
def set_units(self,chip)
Define units for this image.
5.720454
5.407879
1.0578
if not blend: newhdrs = blendheaders.getSingleTemplate(fnames[0]) newtab = None else: # apply rules to create final version of headers, plus table newhdrs, newtab = blendheaders.get_blended_headers(inputs=fnames) cleanTemplates(newhdrs[1],newhdrs[2],newhdrs[3]) re...
def getTemplates(fnames, blend=True)
Process all headers to produce a set of combined headers that follows the rules defined by each instrument.
8.870178
8.094201
1.095868
wname = wcs.wcs.name if not single: wname = 'DRZWCS' # Update WCS Keywords based on PyDrizzle product's value # since 'drizzle' itself doesn't update that keyword. hdr['WCSNAME'] = wname hdr.set('VAFACTOR', value=1.0, after=after) hdr.set('ORIENTAT', value=wcs.orientat, after=a...
def addWCSKeywords(wcs,hdr,blot=False,single=False,after=None)
Update input header 'hdr' with WCS keywords.
2.732857
2.726318
1.002399
outname,outextn = fileutil.parseFilename(output) outextname,outextver = fileutil.parseExtn(outextn) if fileutil.findFile(outname): if clobber: log.info('Deleting previous output product: %s' % outname) fileutil.removeFile(outname) else: log.warning(...
def writeSingleFITS(data,wcs,output,template,clobber=True,verbose=True)
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.
4.078175
4.138993
0.985306
_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'])
def writeDrizKeywords(hdr,imgnum,drizdict)
Write basic drizzle-related keywords out to image header as a record of the processing performed to create the image The dictionary 'drizdict' will contain the keywords and values to be written out to the header.
3.275932
3.744884
0.874775
# start by looping through the full templates kw_list = None last_kw = None for extn in self.fullhdrs: if keyword in extn: #indx = extn.ascard.index_of(keyword) indx = extn.index(keyword) kw_list = list(extn.keys())[:in...
def find_kwupdate_location(self,hdr,keyword)
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 remove...
4.987636
4.788076
1.041678
# Extract some global information for the keywords _geom = 'User parameters' _imgnum = 0 for pl in self.parlist: # Start by building up the keyword prefix based # on the image number for the chip #_keyprefix = 'D%03d'%_imgnum _i...
def addDrizKeywords(self,hdr,versions)
Add drizzle parameter keywords to header.
4.339401
4.277949
1.014365
fit = fit_shifts(xy,uv) if nclip is None: nclip = 0 # define index to initially include all points 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() # redefine what pixel...
def iter_fit_shifts(xy,uv,nclip=3,sigma=3.0)
Perform an iterative-fit with 'nclip' iterations
4.2011
4.139939
1.014773
if mode not in ['general', 'shift', 'rscale']: mode = 'rscale' if not isinstance(xy,np.ndarray): # cast input list as numpy ndarray for fitting xy = np.array(xy) if not isinstance(uv,np.ndarray): # cast input list as numpy ndarray for fitting uv = np.array(uv) ...
def fit_all(xy,uv,mode='rscale',center=None,verbose=True)
Performs an 'rscale' fit between matched lists of pixel positions xy and uv
2.21262
2.177199
1.016269
diff_pts = xy - uv Pcoeffs = np.array([1.0,0.0,diff_pts[:,0].mean(dtype=np.float64)]) Qcoeffs = np.array([0.0,1.0,diff_pts[:,1].mean(dtype=np.float64)]) fit = build_fit(Pcoeffs, Qcoeffs, 'shift') resids = diff_pts - fit['offset'] fit['resids'] = resids fit['rms'] = resids.std(axis=0) ...
def fit_shifts(xy, uv)
Performs a simple fit for the shift only between matched lists of positions 'xy' and 'uv'. Output: (same as for fit_arrays) ================================= DEVELOPMENT NOTE: Checks need to be put in place to verify that enough objects are available for a fit. ...
3.316549
3.383902
0.980096
# Set up products used for computing the fit gxy = uv.astype(ndfloat128) guv = xy.astype(ndfloat128) Sx = gxy[:,0].sum() Sy = gxy[:,1].sum() Su = guv[:,0].sum() Sv = guv[:,1].sum() Sux = np.dot(guv[:,0], gxy[:,0]) Svx = np.dot(guv[:,1], gxy[:,0]) Suy = np.dot(guv[:,0], gxy[...
def fit_general(xy, uv)
Performs a simple fit for the shift only between matched lists of positions 'xy' and 'uv'. Output: (same as for fit_arrays) ================================= DEVELOPMENT NOTE: Checks need to be put in place to verify that enough objects are available for a fit. ...
2.807845
2.84088
0.988372
if not isinstance(xy,np.ndarray): # cast input list as numpy ndarray for fitting xy = np.array(xy) if not isinstance(uv,np.ndarray): # cast input list as numpy ndarray for fitting uv = np.array(uv) # Set up products used for computing the fit Sx = xy[:,0].sum() ...
def fit_arrays(uv, xy)
Performs a generalized fit between matched lists of positions given by the 2 column arrays xy and uv. This function fits for translation, rotation, and scale changes between 'xy' and 'uv', allowing for different scales and orientations for X and Y axes. ========================...
2.695827
2.616877
1.03017
_theta = np.deg2rad(coeffs[1]) _mrot = np.zeros(shape=(2,2),dtype=np.float64) _mrot[0] = (np.cos(_theta),np.sin(_theta)) _mrot[1] = (-np.sin(_theta),np.cos(_theta)) new_pos = (np.dot(xy,_mrot)/coeffs[2][0]) + coeffs[0] return new_pos
def apply_old_coeffs(xy,coeffs)
Apply the offset/shift/rot values from a linear fit to an array of x,y positions.
2.964115
3.157636
0.938713
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
def apply_fit(xy,coeffs)
Apply the coefficients from a linear fit to an array of x,y positions. The coeffs come from the 'coeffs' member of the 'fit_arrays()' output.
1.757097
2.103438
0.835345
print('FIT coeffs: ',fit['coeffs']) xn,yn = apply_fit(uv,fit['coeffs']) resids = xy - np.transpose([xn,yn]) return resids
def compute_resids(xy,uv,fit)
Compute the residuals based on fit and input arrays to the fit
5.619715
6.401985
0.877808
# 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"-defau...
def AstroDrizzle(input=None, mdriztab=False, editpars=False, configobj=None, wcsmap=None, **input_dict)
AstroDrizzle command-line interface
6.409694
6.370564
1.006142
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+' names.orig: '+str(iii.outputNames["origFilename...
def _dbg_dump_virtual_outputs(imgObjList)
dump some helpful information. strictly for debugging
3.628543
3.643831
0.995805
darkcurrent = 0. try: darkcurrent = self._image[self.scienceExt, chip].header['MEANDARK'] except: msg = "#############################################\n" msg += "# #\n" msg += "# Error: ...
def getdarkcurrent(self,chip)
Return the dark current for the WFC3 UVIS detector. This value will be contained within an instrument specific keyword. Returns ------- darkcurrent: float The dark current value with **units of electrons**.
3.763229
3.715998
1.01271
# Image information _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 ...
def doUnitConversions(self)
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
10.691883
9.321155
1.147056
sci_chip = self._image[self.scienceExt,chip] # First attempt to get the dark image specified by the "DARKFILE" # keyword in the primary keyword of the science data. try: filename = self.header["DARKFILE"] handle = fileutil.openImage(filename, mode='reado...
def getdarkimg(self,chip)
Return an array representing the dark image for the detector. Returns ------- dark: array Dark image array in the same shape as the input image with **units of cps**
6.231945
6.509984
0.95729
sci_chip = self._image[self.scienceExt,chip] skyimg = np.ones(sci_chip.image_shape,dtype=sci_chip.image_dtype)*sci_chip.subtractedSky if sci_chip._conversionFactor != 1.0: # If units are not already ELECTRONS skyimg *= self.getexptimeimg(chip) return skyimg
def getskyimg(self,chip)
Notes ===== Return an array representing the sky image for the detector. The value of the sky is what would actually be subtracted from the exposure by the skysub step. :units: electrons
9.571353
8.949107
1.069532
darkcurrent=0. try: darkcurrent = self._image[self.scienceExt,extver].header['MEANDARK'] except: str = "#############################################\n" str += "# #\n" str += "# Error: ...
def getdarkcurrent(self,extver)
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. Returns ------- darkcurrent: float Dark current value for the ACS detecto...
3.807354
3.718319
1.023945
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 self._isNotValid (instr...
def setInstrumentParameters(self,instrpars)
Sets the instrument parameters.
4.326445
4.33398
0.998261
if numarrayObjectList in [None, []]: return None tsum = np.zeros(numarrayObjectList[0].shape, dtype=numarrayObjectList[0].dtype) for image in numarrayObjectList: tsum += image return tsum
def _sumImages(self,numarrayObjectList)
Sum a list of numarray objects.
2.963388
2.96224
1.000388
return lambda x, y: height * np.exp(-0.5* (a*(x-x0)**2 + b*(x-x0)*(y-y0) + c*(y-y0)**2))
def gaussian1(height, x0, y0, a, b, c)
height - the amplitude of the gaussian x0, y0, - center of the gaussian a, b, c - ellipse parameters (coefficients in the quadratic form)
2.660871
2.583029
1.030136
xsigma = fwhm / FWHM2SIG ysigma = ratio * xsigma f = nsigma**2/2. theta = np.deg2rad(theta) cost = np.cos(theta) sint = np.sin(theta) if ratio == 0: # 1D Gaussian if theta == 0 or theta == 180: a = 1/xsigma**2 b = 0.0 c = 0.0 el...
def gausspars(fwhm, nsigma=1.5, ratio=1, theta=0.)
height - the amplitude of the gaussian x0, y0, - center of the gaussian fwhm - full width at half maximum of the observation nsigma - cut the gaussian at nsigma ratio = ratio of xsigma/ysigma theta - angle of position angle of the major axis measured counter-clockwise fro...
2.653348
2.569721
1.032543
total = data.sum() #X, Y = np.indices(data.shape) #x = (X*data).sum()/total #y = (Y*data).sum()/total x,y = cntr xi = int(x) yi = int(y) if xi < 0 or xi >= data.shape[1] or yi < 0 or yi >= data.shape[0]: raise ValueError col = data[:, xi] width_x = np.sqrt(abs(((np.a...
def moments(data,cntr)
Returns (height, x, y, width_x, width_y) the gaussian parameters of a 2D distribution by calculating its moments.
2.288437
1.933076
1.183832
for n in range(niter): if len(fitind) < 1: break fitarr = np.array(fitind,np.float32) fluxarr = np.array(fluxes,np.float32) inpind = np.argsort(fitarr[:,1]) npind = fitarr[inpind] fluxind = fluxarr[inpind] fitind = npind.tolist() fluxe...
def apply_nsigma_separation(fitind,fluxes,separation,niter=10)
Remove sources which are within nsigma*fwhm/2 pixels of each other, leaving only a single valid source in that region. This algorithm only works for sources which end up sequentially next to each other based on Y position and removes enough duplicates to make the final source list more managable. It s...
2.979783
2.868359
1.038846
nyk,nxk = ker2d.shape if datamin is None: datamin = data.min() if datamax is None: datamax = data.max() # call C function for speed now... xy_val = cdriz.arrxyround(data,x0,y0,skymode,ker2d,xsigsq,ysigsq,datamin,datamax) if xy_val is None: x = None y = None ...
def xy_round(data,x0,y0,skymode,ker2d,xsigsq,ysigsq,datamin=None,datamax=None)
Compute center of source Original code from IRAF.noao.digiphot.daofind.apfind ap_xy_round()
2.766935
2.703071
1.023627
# Create arrays for the two- and four-fold symmetry computations: 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
def precompute_sharp_round(nxk, nyk, xc, yc)
Pre-computes mask arrays to be used by the 'sharp_round' function for roundness computations based on two- and four-fold symmetries.
3.003249
2.629695
1.142052
# Compute the first estimate of roundness: sum2 = np.sum(s2m*density) sum4 = np.sum(s4m*abs(density)) if sum2 == 0.0: round = 0.0 elif sum4 <= 0.0: # eps? round = None else: round = 2.0 * sum2 / sum4 # Eliminate the sharpness test if the central pixel is bad: ...
def sharp_round(data, density, kskip, xc, yc, s2m, s4m, nxk, nyk, datamin, datamax)
sharp_round -- Compute first estimate of the roundness and sharpness of the detected objects. A Python translation of the AP_SHARP_ROUND IRAF/DAOFIND function.
3.871356
3.798002
1.019314
perimeter = im.shape[0]*2 +im.shape[1]*2 -4 area = im.size return 4*np.pi*area/perimeter**2
def roundness(im)
from astropy.io import fits as pyfits data=pyfits.getdata('j94f05bgq_flt.fits',ext=1) star0=data[403:412,423:432] star=data[396:432,3522:3558] In [53]: findobj.roundness(star0) Out[53]: 0.99401955054989544 In [54]: findobj.roundness(star) Out[54]: 0.83091919980660645
4.019491
4.180829
0.96141
x = list(range(im.shape[1])) y = list(range(im.shape[0])) #coord=np.array([x.flatten(),y.flatten()]).T moment = np.sum([i**p*j**q*im[i,j] for j in x for i in y], dtype=np.float64) return moment
def immoments(im, p,q)
moment = 0 momentx = 0 for i in x.flatten(): moment+=momentx sumx=0 for j in y.flatten(): sumx+=i**0*j**0*star0[i,j]
4.36978
4.692201
0.931286
# These calls point to Python version of moments function m00 = cdriz.arrmoments(im,0,0) m10 = cdriz.arrmoments(im, 1,0) m01 = cdriz.arrmoments(im,0,1) ycen = m10 / m00 xcen = m01 / m00 return xcen, ycen
def centroid(im)
Computes the centroid of an image using the image moments: centroid = {m10/m00, m01/m00} These calls point to Python version of moments function m00 = immoments(im,0,0) m10 = immoments(im, 1,0) m01 = immoments(im,0,1)
4.317641
2.592157
1.665656
# Get the MDRIZTAB table file name from the primary header. # It is gotten from the first file in the input list. No # consistency checks are performed. _fileName = files[0] _header = fileutil.getHeader(_fileName) if 'MDRIZTAB' in _header: _tableName = _header['MDRIZTAB'] else:...
def getMdriztabParameters(files)
Gets entry in MDRIZTAB where task parameters live. This method returns a record array mapping the selected row.
4.323597
4.355784
0.992611
tabdict = {} # for each entry in the record... for indx in range(len(rec.array.names)): # ... get the name, format, and value. _name = rec.array.names[indx] _format = rec.array.formats[indx] _value = rec.field(_name) # Translate names from MDRIZTAB columns names...
def _interpretMdriztabPars(rec)
Collect task parameters from the MDRIZTAB record and update the master parameters list with those values Note that parameters read from the MDRIZTAB record must be cleaned up in a similar way that parameters read from the user interface are.
4.964106
4.888687
1.015427
distortion_pars = configObj['Distortion Model'] outwcs = build(configObj['outwcs'], configObj['wcsname'], configObj['refimage'], undistort = configObj['undistort'], usecoeffs=distortion_pars['applycoeffs'], coeffsfile=distortion_pars['coeffsfile'], **configObj['User WC...
def run(configObj,wcsmap=None)
Interpret parameters from TEAL/configObj interface as set interactively by the user and build the new WCS instance
7.658157
7.554023
1.013785
# Insure that the User WCS parameters have values for all the parameters, # even if that value is 'None' user_wcs_pars = convert_user_pars(wcspars) userwcs = wcspars['userwcs'] ### Build WCS from refimage and/or user pars if util.is_blank(refimage) and not userwcs: print('WAR...
def build(outname, wcsname, refimage, undistort=False, applycoeffs=False, coeffsfile=None, **wcspars)
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'. Parameters ---------- outname ...
4.127549
4.111147
1.003989
if util.is_blank(wcsname): ptime = fileutil.getDate() wcsname = "User_"+ptime return wcsname
def create_WCSname(wcsname)
Verify that a valid WCSNAME has been provided, and if not, create a default WCSNAME based on current date.
12.336861
10.18452
1.211335
default_pars = default_user_wcs.copy() for kw in user_hstwcs_pars: default_pars[user_hstwcs_pars[kw]] = wcspars[kw] return default_pars
def convert_user_pars(wcspars)
Convert the parameters provided by the configObj into the corresponding parameters from an HSTWCS object
4.69199
4.558364
1.029314
# start by working on a copy of the refwcs 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:...
def mergewcs(outwcs, customwcs, wcspars)
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
2.76598
2.77174
0.997922
# Update refwcs with distortion model for kw in model_attrs: if newcoeffs.__dict__[key] is not None: refwcs.__dict__[key] = newcoeffs.__dict__[key]
def add_model(refwcs, newcoeffs)
Add (new?) distortion model to existing HSTWCS object
6.018258
5.417564
1.110879
# apply distortion model to CD matrix 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() ...
def apply_model(refwcs)
Apply distortion model to WCS, including modifying CD with linear distortion terms
5.056518
4.988747
1.013585
print('WARNING:') print(' Replacing existing distortion model with one') print(' not necessarily matched to the observation!') # create linear version of WCS to be updated by new model wcslin = stwcs.distortion.utils.undistortWCS(refwcs) outwcs = refwcs.deepcopy() outwcs.wcs.cd = ...
def replace_model(refwcs, newcoeffs)
Replace the distortion model in a current WCS with a new model Start by creating linear WCS, then run
6.82323
6.392217
1.067428
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 # Update instrument specific keywords outwcs.inst_kw = refwcs.inst_kw for kw in refwcs.inst...
def undistortWCS(refwcs)
Generate an undistorted HSTWCS from an HSTWCS object with a distortion model
4.5539
4.544784
1.002006
# Create header object from HSTWCS object 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] # create headerlet object in memory; either from ...
def generate_headerlet(outwcs,template,wcsname,outname=None)
Create a headerlet based on the updated HSTWCS object This function uses 'template' as the basis for the headerlet. This file can either be the original wcspars['refimage'] or wcspars['coeffsfile'], in this order of preference. If 'template' is None, then a simple Headerlet will be ...
3.252537
3.189299
1.019828
#Shift images +/- 1 in Y. for y in range(-1,2,2): if y == -1: #shift input image 1 pixel right tmpArray[0:(naxis1-1),1:(naxis2-1)] = array[0:(naxis1-1),0:(naxis2-2)] #print "Y shift = 1" else: #shift input image 1 pixel left tmpArray[0:...
def qderiv(array): # TAKE THE ABSOLUTE DERIVATIVE OF A NUMARRY OBJECT #Create 2 empty arrays in memory of the same dimensions as 'array' tmpArray = np.zeros(array.shape,dtype=np.float64) outArray = np.zeros(array.shape, dtype=np.float64) # Get the length of an array side (naxis1,naxis2) = arr...
Take the absolute derivate of an image in memory.
1.781657
1.780073
1.00089