def read_archive(self,header,prepend=None): """ Extract a copy of WCS keywords from an open file header, if they have already been created and remember the prefix used for those keywords. Otherwise, setup the current WCS keywords as the archive values. """ # Start by looking for the any backup WCS keywords to # determine whether archived values are present and to set # the prefix used. _prefix = None _archive = False if header != None: for kw in header.items(): if kw[0][1:] in self.wcstrans.keys(): _prefix = kw[0][0] _archive = True break if not _archive: self.archive(prepend=prepend) return # We have archive keywords and a defined prefix # Go through and append them to self.backup if _prefix != None: self.prepend = _prefix else: self.prepend = DEFAULT_PREFIX for key in self.wcstrans.keys(): _archive_key = self._buildNewKeyname(key,_prefix) if key!= 'pixel scale': if _archive_key in header: self.orig_wcs[_archive_key] = header[_archive_key] else: self.orig_wcs[_archive_key] = header[key] self.backup[key] = _archive_key self.revert[_archive_key] = key # Establish plate scale value _cd11str = self.prepend+'CD1_1' _cd21str = self.prepend+'CD2_1' pscale = self.compute_pscale(self.orig_wcs[_cd11str],self.orig_wcs[_cd21str]) _archive_key = self.prepend.lower()+'pscale' self.orig_wcs[_archive_key] = pscale self.backup['pixel scale'] = _archive_key self.revert[_archive_key] = 'pixel scale' # Setup keyword to record when these keywords were backed up. if 'WCSCDATE' in header: self.orig_wcs['WCSCDATE'] = header['WCSCDATE'] else: self.orig_wcs['WCSCDATE'] = fileutil.getLTime() self.backup['WCSCDATE'] = 'WCSCDATE' self.revert['WCSCDATE'] = 'WCSCDATE'
def archive(self,prepend=None,overwrite=no,quiet=yes): """ Create backup copies of the WCS keywords with the given prepended string. If backup keywords are already present, only update them if 'overwrite' is set to 'yes', otherwise, do warn the user and do nothing. Set the WCSDATE at this time as well. """ # Verify that existing backup values are not overwritten accidentally. if len(self.backup.keys()) > 0 and overwrite == no: if not quiet: print 'WARNING: Backup WCS keywords already exist! No backup made.' print ' The values can only be overridden if overwrite=yes.' return # Establish what prepend string to use... if prepend == None: if self.prepend != None: _prefix = self.prepend else: _prefix = DEFAULT_PREFIX else: _prefix = prepend # Update backup and orig_wcs dictionaries # We have archive keywords and a defined prefix # Go through and append them to self.backup self.prepend = _prefix for key in self.wcstrans.keys(): if key != 'pixel scale': _archive_key = self._buildNewKeyname(key,_prefix) else: _archive_key = self.prepend.lower()+'pscale' # if key != 'pixel scale': self.orig_wcs[_archive_key] = self.__dict__[self.wcstrans[key]] self.backup[key] = _archive_key self.revert[_archive_key] = key # Setup keyword to record when these keywords were backed up. self.orig_wcs['WCSCDATE']= fileutil.getLTime() self.backup['WCSCDATE'] = 'WCSCDATE' self.revert['WCSCDATE'] = 'WCSCDATE'