def removeAllAltWCS(hdulist,extlist): """ Removes all alternate WCS solutions from the header """ 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 altwcs.deleteWCS(hdulist,extn,wkey) # Forcibly remove OPUS WCS Keywords, since deleteWCS will not do it hwcs = readAltWCS(hdulist,extn,wcskey='O') if hwcs is None: continue for k in hwcs.keys(): if k not in ['DATE-OBS','MJD-OBS'] and k in hdr: try: del hdr[k] except KeyError: pass except: raise finally: log.setLevel(original_logging_level) # restore original logging level
def removeAllAltWCS(hdulist,extlist): """ Removes all alternate WCS solutions from the header """ 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 altwcs.deleteWCS(hdulist,extn,wkey) # Forcibly remove OPUS WCS Keywords, since deleteWCS will not do it hwcs = readAltWCS(hdulist,extn,wcskey='O') if hwcs is None: continue for k in hwcs.keys(): if k not in ['DATE-OBS','MJD-OBS'] and k in hdr: try: del hdr[k] except KeyError: pass except: raise finally: log.setLevel(original_logging_level) # restore original logging level
def updatehdr(fname, wcsobj, wkey, wcsname, ext=1, clobber=False): hdr = fits.getheader(fname, ext=ext) all_keys = list(string.ascii_uppercase) if wkey.upper() not in all_keys: raise KeyError("wkey must be one character: A-Z") if wkey not in altwcs.available_wcskeys(hdr): if not clobber: raise ValueError("wkey %s is already in use. Use clobber=True to overwrite it or specify a different key." %wkey) else: altwcs.deleteWCS(fname, ext=ext, wcskey='V') f = fits.open(fname, mode='update') hwcs = wcs2header(wcsobj) wcsnamekey = 'WCSNAME' + wkey f[ext].header[wcsnamekey] = wcsname for k in hwcs: f[ext].header[k[:7]+wkey] = hwcs[k] f.close()
def restoreWCSdrz(img, ext): wcs = HSTWCS(img, ext=ext, wcskey='A') print 'Removing any previous alternative WCS for image %s[%s]' % (img, ext) names = wcsnames(img, ext) for k, n in names.iteritems(): if k not in [' ', 'O']: deleteWCS(img, ext, wcskey=k, wcsname=n) with fits.open(img, mode='update') as hdu: hdu[ext].header['CD1_1'] = wcs.wcs.cd[0][0] hdu[ext].header['CD1_2'] = wcs.wcs.cd[0][1] hdu[ext].header['CD2_1'] = wcs.wcs.cd[1][0] hdu[ext].header['CD2_2'] = wcs.wcs.cd[1][1] hdu[ext].header['CRVAL1'] = wcs.wcs.crval[0] hdu[ext].header['CRVAL2'] = wcs.wcs.crval[1] hdu[ext].header['CRPIX1'] = wcs.wcs.crpix[0] hdu[ext].header['CRPIX2'] = wcs.wcs.crpix[1] hdu[ext].header['ORIENTAT'] = 0.0 hdu[ext].header['WCSNAME'] = 'DRZWCS' del hdu[ext].header['LATPOLE'] del hdu[ext].header['LONPOLE']
def removeAllAltWCS(hdulist,extlist): """ Removes all alternate WCS solutions from the header """ hdr = hdulist[extlist[0]].header wkeys = altwcs.wcskeys(hdr) if ' ' in wkeys: wkeys.remove(' ') for extn in extlist: for wkey in wkeys: altwcs.deleteWCS(hdulist,extn,wkey) # Forcibly remove OPUS WCS Keywords, since deleteWCS will not do it hwcs = altwcs.readAltWCS(hdulist,extn,wcskey='O') if hwcs is None: continue for k in hwcs.keys(): if k not in ['DATE-OBS','MJD-OBS'] and k in hdr: try: del hdr[k] except KeyError: pass
def restoreWCSdrz(img, ext): wcs = HSTWCS(img, ext=ext, wcskey='A') print('Removing any previous alternative WCS for image %s[%s]' % (img, ext)) names = wcsnames(img, ext) for k, n in names.items(): if k not in [' ', 'O']: deleteWCS(img, ext, wcskey=k, wcsname=n) with fits.open(img, mode='update') as hdu: hdu[ext].header['CD1_1'] = wcs.wcs.cd[0][0] hdu[ext].header['CD1_2'] = wcs.wcs.cd[0][1] hdu[ext].header['CD2_1'] = wcs.wcs.cd[1][0] hdu[ext].header['CD2_2'] = wcs.wcs.cd[1][1] hdu[ext].header['CRVAL1'] = wcs.wcs.crval[0] hdu[ext].header['CRVAL2'] = wcs.wcs.crval[1] hdu[ext].header['CRPIX1'] = wcs.wcs.crpix[0] hdu[ext].header['CRPIX2'] = wcs.wcs.crpix[1] hdu[ext].header['ORIENTAT'] = 0.0 hdu[ext].header['WCSNAME'] = 'DRZWCS' del hdu[ext].header['LATPOLE'] del hdu[ext].header['LONPOLE']