def test_method_refresh_3(): ad = AstroData() ad.open(TESTFILE) ad.refresh_types() assert KNOWNSTAT in ad.types
def test_method_refresh_1(): ad = AstroData(TESTFILE) ad.types.append("FOO") assert "FOO" in ad.types ad.refresh_types() assert "FOO" not in ad.types
def as_astrodata(self, extname=None, tile=False, block=None, return_ROI=True, return_associated_bintables=True, return_non_associations=True, update_catalog_method='wcs'): """ Returns an AstroData object containing by default the mosaiced IMAGE extensions, the merged associated BINTABLEs and all other non-associated extensions of any other type. WCS information in the headers of the IMAGE extensions and any pixel coordinates in BINTABLEs will be updated appropriately. :param extname: If None mosaic all IMAGE extensions. Otherwise only the given extname. This becomes the ref_extname. :type extname: (string). Default is None :param tile: (boolean). If True, the mosaics returned are not corrected for shifting and rotation. :param block: See description below in method 'mosaic_image_data'. :param return_ROI: (True). Returns the minimum frame size calculated from the location of the amplifiers in a given block. If False uses the blocksize value. :param return_associated_bintables: (True). If a bintable is associated to the ref_extname then is returned as a merged table in the output AD. If False, they are not returned in the output AD. :param return_non_associations (True). Specifies whether to return extensions that are not deemed to be associated with the ref_extname. :param update_catalog_method: ('wcs'). Specifies if the X and Y pixel coordinates of any source positions in the BINTABLEs are to be recalculated using the output WCS and the sources R.A. and Dec. values within the table. If set to 'transform' the updated X and Y pixel coordinates will be determined using the transformations used to mosaic the pixel data. In the case of tiling, a shift is technically being applied and therefore update_catalog_method='wcs' should be set internally (Not yet implemented). :type update_catalog_method: (string). Possible values are 'wcs' or 'transform'. """ # If extname is None create mosaics of all image data in ad, merge # the bintables if they are associated with the image extensions # and append to adout all non_associatiated extensions. Appending # these extensions to the output AD is controlled by # return_associated_bintables and return_non_associations. # Make blank ('') same as None; i.e. handle all extensions. if extname == '': extname = None if (extname != None) and (extname not in self.extnames): raise ValueError("as_astrodata: Extname '"+extname+\ "' not found in AD object.") adin = self.ad # alias # Load input data if data_list attribute is not defined. #if not hasattr(self, "data_list"): # self.data_list = self.get_data_list(extname) adout = AstroData() # Prepare output AD adout.phu = adin.phu.copy() # Use input AD phu as output phu adout.phu.header.update('TILED', ['FALSE', 'TRUE'][tile], 'False: Image Mosaicked, True: tiled') # Set up extname lists with all the extension names that are going to # be mosaiced and table extension names to associate. # if extname is None: # Let's work through all extensions if self.associated_im_extns: extname_list = self.associated_im_extns else: extname_list = self.im_extnames else: self.ref_extname = extname # Redefine reference extname if extname in self.associated_im_extns: self.associated_im_extns = [extname] # We need this extname only extname_list = [extname] elif extname in self.non_associated_extns: # Extname is not in associated lists; so clear these lists. extname_list = [] self.associated_im_extns = [] self.associated_tab_extns = [] elif extname in self.associated_tab_extns: # Extname is an associated bintable. extname_list = [] self.associated_im_extns = [] self.associated_tab_extns = [extname] else: extname_list = [extname] # ------ Create mosaic ndarrays, update the output WCS, create an # AstroData object and append to the output list. # Make the list to have the order 'sci','var','dq' svdq = [k for k in ['SCI','VAR','DQ'] if k in extname_list] # add the rest of the extension names. extname_list = svdq + list(set(extname_list)-set(svdq)) for extn in extname_list: # Mosaic the IMAGE extensions now mosarray = self.mosaic_image_data(extn,tile=tile,block=block, return_ROI=return_ROI) # Create the mosaic FITS header using the reference # extension header. header = self.mosaic_header(mosarray.shape,block,tile) # Generate WCS object to be used in the merging the object # catalog table for updating the objects pixel coordinates # w/r to the new crpix1,2. ref_wcs = pywcs.WCS(header) # Setup output AD new_ext = AstroData(data=mosarray,header=header) # Reset extver to 1. new_ext.rename_ext(name=extn,ver=1) adout.append(new_ext) if return_associated_bintables: # If we have associated bintables with image extensions, then # merge the tables. for tab_extn in self.associated_tab_extns: # adout will get the merge table new_tab = self.merge_table_data(ref_wcs, tile, tab_extn, block, update_catalog_method) adout.append(new_tab[0]) # If we have a list of extension names that have not tables extension # names associated, then mosaic them. # if return_non_associations: for extn in self.non_associated_extns: # Now get the list of extver to append if extn in self.im_extnames: # Image extensions # We need to mosaic image extensions having more # than one extver. # if adin.count_exts(extn) > 1: mosarray = self.mosaic_image_data(extn, tile=tile,block=block, return_ROI=return_ROI) # Get reference extension header header = self.mosaic_header(mosarray.shape,block,tile) new_ext = AstroData(data=mosarray,header=header) # Reset extver to 1. new_ext.rename_ext(name=extn,ver=1) adout.append(new_ext) else: self.log.warning("as_astrodata: extension '"+extn+\ "' has 1 extension.") adout.append(adin[extn]) if extn in self.tab_extnames: # We have a list of extvers for extv in self.tab_extnames[extn]: adout.append(adin[extn,extv]) # rediscover classifications. adout.refresh_types() return adout