Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def apply_tweak_shifts(wcs_ref, shift_dict, grism_matches={}, verbose=True):
"""
"""
from drizzlepac import updatehdr
hdu = wcs_ref.to_fits(relax=True)
file0 = list(shift_dict.keys())[0].split('.fits')[0]
tweak_file = '{0}_tweak_wcs.fits'.format(file0)
hdu.writeto(tweak_file, clobber=True)
for file in shift_dict:
updatehdr.updatewcs_with_shift(file, tweak_file,
xsh=shift_dict[file][0],
ysh=shift_dict[file][1],
rot=0., scale=1.,
wcsname='SHIFT', force=True,
reusename=True, verbose=verbose,
sciext='SCI')
### Bug in astrodrizzle? Dies if the FLT files don't have MJD-OBS
### keywords
im = pyfits.open(file, mode='update')
im[0].header['MJD-OBS'] = im[0].header['EXPSTART']
im.flush()
# Update paired grism exposures
if file in grism_matches:
for grism_file in grism_matches[file]:
for drz_file in drz_files[1:]:
root = drz_file.split('_drz')[0]
result = align_drizzled_image(root=root, mag_limits=mag_limits,
radec=rd_ref,
NITER=5, clip=20)
orig_wcs, drz_wcs, out_shift, out_rot, out_scale = result
im = pyfits.open(drz_file)
files = []
for i in range(im[0].header['NDRIZIM']):
files.append(im[0].header['D{0:03d}DATA'.format(i+1)].split('[')[0])
for file in files:
updatehdr.updatewcs_with_shift(file, drz_files[0],
xsh=out_shift[0], ysh=out_shift[1],
rot=out_rot, scale=out_scale,
wcsname=ref_catalog, force=True,
reusename=True, verbose=True,
sciext='SCI')
im = pyfits.open(file, mode='update')
im[0].header['MJD-OBS'] = im[0].header['EXPSTART']
im.flush()
### Second drizzle
if len(files) > 1:
AstroDrizzle(files, output=root, clean=True, context=False, preserve=False, skysub=True, driz_separate=False, driz_sep_wcs=False, median=False, blot=False, driz_cr=False, driz_cr_corr=False, driz_combine=True, final_bits=576, coeffs=True, resetbits=0, build=False, final_wht_type='IVM')
else:
AstroDrizzle(files, output=root, clean=True, final_scale=None, final_pixfrac=1, context=False, final_bits=576, preserve=False, driz_separate=False, driz_sep_wcs=False, median=False, blot=False, driz_cr=False, driz_cr_corr=False, driz_combine=True, build=False, final_wht_type='IVM')
im[0].header['MJD-OBS'] = im[0].header['EXPSTART']
im.flush()
return True
#### Get from WCS log file
for ext in wcs_log['ext']:
tmp_wcs = '/tmp/{0}_tmpwcs.fits'.format(str(direct['product']))
wcs_hdu[ext].writeto(tmp_wcs, clobber=True)
if 'scale' in wcs_log.colnames:
scale = wcs_log['scale'][ext]
else:
scale = 1.
for file in grism['files']:
updatehdr.updatewcs_with_shift(file, tmp_wcs,
xsh=wcs_log['xshift'][ext],
ysh=wcs_log['yshift'][ext],
rot=wcs_log['rot'][ext], scale=scale,
wcsname=ref_catalog, force=True,
reusename=True, verbose=True,
sciext='SCI')
### Bug in astrodrizzle? Dies if the FLT files don't have MJD-OBS
### keywords
im = pyfits.open(file, mode='update')
im[0].header['MJD-OBS'] = im[0].header['EXPSTART']
im.flush()
### Bug in astrodrizzle? Dies if the FLT files don't have MJD-OBS
### keywords
for file in grism['files']: