Skip to content

Commit

Permalink
Merge branch 'master' into dq-bits-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrammer committed Apr 25, 2024
2 parents b2a50d8 + 7e06896 commit 1c4d255
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 33 deletions.
4 changes: 4 additions & 0 deletions grizli/aws/field_tiles.py
Expand Up @@ -57,6 +57,10 @@ def make_all_fields():
sextansa 152.7749473 -4.7061916 46 46
rxcj0600 90.04 -20.145 46 46
ulasj1342 205.555 9.462 46 46
izw18 143.5087276 55.2404070 46 46
q2343p12 356.60847 12.80712 46 46
abell1703 198.76667958333334 51.821752 46 46
sunburst 237.5295615 -78.1917929 46 46
"""

# 46 46 for tile ref 9 9
Expand Down
11 changes: 6 additions & 5 deletions grizli/aws/recalibrate.py
Expand Up @@ -228,11 +228,12 @@ def do_recalibrate(rate_file='jw06541001001_03101_00001_nrs1_rate.fits', cores='
output_path, base_file = os.path.split(rate_file)
mastquery.utils.download_from_mast([base_file.replace('_rate.fits','_uncal.fits')])

try:
ncores = int(cores)
except ValueError:
ncores = cores

# try:
# ncores = int(cores)
# except ValueError:
# ncores = cores
ncores = cores

steps = {
"jump": {
"save_results": True,
Expand Down
35 changes: 35 additions & 0 deletions grizli/data/cwi_badpix.py
@@ -0,0 +1,35 @@
"""
update LW badpix table from C. Willott
https://github.com/gbrammer/grizli/issues/200
"""

import os
import astropy.io.fits as pyfits
import numpy as np
from grizli import utils

new_list = ['https://github.com/gbrammer/grizli/files/13878784/badpixlist_along_20240108.txt',
'https://github.com/gbrammer/grizli/files/13878785/badpixlist_blong_20240108.txt']

old_list = ['nrc_badpix_231206_NRCALONG.fits.gz', 'nrc_badpix_231206_NRCBLONG.fits.gz']

for new_file, old_file in zip(new_list, old_list):
det = os.path.basename(new_file).split('_')[1]

new_data = utils.read_catalog(new_file, format='ascii')

with pyfits.open(old_file) as im:
orig_bad = im[0].data.sum()

for x, y in zip(new_data['col1'], new_data['col2']):
im[0].data[y,x] |= 1

new_bad = im[0].data.sum()

msg = f'{det} prev = {orig_bad.sum()} new = {new_bad.sum()}'
print(msg)

out_file = f'nrc_badpix_240112_NRC{det.upper()}.fits.gz'
im.writeto(out_file, overwrite=True)
39 changes: 39 additions & 0 deletions grizli/data/photom_correction.yml
Expand Up @@ -184,3 +184,42 @@ NRCALONG-F410M-CLEAR: 0.9788
# From j1235 COM-1063 commissioning field
NRCBLONG-F300M-CLEAR: 1.0000
NRCALONG-F300M-CLEAR: 0.9681

## From PRIMER UDS split by detector
## jwst_0989.pmap

# NRCA1-F090W-CLEAR: 0.9761
# NRCA2-F090W-CLEAR: 1.0069
# NRCA3-F090W-CLEAR: 0.9625
# NRCA4-F090W-CLEAR: 0.9987
# NRCB1-F090W-CLEAR: 1.0233
# NRCB2-F090W-CLEAR: 1.0143
# NRCB3-F090W-CLEAR: 1.0121
# NRCB4-F090W-CLEAR: 1.0000

# NRCA1-F115W-CLEAR: 0.9828
# NRCA2-F115W-CLEAR: 1.0133
# NRCA3-F115W-CLEAR: 0.9726
# NRCA4-F115W-CLEAR: 1.0189
# NRCB1-F115W-CLEAR: 1.0283
# NRCB2-F115W-CLEAR: 1.0005
# NRCB3-F115W-CLEAR: 1.0120
# NRCB4-F115W-CLEAR: 1.0000

# NRCA1-F150W-CLEAR: 1.0045
# NRCA2-F150W-CLEAR: 1.0373
# NRCA3-F150W-CLEAR: 0.9785
# NRCA4-F150W-CLEAR: 1.0192
# NRCB1-F150W-CLEAR: 1.0375
# NRCB2-F150W-CLEAR: 1.0055
# NRCB3-F150W-CLEAR: 1.0240
# NRCB4-F150W-CLEAR: 1.0000

# NRCA1-F200W-CLEAR: 0.9953
# NRCA2-F200W-CLEAR: 1.0397
# NRCA3-F200W-CLEAR: 0.9788
# NRCA4-F200W-CLEAR: 1.0196
# NRCB1-F200W-CLEAR: 1.0293
# NRCB2-F200W-CLEAR: 1.0053
# NRCB3-F200W-CLEAR: 1.0175
# NRCB4-F200W-CLEAR: 1.0000
11 changes: 8 additions & 3 deletions grizli/galfit/psf.py
Expand Up @@ -367,7 +367,10 @@ def objfun(params, self, ra, dec, wcs_slice, filter, drz_cutout):
print(params, chi2)
return chi2

def get_psf(self, ra=53.06967306, dec=-27.72333015, filter='F140W', pixfrac=0.1, kernel='point', verbose=True, wcs_slice=None, get_extended=True, get_weight=False, ds9=None, npix=13, renormalize=True):
def get_psf(self, ra=53.06967306, dec=-27.72333015, filter='F140W', pixfrac=0.1, kernel='point', verbose=True, wcs_slice=None, get_extended=True, get_weight=False, ds9=None, npix=13, renormalize=True, xphase=0, yphase=0):
"""
"""

from drizzlepac import adrizzle
from shapely.geometry import Polygon, Point

Expand All @@ -388,8 +391,10 @@ def get_psf(self, ra=53.06967306, dec=-27.72333015, filter='F140W', pixfrac=0.1,

xy = self.wcs[key].all_world2pix(np.array([[ra, dec]]), 0)[0]
xyp = np.cast[int](xy) #np.round(xy)) # +1
dx = xy[0]-int(xy[0])#-0.5
dy = xy[1]-int(xy[1])#-0.5
dx = xy[0] - int(xy[0]) + xphase
dy = xy[1] - int(xy[1]) + yphase
# dx = xy[0]-int(xy[0]) + 0.5
# dy = xy[1]-int(xy[1]) + 0.5

if ext == 2:
# UVIS
Expand Down
17 changes: 14 additions & 3 deletions grizli/jwst_utils.py
Expand Up @@ -923,7 +923,7 @@ def copy_jwst_keywords(header, orig_keys=ORIG_KEYS, verbose=True):
utils.log_comment(utils.LOGFILE, msg, verbose=verbose)


def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask=None, dilate_iterations=3, deg_pix=64, make_plot=True, init_model=0, in_place=False, skip_miri=True, verbose=True, **kwargs):
def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask=None, dilate_iterations=3, deg_pix=64, make_plot=True, init_model=0, in_place=False, skip_miri=True, force_oneoverf=False, verbose=True, **kwargs):
"""
1/f correction for individual exposure
Expand Down Expand Up @@ -971,6 +971,9 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask
skip_miri : bool
Don't run on MIRI exposures
force_oneoverf : bool
Force the correction even if the `ONEFEXP` keyword is already set
verbose : bool
Print status messages
Expand All @@ -997,6 +1000,14 @@ def exposure_oneoverf_correction(file, axis=None, thresholds=[5,4,3], erode_mask
utils.log_comment(utils.LOGFILE, msg, verbose=verbose)

return None, 0

if ('ONEFEXP' in im[0].header) and im[0].header['ONEFEXP'] and (not force_oneoverf):
im.close()

msg = 'exposure_oneoverf_correction: Skip, already corrected'
utils.log_comment(utils.LOGFILE, msg, verbose=verbose)

return None, 0

if axis is None:
if im[0].header['INSTRUME'] in ('NIRISS', 'NIRSPEC'):
Expand Down Expand Up @@ -1456,7 +1467,7 @@ def initialize_jwst_image(filename, verbose=True, max_dq_bit=14, orig_keys=ORIG_
# 'F480M': [1.879639e-21, 1.453752e-30, 4.8152]}
#

def set_jwst_to_hst_keywords(input, reset=False, verbose=True, orig_keys=ORIG_KEYS):
def set_jwst_to_hst_keywords(input, reset=False, verbose=True, orig_keys=ORIG_KEYS, oneoverf_correction=True):
"""
Make primary header look like an HST instrument
"""
Expand All @@ -1476,7 +1487,7 @@ def set_jwst_to_hst_keywords(input, reset=False, verbose=True, orig_keys=ORIG_KE
'DETECTOR':'IR'}

if 'OTELESCO' not in img[0].header:
_status = initialize_jwst_image(input, verbose=verbose)
_status = initialize_jwst_image(input, oneoverf_correction=oneoverf_correction, verbose=verbose)

# Reopen
if isinstance(input, str):
Expand Down
56 changes: 40 additions & 16 deletions grizli/prep.py
Expand Up @@ -4452,11 +4452,16 @@ def process_direct_grism_visit(direct={},
if 'driz_cr_snr' in drizzle_params:
driz_cr_snr = drizzle_params['driz_cr_snr']
drizzle_params.pop('driz_cr_snr')

if 'bits' in drizzle_params:
bits = drizzle_params['bits']
drizzle_params.pop('bits')


if 'driz_cr_grow' in drizzle_params:
driz_cr_grow = drizzle_params.pop('driz_cr_grow')
else:
driz_cr_grow = 1

# Relax CR rejection for first-pass ACS
if isACS:
driz_cr_snr_first = '15. 10.0'
Expand Down Expand Up @@ -4779,15 +4784,27 @@ def process_direct_grism_visit(direct={},
utils.log_comment(utils.LOGFILE, logstr, verbose=True, show_date=True)

if len(direct['files']) == 1:
AstroDrizzle(direct['files'], output=direct['product'],
clean=True, final_pixfrac=0.8, context=False,
resetbits=4096, final_bits=bits, driz_sep_bits=bits,
preserve=False, driz_cr_snr=driz_cr_snr,
driz_cr_scale=driz_cr_scale, driz_separate=False,
driz_sep_wcs=False, median=False, blot=False,
driz_cr=False, driz_cr_corr=False,
build=False, final_wht_type='IVM',
gain=_gain, rdnoise=_rdnoise,
AstroDrizzle(direct['files'],
output=direct['product'],
clean=True,
final_pixfrac=0.8,
context=False,
resetbits=4096,
final_bits=bits,
driz_sep_bits=bits,
preserve=False,
driz_cr_snr=driz_cr_snr,
driz_cr_scale=driz_cr_scale,
driz_separate=False,
driz_sep_wcs=False,
median=False,
blot=False,
driz_cr=False,
driz_cr_corr=False,
build=False,
final_wht_type='IVM',
gain=_gain,
rdnoise=_rdnoise,
static=False,
**drizzle_params)
else:
Expand All @@ -4799,12 +4816,19 @@ def process_direct_grism_visit(direct={},
AstroDrizzle(direct['files'], output=direct['product'],
clean=True, final_pixfrac=pixfrac,
context=(isACS | isWFPC2),
skysub=True, skymethod=skymethod,
resetbits=4096, final_bits=bits, driz_sep_bits=bits,
preserve=False, driz_cr_snr=driz_cr_snr,
driz_cr_scale=driz_cr_scale, build=False,
skysub=True,
skymethod=skymethod,
resetbits=4096,
final_bits=bits,
driz_sep_bits=bits,
preserve=False,
driz_cr_snr=driz_cr_snr,
driz_cr_scale=driz_cr_scale,
driz_cr_grow=driz_cr_grow,
build=False,
final_wht_type='IVM',
gain=_gain, rdnoise=_rdnoise,
gain=_gain,
rdnoise=_rdnoise,
static=static_mask,
**drizzle_params)

Expand Down
11 changes: 5 additions & 6 deletions grizli/utils.py
Expand Up @@ -6267,8 +6267,6 @@ def drizzle_from_visit(visit, output=None, pixfrac=1., kernel='point',

wcs_rows.append(row)

sci_list.append((flt[('SCI', ext)].data - sky)*phot_scale)

err = flt[('ERR', ext)].data*phot_scale

# JWST: just 1,1024,4096 bits
Expand Down Expand Up @@ -6340,9 +6338,10 @@ def drizzle_from_visit(visit, output=None, pixfrac=1., kernel='point',
log_comment(LOGFILE, msg, verbose=verbose)

wht_list.append(wht)
sci_i = (flt[('SCI', ext)].data - sky)*phot_scale
sci_i[wht <= 0] = 0
sci_list.append(sci_i)

# wcs_i = HSTWCS(fobj=flt, ext=('SCI',ext), minerr=0.0,
# wcskey=' ')
if not hasattr(wcs_i, 'pixel_shape'):
wcs_i.pixel_shape = wcs_i._naxis1, wcs_i._naxis2

Expand Down Expand Up @@ -9117,7 +9116,7 @@ def log_function_arguments(LOGFILE, frame, func='func', ignore=[], verbose=True)
logstr = logstr.format(func, args)
msg = log_comment(LOGFILE, logstr, verbose=verbose, show_date=True)

return msg
return args


def ctime_to_iso(mtime, format='%a %b %d %H:%M:%S %Y', strip_decimal=True, verbose=True):
Expand Down Expand Up @@ -9581,7 +9580,7 @@ def N(self):
return len(self.values)


def info(self, sort_counts=-1):
def info(self, sort_counts=0):
"""
Print a summary
"""
Expand Down

0 comments on commit 1c4d255

Please sign in to comment.