idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
35,500 | def generate_source_catalogs ( imglist , ** pars ) : output = pars . get ( 'output' , False ) sourcecatalogdict = { } for imgname in imglist : log . info ( "Image name: {}" . format ( imgname ) ) sourcecatalogdict [ imgname ] = { } imghdu = fits . open ( imgname ) imgprimaryheader = imghdu [ 0 ] . header instrument = i... | Generates a dictionary of source catalogs keyed by image name . |
35,501 | def update_image_wcs_info ( tweakwcs_output ) : out_headerlet_dict = { } for item in tweakwcs_output : imageName = item . meta [ 'filename' ] chipnum = item . meta [ 'chip' ] if chipnum == 1 : chipctr = 1 hdulist = fits . open ( imageName , mode = 'update' ) num_sci_ext = amutils . countExtn ( hdulist ) if not hdulist ... | Write newly computed WCS information to image headers and write headerlet files |
35,502 | def update_headerlet_phdu ( tweakwcs_item , headerlet ) : rms_ra = tweakwcs_item . meta [ 'fit_info' ] [ 'RMS_RA' ] . value rms_dec = tweakwcs_item . meta [ 'fit_info' ] [ 'RMS_DEC' ] . value fit_rms = tweakwcs_item . meta [ 'fit_info' ] [ 'FIT_RMS' ] nmatch = tweakwcs_item . meta [ 'fit_info' ] [ 'nmatches' ] catalog ... | Update the primary header data unit keywords of a headerlet object in - place |
35,503 | def interpret_fit_rms ( tweakwcs_output , reference_catalog ) : group_ids = [ info . meta [ 'group_id' ] for info in tweakwcs_output ] group_ids = list ( set ( group_ids ) ) group_dict = { 'avg_RMS' : None } obs_rms = [ ] for group_id in group_ids : for item in tweakwcs_output : if item . meta [ 'fit_info' ] [ 'status'... | Interpret the FIT information to convert RMS to physical units |
35,504 | def sky ( input = None , outExt = None , configObj = None , group = None , editpars = False , ** inputDict ) : if input is not None : inputDict [ 'input' ] = input inputDict [ 'output' ] = None inputDict [ 'updatewcs' ] = False inputDict [ 'group' ] = group else : print ( "Please supply an input image" , file = sys . s... | Perform sky subtraction on input list of images |
35,505 | def _skyUserFromFile ( imageObjList , skyFile , apply_sky = None ) : skyKW = "MDRIZSKY" skyvals = { } if apply_sky is None : skyapplied = False else : skyapplied = apply_sky for line in open ( skyFile ) : if apply_sky is None and line [ 0 ] == '#' and 'applied' in line : if '=' in line : linesep = '=' if ':' in line : ... | Apply sky value as read in from a user - supplied input file . |
35,506 | def _computeSky ( image , skypars , memmap = False ) : _tmp = imagestats . ImageStats ( image . data , fields = skypars [ 'skystat' ] , lower = skypars [ 'skylower' ] , upper = skypars [ 'skyupper' ] , nclip = skypars [ 'skyclip' ] , lsig = skypars [ 'skylsigma' ] , usig = skypars [ 'skyusigma' ] , binwidth = skypars [... | Compute the sky value for the data array passed to the function image is a fits object which contains the data and the header for one image extension |
35,507 | def _subtractSky ( image , skyValue , memmap = False ) : try : np . subtract ( image . data , skyValue , image . data ) except IOError : print ( "Unable to perform sky subtraction on data array" ) raise IOError | subtract the given sky value from each the data array that has been passed . image is a fits object that contains the data and header for one image extension |
35,508 | def _updateKW ( image , filename , exten , skyKW , Value ) : image . header [ skyKW ] = Value if isinstance ( exten , tuple ) : strexten = '[%s,%s]' % ( exten [ 0 ] , str ( exten [ 1 ] ) ) else : strexten = '[%s]' % ( exten ) log . info ( 'Updating keyword %s in %s' % ( skyKW , filename + strexten ) ) fobj = fileutil .... | update the header with the kw value |
35,509 | def _addDefaultSkyKW ( imageObjList ) : skyKW = "MDRIZSKY" Value = 0.0 for imageSet in imageObjList : fname = imageSet . _filename numchips = imageSet . _numchips sciExt = imageSet . scienceExt fobj = fileutil . openImage ( fname , mode = 'update' , memmap = False ) for chip in range ( 1 , numchips + 1 , 1 ) : ext = ( ... | Add MDRIZSKY keyword to commanded SCI headers of all input images if that keyword does not already exist . |
35,510 | def create_astrometric_catalog ( inputs , ** pars ) : catalog = pars . get ( "catalog" , 'GAIADR2' ) output = pars . get ( "output" , 'ref_cat.ecsv' ) gaia_only = pars . get ( "gaia_only" , False ) table_format = pars . get ( "table_format" , 'ascii.ecsv' ) existing_wcs = pars . get ( "existing_wcs" , None ) inputs , _... | Create an astrometric catalog that covers the inputs field - of - view . |
35,511 | def build_reference_wcs ( inputs , sciname = 'sci' ) : wcslist = [ ] for img in inputs : nsci = countExtn ( img ) for num in range ( nsci ) : extname = ( sciname , num + 1 ) if sciname == 'sci' : extwcs = wcsutil . HSTWCS ( img , ext = extname ) else : extwcs = read_hlet_wcs ( img , ext = extname ) wcslist . append ( e... | Create the reference WCS based on all the inputs for a field |
35,512 | def get_catalog ( ra , dec , sr = 0.1 , fmt = 'CSV' , catalog = 'GSC241' ) : serviceType = 'vo/CatalogSearch.aspx' spec_str = 'RA={}&DEC={}&SR={}&FORMAT={}&CAT={}&MINDET=5' headers = { 'Content-Type' : 'text/csv' } spec = spec_str . format ( ra , dec , sr , fmt , catalog ) serviceUrl = '{}/{}?{}' . format ( SERVICELOCA... | Extract catalog from VO web service . |
35,513 | def compute_radius ( wcs ) : ra , dec = wcs . wcs . crval img_center = SkyCoord ( ra = ra * u . degree , dec = dec * u . degree ) wcs_foot = wcs . calc_footprint ( ) img_corners = SkyCoord ( ra = wcs_foot [ : , 0 ] * u . degree , dec = wcs_foot [ : , 1 ] * u . degree ) radius = img_center . separation ( img_corners ) .... | Compute the radius from the center to the furthest edge of the WCS . |
35,514 | def find_gsc_offset ( image , input_catalog = 'GSC1' , output_catalog = 'GAIA' ) : serviceType = "GSCConvert/GSCconvert.aspx" spec_str = "TRANSFORM={}-{}&IPPPSSOOT={}" if 'rootname' in pf . getheader ( image ) : ippssoot = pf . getval ( image , 'rootname' ) . upper ( ) else : ippssoot = fu . buildNewRootname ( image ) ... | Find the GSC to GAIA offset based on guide star coordinates |
35,515 | def generate_source_catalog ( image , ** kwargs ) : if not isinstance ( image , pf . HDUList ) : raise ValueError ( "Input {} not fits.HDUList object" . format ( image ) ) dqname = kwargs . get ( 'dqname' , 'DQ' ) output = kwargs . get ( 'output' , None ) source_cats = { } numSci = countExtn ( image , extname = 'SCI' )... | Build source catalogs for each chip using photutils . |
35,516 | def generate_sky_catalog ( image , refwcs , ** kwargs ) : source_cats = generate_source_catalog ( image , ** kwargs ) master_cat = None numSci = countExtn ( image , extname = 'SCI' ) if refwcs is None : refwcs = build_reference_wcs ( [ image ] ) for chip in range ( numSci ) : chip += 1 seg_tab_phot = source_cats [ chip... | Build source catalog from input image using photutils . |
35,517 | def compute_photometry ( catalog , photmode ) : photmode = photmode . replace ( ' ' , ', ' ) vega = S . FileSpectrum ( VEGASPEC ) bp = S . ObsBandpass ( photmode ) vegauvis = S . Observation ( vega , bp ) vegazpt = 2.5 * np . log10 ( vegauvis . countrate ( ) ) source_phot = vegazpt - 2.5 * np . log10 ( catalog [ 'flux'... | Compute magnitudes for sources from catalog based on observations photmode . |
35,518 | def filter_catalog ( catalog , ** kwargs ) : bright_limit = kwargs . get ( 'bright_limit' , 1.00 ) max_bright = kwargs . get ( 'max_bright' , None ) min_bright = kwargs . get ( 'min_bright' , 20 ) colname = kwargs . get ( 'colname' , 'vegamag' ) phot_column = catalog [ colname ] num_sources = len ( phot_column ) sort_i... | Create a new catalog selected from input based on photometry . |
35,519 | def build_self_reference ( filename , clean_wcs = False ) : if 'sipwcs' in filename : sciname = 'sipwcs' else : sciname = 'sci' wcslin = build_reference_wcs ( [ filename ] , sciname = sciname ) if clean_wcs : wcsbase = wcslin . wcs customwcs = build_hstwcs ( wcsbase . crval [ 0 ] , wcsbase . crval [ 1 ] , wcsbase . crp... | This function creates a reference undistorted WCS that can be used to apply a correction to the WCS of the input file . |
35,520 | def read_hlet_wcs ( filename , ext ) : hstwcs = wcsutil . HSTWCS ( filename , ext = ext ) if hstwcs . naxis1 is None : hstwcs . naxis1 = int ( hstwcs . wcs . crpix [ 0 ] * 2. ) hstwcs . naxis2 = int ( hstwcs . wcs . crpix [ 1 ] * 2. ) return hstwcs | Insure stwcs . wcsutil . HSTWCS includes all attributes of a full image WCS . |
35,521 | def build_hstwcs ( crval1 , crval2 , crpix1 , crpix2 , naxis1 , naxis2 , pscale , orientat ) : wcsout = wcsutil . HSTWCS ( ) wcsout . wcs . crval = np . array ( [ crval1 , crval2 ] ) wcsout . wcs . crpix = np . array ( [ crpix1 , crpix2 ] ) wcsout . naxis1 = naxis1 wcsout . naxis2 = naxis2 wcsout . wcs . cd = buildRotM... | Create an stwcs . wcsutil . HSTWCS object for a default instrument without distortion based on user provided parameter values . |
35,522 | def within_footprint ( img , wcs , x , y ) : if hasattr ( wcs , 'naxis1' ) : naxis1 = wcs . naxis1 naxis2 = wcs . naxis2 elif hasattr ( wcs , 'pixel_shape' ) : naxis1 , naxis2 = wcs . pixel_shape else : naxis1 = wcs . _naxis1 naxis2 = wcs . _naxis2 maskx = np . bitwise_or ( x < 0 , x > naxis1 ) masky = np . bitwise_or ... | Determine whether input x y fall in the science area of the image . |
35,523 | def create_image_footprint ( image , refwcs , border = 0. ) : if isinstance ( image , str ) : image = pf . open ( image ) numSci = countExtn ( image , extname = 'SCI' ) ref_x = refwcs . _naxis1 ref_y = refwcs . _naxis2 border_pixels = int ( border / refwcs . pscale ) mask_arr = np . zeros ( ( ref_y , ref_x ) , dtype = ... | Create the footprint of the image in the reference WCS frame . |
35,524 | def find_hist2d_offset ( filename , reference , refwcs = None , refnames = [ 'ra' , 'dec' ] , match_tolerance = 5. , chip_catalog = True , search_radius = 15.0 , min_match = 10 , classify = True ) : if isinstance ( filename , str ) : image = pf . open ( filename ) rootname = filename . split ( "_" ) [ 0 ] else : image ... | Iteratively look for the best cross - match between the catalog and ref . |
35,525 | def build_wcscat ( image , group_id , source_catalog ) : open_file = False if isinstance ( image , str ) : hdulist = pf . open ( image ) open_file = True elif isinstance ( image , pf . HDUList ) : hdulist = image else : log . info ( "Wrong type of input, {}, for build_wcscat..." . format ( type ( image ) ) ) raise Valu... | Return a list of ~tweakwcs . tpwcs . FITSWCS objects for all chips in an image . |
35,526 | def update_from_shiftfile ( shiftfile , wcsname = None , force = False ) : f = open ( fileutil . osfn ( shiftfile ) ) shift_lines = [ x . strip ( ) for x in f . readlines ( ) ] f . close ( ) for line in shift_lines : if 'refimage' in line or 'reference' in line : refimage = line . split ( ':' ) [ - 1 ] refimage = refim... | Update headers of all images specified in shiftfile with shifts from shiftfile . |
35,527 | def linearize ( wcsim , wcsima , wcsref , imcrpix , f , shift , hx = 1.0 , hy = 1.0 ) : x0 = imcrpix [ 0 ] y0 = imcrpix [ 1 ] p = np . asarray ( [ [ x0 , y0 ] , [ x0 - hx , y0 ] , [ x0 - hx * 0.5 , y0 ] , [ x0 + hx * 0.5 , y0 ] , [ x0 + hx , y0 ] , [ x0 , y0 - hy ] , [ x0 , y0 - hy * 0.5 ] , [ x0 , y0 + hy * 0.5 ] , [ ... | linearization using 5 - point formula for first order derivative |
35,528 | def update_wcs ( image , extnum , new_wcs , wcsname = "" , reusename = False , verbose = False ) : new_wcs . setOrient ( ) fimg_open = False if not isinstance ( image , fits . HDUList ) : fimg = fits . open ( image , mode = 'update' , memmap = False ) fimg_open = True fimg_update = True else : fimg = image if fimg . fi... | Updates the WCS of the specified extension number with the new WCS after archiving the original WCS . |
35,529 | def create_unique_wcsname ( fimg , extnum , wcsname ) : wnames = list ( wcsutil . altwcs . wcsnames ( fimg , ext = extnum ) . values ( ) ) if wcsname not in wnames : uniqname = wcsname else : rpatt = re . compile ( wcsname + '_\d' ) index = 0 for wname in wnames : rmatch = rpatt . match ( wname ) if rmatch : n = int ( ... | This function evaluates whether the specified wcsname value has already been used in this image . If so it automatically modifies the name with a simple version ID using wcsname_NNN format . |
35,530 | def end_logging ( filename = None ) : if logutil . global_logging_started : if filename : print ( 'Trailer file written to: ' , filename ) else : print ( 'No trailer file saved...' ) logutil . teardown_global_logging ( ) else : print ( 'No trailer file saved...' ) | Close log file and restore system defaults . |
35,531 | def findrootname ( filename ) : puncloc = [ filename . find ( char ) for char in string . punctuation ] if sys . version_info [ 0 ] >= 3 : val = sys . maxsize else : val = sys . maxint for num in puncloc : if num != - 1 and num < val : val = num return filename [ 0 : val ] | Return the rootname of the given file . |
35,532 | def removeFileSafely ( filename , clobber = True ) : if filename is not None and filename . strip ( ) != '' : if os . path . exists ( filename ) and clobber : os . remove ( filename ) | Delete the file specified but only if it exists and clobber is True . |
35,533 | def displayEmptyInputWarningBox ( display = True , parent = None ) : if sys . version_info [ 0 ] >= 3 : from tkinter . messagebox import showwarning else : from tkMessageBox import showwarning if display : msg = 'No valid input files found! ' + 'Please check the value for the "input" parameter.' showwarning ( parent = ... | Displays a warning box for the input parameter . |
35,534 | def count_sci_extensions ( filename ) : num_sci = 0 extname = 'SCI' hdu_list = fileutil . openImage ( filename , memmap = False ) for extn in hdu_list : if 'extname' in extn . header and extn . header [ 'extname' ] == extname : num_sci += 1 if num_sci == 0 : extname = 'PRIMARY' num_sci = 1 hdu_list . close ( ) return n... | Return the number of SCI extensions and the EXTNAME from a input MEF file . |
35,535 | def verifyUniqueWcsname ( fname , wcsname ) : uniq = True numsci , extname = count_sci_extensions ( fname ) wnames = altwcs . wcsnames ( fname , ext = ( extname , 1 ) ) if wcsname in wnames . values ( ) : uniq = False return uniq | Report whether or not the specified WCSNAME already exists in the file |
35,536 | def verifyUpdatewcs ( fname ) : updated = True numsci , extname = count_sci_extensions ( fname ) for n in range ( 1 , numsci + 1 ) : hdr = fits . getheader ( fname , extname = extname , extver = n , memmap = False ) if 'wcsname' not in hdr : updated = False break return updated | Verify the existence of WCSNAME in the file . If it is not present report this to the user and raise an exception . Returns True if WCSNAME was found in all SCI extensions . |
35,537 | def verifyRefimage ( refimage ) : valid = True if is_blank ( refimage ) : valid = True return valid refroot , extroot = fileutil . parseFilename ( refimage ) if not os . path . exists ( refroot ) : valid = False return valid if valid : if extroot is None : extn = findWCSExtn ( refimage ) if extn is None : valid = False... | Verify that the value of refimage specified by the user points to an extension with a proper WCS defined . It starts by making sure an extension gets specified by the user when using a MEF file . The final check comes by looking for a CD matrix in the WCS object itself . If either test fails it returns a value of False... |
35,538 | def findWCSExtn ( filename ) : rootname , extroot = fileutil . parseFilename ( filename ) extnum = None if extroot is None : fimg = fits . open ( rootname , memmap = False ) for i , extn in enumerate ( fimg ) : if 'crval1' in extn . header : refwcs = wcsutil . HSTWCS ( '{}[{}]' . format ( rootname , i ) ) if refwcs . w... | Return new filename with extension that points to an extension with a valid WCS . |
35,539 | def verifyFilePermissions ( filelist , chmod = True ) : badfiles = [ ] archive_dir = False for img in filelist : fname = fileutil . osfn ( img ) if 'OrIg_files' in os . path . split ( fname ) [ 0 ] : archive_dir = True try : fp = open ( fname , mode = 'a' ) fp . close ( ) except IOError as e : if e . errno == errno . E... | Verify that images specified in filelist can be updated . |
35,540 | def getFullParList ( configObj ) : plist = [ ] for par in configObj . keys ( ) : if isinstance ( configObj [ par ] , configobj . Section ) : plist . extend ( getFullParList ( configObj [ par ] ) ) else : plist . append ( par ) return plist | Return a single list of all parameter names included in the configObj regardless of which section the parameter was stored |
35,541 | def validateUserPars ( configObj , input_dict ) : plist = getFullParList ( configObj ) extra_pars = [ ] for kw in input_dict : if kw not in plist : extra_pars . append ( kw ) if len ( extra_pars ) > 0 : print ( '=' * 40 ) print ( 'The following input parameters were not recognized as valid inputs:' ) for p in extra_par... | Compares input parameter names specified by user with those already recognized by the task . |
35,542 | def applyUserPars_steps ( configObj , input_dict , step = '3a' ) : step_kws = { '7a' : 'final_wcs' , '3a' : 'driz_sep_wcs' } stepname = getSectionName ( configObj , step ) finalParDict = configObj [ stepname ] . copy ( ) del finalParDict [ step_kws [ step ] ] user_pars = { } for kw in finalParDict : if kw in input_dict... | Apply logic to turn on use of user - specified output WCS if user provides any parameter on command - line regardless of how final_wcs was set . |
35,543 | def getDefaultConfigObj ( taskname , configObj , input_dict = { } , loadOnly = True ) : if configObj is None : configObj = teal . load ( taskname ) elif isinstance ( configObj , str ) : if configObj . lower ( ) . strip ( ) == 'defaults' : configObj = teal . load ( taskname , defaults = True ) configObj . filename = tas... | Return default configObj instance for task updated with user - specified values from input_dict . |
35,544 | def getSectionName ( configObj , stepnum ) : for key in configObj . keys ( ) : if key . find ( 'STEP ' + str ( stepnum ) + ':' ) >= 0 : return key | Return section label based on step number . |
35,545 | def displayMakewcsWarningBox ( display = True , parent = None ) : if sys . version_info [ 0 ] >= 3 : from tkinter . messagebox import showwarning else : from tkMessageBox import showwarning ans = { 'yes' : True , 'no' : False } if ans [ display ] : msg = 'Setting "updatewcs=yes" will result ' + 'in all input WCS values... | Displays a warning box for the makewcs parameter . |
35,546 | def printParams ( paramDictionary , all = False , log = None ) : if log is not None : def output ( msg ) : log . info ( msg ) else : def output ( msg ) : print ( msg ) if not paramDictionary : output ( 'No parameters were supplied' ) else : for key in sorted ( paramDictionary ) : if all or ( not isinstance ( paramDicti... | Print nicely the parameters from the dictionary . |
35,547 | def isCommaList ( inputFilelist ) : if isinstance ( inputFilelist , int ) or isinstance ( inputFilelist , np . int32 ) : ilist = str ( inputFilelist ) else : ilist = inputFilelist if "," in ilist : return True return False | Return True if the input is a comma separated list of names . |
35,548 | def loadFileList ( inputFilelist ) : f = open ( inputFilelist [ 1 : ] ) lines = f . readline ( ) f . close ( ) if len ( line . split ( ) ) == 2 : ivmlist = irafglob . irafglob ( input , atfile = atfile_ivm ) filelist = irafglob . irafglob ( input , atfile = atfile_sci ) return filelist | Open up the |
35,549 | def readCommaList ( fileList ) : names = fileList . split ( ',' ) fileList = [ ] for item in names : fileList . append ( item ) return fileList | Return a list of the files with the commas removed . |
35,550 | def update_input ( filelist , ivmlist = None , removed_files = None ) : newfilelist = [ ] if removed_files == [ ] : return filelist , ivmlist else : sci_ivm = list ( zip ( filelist , ivmlist ) ) for f in removed_files : result = [ sci_ivm . remove ( t ) for t in sci_ivm if t [ 0 ] == f ] ivmlist = [ el [ 1 ] for el in ... | Removes files flagged to be removed from the input filelist . Removes the corresponding ivm files if present . |
35,551 | def get_expstart ( header , primary_hdr ) : if 'expstart' in primary_hdr : exphdr = primary_hdr else : exphdr = header if 'EXPSTART' in exphdr : expstart = float ( exphdr [ 'EXPSTART' ] ) expend = float ( exphdr [ 'EXPEND' ] ) else : expstart = 0. expend = 0.0 return ( expstart , expend ) | shouldn t this just be defined in the instrument subclass of imageobject? |
35,552 | def compute_texptime ( imageObjectList ) : expnames = [ ] exptimes = [ ] start = [ ] end = [ ] for img in imageObjectList : expnames += img . getKeywordList ( '_expname' ) exptimes += img . getKeywordList ( '_exptime' ) start += img . getKeywordList ( '_expstart' ) end += img . getKeywordList ( '_expend' ) exptime = 0.... | Add up the exposure time for all the members in the pattern since drizzle doesn t have the necessary information to correctly set this itself . |
35,553 | def computeRange ( corners ) : x = corners [ : , 0 ] y = corners [ : , 1 ] _xrange = ( np . minimum . reduce ( x ) , np . maximum . reduce ( x ) ) _yrange = ( np . minimum . reduce ( y ) , np . maximum . reduce ( y ) ) return _xrange , _yrange | Determine the range spanned by an array of pixel positions . |
35,554 | def readcols ( infile , cols = [ 0 , 1 , 2 , 3 ] , hms = False ) : fin = open ( infile , 'r' ) outarr = [ ] for l in fin . readlines ( ) : l = l . strip ( ) if len ( l ) == 0 or len ( l . split ( ) ) < len ( cols ) or ( len ( l ) > 0 and l [ 0 ] == '#' or ( l . find ( "INDEF" ) > - 1 ) ) : continue for i in range ( 10 ... | Read the columns from an ASCII file as numpy arrays . |
35,555 | def parse_colnames ( colnames , coords = None ) : cols = [ ] if not isinstance ( colnames , list ) : colnames = colnames . split ( ',' ) if coords is not None and fileutil . isFits ( coords ) [ 0 ] : ftab = fits . open ( coords , memmap = False ) for extn in ftab : if isinstance ( extn , fits . BinTableHDU ) : cnames =... | Convert colnames input into list of column numbers . |
35,556 | def createFile ( dataArray = None , outfile = None , header = None ) : assert ( dataArray is not None ) , "Please supply a data array for createFiles" try : fitsobj = fits . HDUList ( ) if header is not None : try : del ( header [ 'NAXIS1' ] ) del ( header [ 'NAXIS2' ] ) if 'XTENSION' in header : del ( header [ 'XTENSI... | Create a simple fits file for the given data array and header . Returns either the FITS object in - membory when outfile == None or None when the FITS file was written out to a file . |
35,557 | def base_taskname ( taskname , packagename = None ) : if not isinstance ( taskname , str ) : return taskname indx = taskname . rfind ( '.' ) if indx >= 0 : base_taskname = taskname [ ( indx + 1 ) : ] pkg_name = taskname [ : indx ] else : base_taskname = taskname pkg_name = '' assert ( True if packagename is None else (... | Extract the base name of the task . |
35,558 | def endStep ( self , key ) : ptime = _ptime ( ) if key is not None : self . steps [ key ] [ 'end' ] = ptime self . steps [ key ] [ 'elapsed' ] = ptime [ 1 ] - self . steps [ key ] [ 'start' ] [ 1 ] self . end = ptime print ( '==== Processing Step ' , key , ' finished at ' , ptime [ 0 ] ) print ( '' ) | Record the end time for the step . |
35,559 | def reportTimes ( self ) : self . end = _ptime ( ) total_time = 0 print ( ProcSteps . __report_header ) for step in self . order : if 'elapsed' in self . steps [ step ] : _time = self . steps [ step ] [ 'elapsed' ] else : _time = 0.0 total_time += _time print ( ' %20s %0.4f sec.' % ( step , _time ) ) print (... | Print out a formatted summary of the elapsed times for all the performed steps . |
35,560 | def buildDQMasks ( imageObjectList , configObj ) : if not isinstance ( imageObjectList , list ) : imageObjectList = [ imageObjectList ] for img in imageObjectList : img . buildMask ( configObj [ 'single' ] , configObj [ 'bits' ] ) | Build DQ masks for all input images . |
35,561 | def buildMask ( dqarr , bitvalue ) : return bitfield_to_boolean_mask ( dqarr , bitvalue , good_mask_value = 1 , dtype = np . uint8 ) | Builds a bit - mask from an input DQ array and a bitvalue flag |
35,562 | def buildMaskImage ( rootname , bitvalue , output , extname = 'DQ' , extver = 1 ) : maskname = output if fileutil . findFile ( maskname ) : fileutil . removeFile ( maskname ) fdq = fileutil . openImage ( rootname , mode = 'readonly' , memmap = False ) try : _extn = fileutil . findExtname ( fdq , extname , extver = extv... | Builds mask image from rootname s DQ array If there is no valid DQ array in image then return an empty string . |
35,563 | def buildShadowMaskImage ( dqfile , detnum , extnum , maskname , bitvalue = None , binned = 1 ) : if type ( detnum ) != type ( '' ) : detnum = repr ( detnum ) _funcroot = '_func_Shadow_WF' if fileutil . findFile ( maskname ) : fileutil . removeFile ( maskname ) _use_inmask = not fileutil . findFile ( dqfile ) or bitval... | Builds mask image from WFPC2 shadow calibrations . detnum - string value for DETECTOR detector |
35,564 | def mergeDQarray ( maskname , dqarr ) : maskarr = None if maskname is not None : if isinstance ( maskname , str ) : if os . path . exists ( maskname ) : mask = fileutil . openImage ( maskname , memmap = False ) maskarr = mask [ 0 ] . data . astype ( np . bool ) mask . close ( ) else : if isinstance ( maskname , fits . ... | Merge static or CR mask with mask created from DQ array on - the - fly here . |
35,565 | def _setDefaults ( configObj = { } ) : paramDict = { "build" : True , "single" : True , "stepsize" : 10 , "in_units" : "cps" , "wt_scl" : 1. , "pixfrac" : 1. , "kernel" : "square" , "fillval" : 999. , "maskval" : None , "rot" : 0. , "scale" : 1. , "xsh" : 0. , "ysh" : 0. , "blotnx" : 2048 , "blotny" : 2048 , "outnx" : ... | set up the default parameters to run drizzle build single units wt_scl pixfrac kernel fillval rot scale xsh ysh blotnx blotny outnx outny data |
35,566 | def interpret_maskval ( paramDict ) : if 'maskval' not in paramDict : return 0 maskval = paramDict [ 'maskval' ] if maskval is None : maskval = np . nan else : maskval = float ( maskval ) return maskval | Apply logic for interpreting final_maskval value ... |
35,567 | def _regwrite ( shapelist , outfile ) : if len ( shapelist ) < 1 : _print_warning ( "The region list is empty. The region file \"%s\" " "will be empty." % outfile ) try : outf = open ( outfile , 'w' ) outf . close ( ) return except IOError as e : cmsg = "Unable to create region file \'%s\'." % outfile if e . args : e .... | Writes the current shape list out as a region file |
35,568 | def _needs_ref_WCS ( reglist ) : from pyregion . wcs_helper import image_like_coordformats for r in reglist : if r . coord_format in image_like_coordformats : return True return False | Check if the region list contains shapes in image - like coordinates |
35,569 | def run_generator ( product_category , obs_info ) : category_generator_mapping = { 'single exposure product' : single_exposure_product_filename_generator , 'filter product' : filter_product_filename_generator , 'total detection product' : total_detection_product_filename_generator , 'multivisit mosaic product' : multiv... | This is the main calling subroutine . It decides which filename generation subroutine should be run based on the input product_category and then passes the information stored in input obs_info to the subroutine so that the appropriate filenames can be generated . |
35,570 | def single_exposure_product_filename_generator ( obs_info , nn ) : proposal_id = obs_info [ 0 ] visit_id = obs_info [ 1 ] instrument = obs_info [ 2 ] detector = obs_info [ 3 ] filter = obs_info [ 4 ] ipppssoot = obs_info [ 5 ] product_filename_dict = { } product_filename_dict [ "image" ] = "hst_{}_{}_{}_{}_{}_{}_{}.fit... | Generate image and sourcelist filenames for single - exposure products |
35,571 | def filter_product_filename_generator ( obs_info , nn ) : proposal_id = obs_info [ 0 ] visit_id = obs_info [ 1 ] instrument = obs_info [ 2 ] detector = obs_info [ 3 ] filter = obs_info [ 4 ] product_filename_dict = { } product_filename_dict [ "image" ] = "hst_{}_{}_{}_{}_{}.fits" . format ( proposal_id , visit_id , ins... | Generate image and sourcelist filenames for filter products |
35,572 | def total_detection_product_filename_generator ( obs_info , nn ) : proposal_id = obs_info [ 0 ] visit_id = obs_info [ 1 ] instrument = obs_info [ 2 ] detector = obs_info [ 3 ] product_filename_dict = { } product_filename_dict [ "image" ] = "hst_{}_{}_{}_{}.fits" . format ( proposal_id , visit_id , instrument , detector... | Generate image and sourcelist filenames for total detection products |
35,573 | def multivisit_mosaic_product_filename_generator ( obs_info , nn ) : group_num = obs_info [ 0 ] instrument = obs_info [ 1 ] detector = obs_info [ 2 ] filter = obs_info [ 3 ] product_filename_dict = { } product_filename_dict [ "image" ] = "hst_mos_{}_{}_{}_{}.fits" . format ( group_num , instrument , detector , filter )... | Generate image and sourcelist filenames for multi - visit mosaic products |
35,574 | def build_referenceWCS ( catalog_list ) : wcslist = [ ] for catalog in catalog_list : for scichip in catalog . catalogs : wcslist . append ( catalog . catalogs [ scichip ] [ 'wcs' ] ) return utils . output_wcs ( wcslist ) | Compute default reference WCS from list of Catalog objects . |
35,575 | def convex_hull ( points ) : points = sorted ( set ( points ) ) if len ( points ) <= 1 : return points def cross ( o , a , b ) : return ( a [ 0 ] - o [ 0 ] ) * ( b [ 1 ] - o [ 1 ] ) - ( a [ 1 ] - o [ 1 ] ) * ( b [ 0 ] - o [ 0 ] ) lower = [ ] for p in points : while len ( lower ) >= 2 and cross ( lower [ - 2 ] , lower [... | Computes the convex hull of a set of 2D points . |
35,576 | def _estimate_2dhist_shift ( imgxy , refxy , searchrad = 3.0 ) : print ( "Computing initial guess for X and Y shifts..." ) zpmat = _xy_2dhist ( imgxy , refxy , r = searchrad ) nonzeros = np . count_nonzero ( zpmat ) if nonzeros == 0 : print ( "WARNING: No matches found within a search radius of {:g} " "pixels." . forma... | Create a 2D matrix - histogram which contains the delta between each XY position and each UV position . Then estimate initial offset between catalogs . |
35,577 | def openFile ( self , openDQ = False ) : 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 ) fi . image = self . name self . _im = fi . image fi . append_ext ( spu ... | Open file and set up filehandle for image file |
35,578 | def get_wcs ( self ) : wcslist = [ ] for chip in self . chip_catalogs : wcslist . append ( self . chip_catalogs [ chip ] [ 'wcs' ] ) return wcslist | Helper method to return a list of all the input WCS objects associated with this image . |
35,579 | def buildSkyCatalog ( self ) : 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 ] [ 'catalog' ] . xypos if skycat is not... | Convert sky catalog for all chips into a single catalog for the entire field - of - view of this image . |
35,580 | def buildDefaultRefWCS ( self ) : 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 ) | Generate a default reference WCS for this image . |
35,581 | def transformToRef ( self , ref_wcs , force = False ) : if not isinstance ( ref_wcs , pywcs . WCS ) : print ( textutil . textbox ( 'Reference WCS not a valid HSTWCS object' ) , file = sys . stderr ) raise ValueError if self . outxy is None or force : outxy = ref_wcs . wcs_world2pix ( self . all_radec [ 0 ] , self . all... | Transform sky coords from ALL chips into X Y coords in reference WCS . |
35,582 | def get_xy_catnames ( self ) : catstr = self . name + ' ' if 'input_xy' in self . catalog_names : for xycat in self . catalog_names [ 'input_xy' ] : catstr += ' ' + xycat return catstr + '\n' | Return a string with the names of input_xy catalog names |
35,583 | def get_shiftfile_row ( self ) : 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 ] )... | Return the information for a shiftfile for this image to provide compatability with the IRAF - based MultiDrizzle . |
35,584 | def clean ( self ) : 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 ] ) os . remove ( self . catalog_names [ f ] ) else : for extn in f : if os . path . exists ( extn ) : log . info (... | Remove intermediate files created . |
35,585 | def clean ( self ) : if not util . is_blank ( self . catalog . catname ) and os . path . exists ( self . catalog . catname ) : os . remove ( self . catalog . catname ) | Remove intermediate files created |
35,586 | def close ( self ) : if self . _image is None : return empty_image = fits . HDUList ( ) for u in self . _image : empty_image . append ( u . __class__ ( data = None , header = None ) ) self . _image . close ( ) self . _image = empty_image | 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 . |
35,587 | def clean ( self ) : clean_files = [ 'blotImage' , 'crmaskImage' , 'finalMask' , 'staticMask' , 'singleDrizMask' , 'outSky' , 'outSContext' , 'outSWeight' , 'outSingle' , 'outMedian' , 'dqmask' , 'tmpmask' , 'skyMatchMask' ] log . info ( 'Removing intermediate files for %s' % self . _filename ) util . removeFileSafely ... | Deletes intermediate products generated for this imageObject . |
35,588 | def getData ( self , exten = None ) : if exten . lower ( ) . find ( 'sci' ) > - 1 : fname = self . _filename else : extn = exten . split ( ',' ) sci_chip = self . _image [ self . scienceExt , int ( extn [ 1 ] ) ] fname = sci_chip . dqfile extnum = self . _interpretExten ( exten ) if self . _image [ extnum ] . data is N... | 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 . |
35,589 | def getHeader ( self , exten = None ) : _image = fileutil . openImage ( self . _filename , clobber = False , memmap = False ) _header = fileutil . getExtn ( _image , extn = exten ) . header _image . close ( ) del _image return _header | Return just the specified header extension fileutil is used instead of fits to account for non - FITS input images . openImage returns a fits object . |
35,590 | def updateData ( self , exten , data ) : _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 ( ) | Write out updated data and header to the original input file for this object . |
35,591 | def getAllData ( self , extname = None , exclude = None ) : 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 ] . head... | 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 . |
35,592 | def _findExtnames ( self , extname = None , exclude = None ) : extensions = [ ] if extname is not None : if not isinstance ( extname , list ) : extname = [ extname ] for extn in extname : extensions . append ( extn . upper ( ) ) else : for i in range ( 1 , self . _nextend + 1 , 1 ) : if hasattr ( self . _image [ i ] , ... | 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 . |
35,593 | def findExtNum ( self , extname = None , extver = 1 ) : 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 = ext . extnum else ... | Find the extension number of the give extname and extver . |
35,594 | def _assignRootname ( self , chip ) : extname = self . _image [ self . scienceExt , chip ] . header [ "EXTNAME" ] . lower ( ) extver = self . _image [ self . scienceExt , chip ] . header [ "EXTVER" ] expname = self . _rootname self . _image [ self . scienceExt , chip ] . rootname = expname + "_" + extname + str ( extve... | Assign a unique rootname for the image based in the expname . |
35,595 | def _setOutputNames ( self , rootname , suffix = '_drz' ) : outFinal = rootname + suffix + '.fits' outSci = rootname + suffix + '_sci.fits' outWeight = rootname + suffix + '_wht.fits' outContext = rootname + suffix + '_ctx.fits' outMedian = rootname + '_med.fits' origFilename = self . _filename . replace ( '.fits' , '_... | 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 . |
35,596 | def _initVirtualOutputs ( self ) : self . virtualOutputs = { } for product in self . outputNames : self . virtualOutputs [ product ] = None | Sets up the structure to hold all the output data arrays for this image in memory . |
35,597 | def saveVirtualOutputs ( self , outdict ) : if not self . inmemory : return for outname in outdict : self . virtualOutputs [ outname ] = outdict [ outname ] | Assign in - memory versions of generated products for this imageObject based on dictionary outdict . |
35,598 | def getOutputName ( self , name ) : val = self . outputNames [ name ] if self . inmemory : val = self . virtualOutputs [ val ] return val | Return the name of the file or PyFITS object associated with that name depending on the setting of self . inmemory . |
35,599 | def updateOutputValues ( self , output_wcs ) : 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 . _... | Copy info from output WCSObject into outputnames for each chip for use in creating outputimage object . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.